Skip to content

Commit

Permalink
revise 'makeChange' to take fees, deposits, withdrawals and minimum a…
Browse files Browse the repository at this point in the history
…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
KtorZ committed Jan 18, 2021
1 parent 4ee5c71 commit c640a39
Show file tree
Hide file tree
Showing 2 changed files with 643 additions and 270 deletions.

0 comments on commit c640a39

Please sign in to comment.