CoinSelection.optimal constructor
CoinSelection.optimal({})
A useful default coin selection algorithm. Currently this will first select candidates at random until the required input amount is reached. If the resulting transaction is too large or not enough funds have been reached it will fall back to adding the largest input values first.
Implementation
factory CoinSelection.optimal({
int version = Transaction.currentVersion,
required Iterable<InputCandidate> candidates,
required Iterable<Output> recipients,
required Program changeProgram,
required BigInt feePerKb,
required BigInt minFee,
required BigInt minChange,
int locktime = 0,
}) {
final randomSelection = CoinSelection.random(
version: version,
candidates: candidates,
recipients: recipients,
changeProgram: changeProgram,
feePerKb: feePerKb,
minFee: minFee,
minChange: minChange,
locktime: locktime,
);
return randomSelection.tooLarge || !randomSelection.enoughFunds
? CoinSelection.largestFirst(
version: version,
candidates: candidates,
recipients: recipients,
changeProgram: changeProgram,
feePerKb: feePerKb,
minFee: minFee,
minChange: minChange,
locktime: locktime,
)
: randomSelection;
}