cardano-serialization-lib
cardano-serialization-lib copied to clipboard
Tszwai/add inputs from and change
Adds function to perform UTxO selection, add change output, and set fees. Previously, these actions were done by two different functions, the add_inputs_from and add_change_if_needed functions, which caused issues when the change output had tokens, and therefore had some minimum required ADA. This was not taken into account by the add_change_if_needed function.
I have added a function called add_inputs_from_and_change which will do both of these actions in one. It uses the already existing functions, but if add_change_if_needed fails, then it will attempt to continuously add more unused inputs (the unused inputs are sorted by length of multiasset), re-attempting the add_change_if_needed function after every extra input.
The unused inputs are sorted by length of multiasset since adding more tokens potentially increases the fees required. The other possibility would be to sort them by the number of tokens different from already selected inputs, but this would require a relatively complicated sorting function. I ended up deciding to simply sort them according to the length of their multiasset.
Potentially solves issues #616 and #553