Emurgo / cardano-serialization-lib

This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.
Other
230 stars 124 forks source link

Tszwai/add inputs from and change #652

Closed twwu123 closed 3 months ago

twwu123 commented 9 months ago

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