The RPC command scanblocks
provides a useful way to get a set of blockhashes that have activity relevant to a set of descriptors (relevant_blocks
). However actually extracting the activity from those blocks is left as an exercise to the end user.
This process involves not only generating the (potentially ranged) set of scripts for the descriptor set on the client side (maybe via deriveaddresses
), but then the user must retrieve each block’s contents one-by-one using getblock <hash>
, which is transmitted over a network link. And that’s all before they perform the actual search over block content. There’s even more work required to incorporate unconfirmed transactions.
This PR introduces an RPC getdescriptoractivity
that dovetails with scanblocks
output, handling the process described above. Users specify the blockhashes (perhaps from relevant_blocks
) and a set of descriptors; they are then given all spend/receive activity in that set of blocks.
This is a very useful tool when implementing lightweight wallets that want neither to require a third-party indexer like electrs, nor the overhead of creating and managing watch-only wallets in Core. This allows Core to be more easily used in a “stateless” manner by wallets, with potentially many nodes interchangeably acting as backends.
Example usage
0% ./src/bitcoin-cli scanblocks start \
1 '["addr(bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t)"]' \
2 857263
3{
4 "from_height": 857263,
5 "to_height": 858263,
6 "relevant_blocks": [
7 "00000000000000000002bc5cc78f5b0913a5230a8f4b0d5060bc9a60900a5a88",
8 "00000000000000000001c5291ed6a40c06d3db5c8fb738567654b24a14b24ecb"
9 ],
10 "completed": true
11}
12
13
14% ./src/bitcoin-cli getdescriptoractivity \
15 '["00000000000000000002bc5cc78f5b0913a5230a8f4b0d5060bc9a60900a5a88", "00000000000000000001c5291ed6a40c06d3db5c8fb738567654b24a14b24ecb"]' \
16 '["addr(bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t)"]'
17{
18 "activity": [
19 {
20 "type": "receive",
21 "amount": 0.00002900,
22 "blockhash": "00000000000000000002bc5cc78f5b0913a5230a8f4b0d5060bc9a60900a5a88",
23 "height": 857907,
24 "txid": "c9d34f202c1f66d80cae76f305350f5fdde910b97cf6ae6bf79f5bcf2a337d06",
25 "vout": 254,
26 "output_spk": {
27 "asm": "1 7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
28 "desc": "rawtr(7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b)#yewcd80j",
29 "hex": "51207e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
30 "address": "bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t",
31 "type": "witness_v1_taproot"
32 }
33 },
34 {
35 "type": "spend",
36 "amount": 0.00002900,
37 "blockhash": "00000000000000000001c5291ed6a40c06d3db5c8fb738567654b24a14b24ecb",
38 "height": 858260,
39 "spend_txid": "7f61d1b248d4ee46376f9c6df272f63fbb0c17039381fb23ca5d90473b823c36",
40 "spend_vin": 0,
41 "prevout_txid": "c9d34f202c1f66d80cae76f305350f5fdde910b97cf6ae6bf79f5bcf2a337d06",
42 "prevout_vout": 254,
43 "prevout_spk": {
44 "asm": "1 7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
45 "desc": "rawtr(7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b)#yewcd80j",
46 "hex": "51207e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
47 "address": "bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t",
48 "type": "witness_v1_taproot"
49 }
50 }
51 ]
52}