determineTransactionValue function
Implementation
(BigInt, BigInt) determineTransactionValue(
List<ElectrumOutput> outputs,
TransactionTransferMethod transferMethod,
Iterable<NodeWithAddress> nodes,
UTXONetworkType type,
) {
final ourValue = switch (transferMethod) {
TransactionTransferMethod.receive => outputs.fold(
BigInt.zero,
(prev, output) {
if (output.belongsToUs) {
return prev + output.value;
}
return prev;
},
),
TransactionTransferMethod.own => outputs
.singleWhereOrNull(
(output) => output.node is ReceiveNode,
)
?.value ??
BigInt.from(-1),
TransactionTransferMethod.send => outputs.fold(
BigInt.zero,
(prev, output) {
if (!output.belongsToUs) {
return prev + output.value;
}
return prev;
},
),
TransactionTransferMethod.unknown => BigInt.from(-1),
};
final totalValue = outputs.fold(
BigInt.zero,
(prev, output) => prev + output.value,
);
return (ourValue, totalValue);
}