Flow: Watch unspent transaction outputs
The WatchUTXOS
sets up a ticker that collects all the unspent transaction outputs on the TSS address. It does this by calling ListUnspentMinMaxAddresses
in a loop, from one to the current block number in chunks of 500.
for i := minConfirmations; i < maxConfirmations; i += chunkSize {
unspents, err := ob.rpcClient.ListUnspentMinMaxAddresses(i, i+chunkSize, addresses)
if err != nil {
return err
}
utxos = append(utxos, unspents...)
ob.logger.Info().Msgf("btc: fetched %d utxos", len(unspents))
}
This results in around 5,000 RPC calls per tick on the BTC testnet and around 1,600 on mainnet, as the current block numbers are 2.5 million and 800,000, respectively.
The transactions are then filtered to remove any pending outputs, then sorted by the amount. It then calls housekeepPending
to remove any completed transactions from the list of pending transaction outputs.