getUnspentOutputsForTransaction function
(Decimal, List<SafeUtxoOutput> )
getUnspentOutputsForTransaction(
- List<
SafeUtxoOutput> outputs, - Decimal desiredAmount
Get unspent utxos for recipients.
return param1: the amount that we need to get more utxos
Implementation
(Decimal, List<SafeUtxoOutput>) getUnspentOutputsForTransaction(
List<SafeUtxoOutput> outputs,
Decimal desiredAmount,
) {
var candidatesAmount = Decimal.zero;
final candidates = <SafeUtxoOutput>[];
for (final o in outputs) {
if (o.state != OutputState.unspent.name) {
continue;
}
candidates.add(o);
candidatesAmount += Decimal.parse(o.amount);
if (candidatesAmount >= desiredAmount) {
// we get enough utxos
break;
}
}
return (candidatesAmount, candidates);
}