extractUTXOs function

Map<ElectrumOutput, UTXOTransaction> extractUTXOs({
  1. required Iterable<UTXOTransaction> txList,
})

Returns a map of UTXOs which belong to us and are unspent and their corresponding transactions

Implementation

Map<ElectrumOutput, UTXOTransaction> extractUTXOs({
  required Iterable<UTXOTransaction> txList,
}) {
  Map<ElectrumOutput, UTXOTransaction> utxoMap = {};
  for (final tx in txList) {
    for (final ElectrumOutput output in tx.outputs) {
      if (output.spent == false && output.belongsToUs == true) {
        utxoMap[output] = tx;
      }
    }
  }
  return utxoMap;
}