Skip to content

Commit 552e439

Browse files
author
Robert 'Probie' Offner
committed
Append change instead of prepending it
It's desirable for a client to be able to predict the index of outputs. As such we append change to the end so that the index of other outputs doesn't changed based on whether there's change or not. Resolves #3725
1 parent 47247f6 commit 552e439

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cardano-api/ChangeLog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog for cardano-api
22

3+
## vNext
4+
5+
### Features
6+
7+
- Append, not prepend change output when balancing a transaction ([PR 4343](https://github.com/input-output-hk/cardano-node/pull/4343))
8+
39
## 1.33.0 -- December 2021
410
## 1.32.1 -- November 2021
511

cardano-api/src/Cardano/Api/Fees.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,9 @@ makeTransactionBodyAutoBalance eraInMode systemstart history pparams
11291129
accountForNoChange change@(TxOut _ balance _ _) rest =
11301130
case txOutValueToLovelace balance of
11311131
Lovelace 0 -> rest
1132-
_ -> change : rest
1132+
-- We append change at the end so a client can predict the indexes
1133+
-- out of the outputs
1134+
_ -> rest ++ [change]
11331135

11341136
balanceCheck :: TxOutValue era -> Either TxBodyErrorAutoBalance ()
11351137
balanceCheck balance

0 commit comments

Comments
 (0)