bitcoindevkit / coin-select

Tool to help you select inputs for making bitcoin transactions.
Other
13 stars 7 forks source link

Simplify change policy #14

Closed LLFourn closed 10 months ago

LLFourn commented 10 months ago

This PR makes a simplifying assumption: The decision about whether to add change or not can be reduced to a check whether the excess is over a certain threshold. The change policy is simply how to compute that threshold.

I originally didn't do this because I thought change policies could be more complicated than that -- and they probably could be! But @evanlinjin pointed out that you can easily run the coin selector multiple times with different policies and change output structures if you wanted to compare and contrast different approaches (rather than trying to embed this logic into the change policy itself).

I realized it is actually quite difficult to implement the metrics correctly without knowing the threshold that will case change to be added (and the weight of that change) up front. Knowing this we should be able to make the implementations much simpler.