Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revise 'makeChange' to take fees, deposits, withdrawals and minimum a…
…da values into account The strategy is as follows: 1. We start by computing the surplus amount coming from the difference between the total requested outputs and the total incoming value. 2. From there, we start by creating as many change outputs as there are outputs, and assign surplus tokens proportionally to the quantity present in each outputs. That is, to create change outputs that are following a similar distribution as the requested outputs. 3. For tokens which are not present in any requested outputs (coming from selected inputs), we forward them into pre-existing change outputs, coalescing small values as necessary so that there the number of change outputs remains equal to the number of requested outputs. 4. Then, we assign some coins from the surplus to each change output so that each can meet the minimum coin value required. At this point, we may return stop and return 'Nothing' if there's not enough surplus coins to assign all required minimum to all change outputs. 5. Then, we split the remaining coin amount across all change outputs, proportionally to the size of each corresponding output.
- Loading branch information