This PR resolves #30478 by adding two fields to the scantxoutset
RPC:
- blockhash: the blockhash that an UTXO was created
- confirmations: the number of confirmations an UTXO has relative to the chaintip.
The rationale for the first field is that a blockhash is a much more reliable identifier than the height:
When using the scantxoutset RPC, the current behaviour is to show the block height of the UTXO. This is not optimal, as block height is ambiguous, especially in the case of a block reorganization happening at the same instant of the query. In this case, an UTXO that does not exist would be assumed to exist, unless the chain’s tip hash is recorded before the scan, and make sure it still exists after, as per https://github.com/bitcoindevkit/bdk/issues/895#issuecomment-1475766797 comment by evanlinjin.
The second one was suggested by maflcko, and I agree it’s useful for human users:
While touching this, another thing to add could be the number of confirmations? I understand that this wouldn’t help machine consumers of the interface, but human callers may find it useful?
This will yield an RPC output like so:
0bitcoin-cli scantxoutset start "[\"addr(bc1q5q9344vdyjkcgv79ve3tldz4jmx4lf7knmnx6r)\"]"
1{
2 "success": true,
3 "txouts": 185259116,
4 "height": 853622,
5 "bestblock": "00000000000000000002e97d9be8f0ddf31829cf873061b938c10b0f80f708b2",
6 "unspents": [
7 {
8 "txid": "fae435084345fe26e464994aebc6544875bca0b897bf4ce52a65901ae28ace92",
9 "vout": 0,
10 "scriptPubKey": "0014a00b1ad58d24ad8433c56662bfb45596cd5fa7d6",
11 "desc": "addr(bc1q5q9344vdyjkcgv79ve3tldz4jmx4lf7knmnx6r)#smk4xmt7",
12 "amount": 0.00091190,
13 "coinbase": false,
14 "height": 852741,
15+ "blockhash": "00000000000000000002eefe7e7db44d5619c3dace4c65f3fdcd2913d4945c13",
16+ "confirmations": 882
17 }
18 ],
19 "total_amount": 0.00091190
20}