Skip to content

Commit

Permalink
coinselection: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jul 26, 2024
1 parent 125ce9e commit 67c35a2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cashu/wallet/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ async def _select_proofs_to_send(
"""Select proofs to send based on the amount to send and the proofs available. Implements a simple coin selection algorithm.
Can be used for selecting proofs to send an offline transaction.
Rationale:
- Put aside the first proof that is bigger than the amount to send
- Put aside all proofs that are smaller than the amount to send
- If the sum of the selected proofs is smaller than the amount to send, select the next bigger proof and return
- Sort the smaller proofs by amount in descending order
- Select the biggest proof from the ones remaining
- Subtract from the amount to send the amount of the selected proof and the fee for sending it
- If the remainder is bigger than 0, call the function recursively with the remaining proofs and the remaining amount to send
Args:
proofs (List[Proof]): List of proofs to select from
amount_to_send (Union[int, float]): Amount to select proofs for
Expand Down

0 comments on commit 67c35a2

Please sign in to comment.