Protected ReadonlyDUST_Protected ReadonlyINPUT_ProtectedMAX_Protected ReadonlyOUTPUT_Protected ReadonlyTRANSACTION_ProtectedcalculateCalculate change amount
ProtectedcalculateProtectedcheckCheck if options are valid and return failure result if not
ProtectedcreateEstimate transaction fee
ProtectedestimateEstimate transaction size in vBytes
ProtectedfilterFilter UTXOs with protection and confirmation checks
ProtectedfilterProtectedisCheck if amount is dust
OptionaldustThreshold: numberProtectedsortProtectedsortProtectedsumProtectedvalidate
Knapsack UTXO Selection Algorithm - Legacy stochastic approximation
The Knapsack selector implements Bitcoin Core's legacy UTXO selection algorithm (pre-2018) using a stochastic approximation approach. It runs multiple random iterations to find good solutions, making it highly reliable and capable of finding valid selections even when more sophisticated algorithms fail.
Remarks
The algorithm operates through multiple phases:
Each iteration processes UTXOs from largest to smallest value, randomly including each with a configurable probability (default 50%). The algorithm tracks the best solution found across all iterations, preferring selections that minimize excess value over the target amount.
The algorithm includes intelligent early exit conditions and prefers solutions that avoid creating dust outputs (change below 1000 satoshis threshold).
Key features:
Performance characteristics:
Example