0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-24 12:41:41 -05:00
bitcoin-bitcoin-core/src/rpc
Ava Chow b2af068825
Merge bitcoin/bitcoin#30708: rpc: add getdescriptoractivity
37a5c5d836 doc: update descriptors.md for getdescriptoractivity (James O'Beirne)
ee3ce6a4f4 test: rpc: add no address case for getdescriptoractivity (James O'Beirne)
811f76f3a5 rpc: add getdescriptoractivity (James O'Beirne)
25fe087de5 rpc: move-only: move ScriptPubKeyDoc to utils (James O'Beirne)

Pull request description:

  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](https://bitcoin-irc.chaincode.com/bitcoin-core-dev/2024-08-16#1046393;) 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

  ```
  % ./src/bitcoin-cli scanblocks start \
      '["addr(bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t)"]' \
      857263
  {
    "from_height": 857263,
    "to_height": 858263,
    "relevant_blocks": [
      "00000000000000000002bc5cc78f5b0913a5230a8f4b0d5060bc9a60900a5a88",
      "00000000000000000001c5291ed6a40c06d3db5c8fb738567654b24a14b24ecb"
    ],
    "completed": true
  }

  % ./src/bitcoin-cli getdescriptoractivity \
      '["00000000000000000002bc5cc78f5b0913a5230a8f4b0d5060bc9a60900a5a88", "00000000000000000001c5291ed6a40c06d3db5c8fb738567654b24a14b24ecb"]' \
      '["addr(bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t)"]'
  {
    "activity": [
      {
        "type": "receive",
        "amount": 0.00002900,
        "blockhash": "00000000000000000002bc5cc78f5b0913a5230a8f4b0d5060bc9a60900a5a88",
        "height": 857907,
        "txid": "c9d34f202c1f66d80cae76f305350f5fdde910b97cf6ae6bf79f5bcf2a337d06",
        "vout": 254,
        "output_spk": {
          "asm": "1 7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
          "desc": "rawtr(7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b)#yewcd80j",
          "hex": "51207e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
          "address": "bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t",
          "type": "witness_v1_taproot"
        }
      },
      {
        "type": "spend",
        "amount": 0.00002900,
        "blockhash": "00000000000000000001c5291ed6a40c06d3db5c8fb738567654b24a14b24ecb",
        "height": 858260,
        "spend_txid": "7f61d1b248d4ee46376f9c6df272f63fbb0c17039381fb23ca5d90473b823c36",
        "spend_vin": 0,
        "prevout_txid": "c9d34f202c1f66d80cae76f305350f5fdde910b97cf6ae6bf79f5bcf2a337d06",
        "prevout_vout": 254,
        "prevout_spk": {
          "asm": "1 7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
          "desc": "rawtr(7e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b)#yewcd80j",
          "hex": "51207e02f613a8d427f5f55ff62bddc47ccfb394953e57fdcb9a8add58af3124698b",
          "address": "bc1p0cp0vyag6snlta2l7c4am3rue7eef9f72l7uhx52m4v27vfydx9s8tfs7t",
          "type": "witness_v1_taproot"
        }
      }
    ]
  }
  ```

ACKs for top commit:
  instagibbs:
    reACK 37a5c5d836
  achow101:
    ACK 37a5c5d836
  tdb3:
    Code review and light retest ACK 37a5c5d836
  rkrux:
    re-ACK 37a5c5d836

Tree-SHA512: 04aa51e329c6c2ed72464b9886281d5ebd7511a8a8e184ea81249033a4dad535a12829b1010afc2da79b344ea8b5ab8ed47e426d0bf2eb78ab395d20b1da8dbb
2024-11-27 12:23:35 -05:00
..
blockchain.cpp Merge bitcoin/bitcoin#30708: rpc: add getdescriptoractivity 2024-11-27 12:23:35 -05:00
blockchain.h Replace RPCNotifyBlockChange with waitTipChanged() 2024-09-17 09:27:44 +02:00
client.cpp Merge bitcoin/bitcoin#30708: rpc: add getdescriptoractivity 2024-11-27 12:23:35 -05:00
client.h refactor: rpc: hide and rename ParseNonRFCJSONValue() 2023-03-23 18:18:46 +00:00
external_signer.cpp scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
fees.cpp [rpc, fees]: add more detail on the fee estimation modes 2024-08-02 15:40:43 +01:00
mempool.cpp Merge bitcoin/bitcoin#30592: Remove mempoolfullrbf 2024-11-08 13:51:29 -05:00
mempool.h rpc: Move mempool RPCs to new file 2022-03-11 17:46:58 +01:00
mining.cpp RPC: only enforce dust rules on priority when standardness active 2024-11-20 13:49:41 -05:00
mining.h
net.cpp scripted-diff: get rid of remaining "command" terminology in protocol.{h,cpp} 2024-10-26 23:44:15 +02:00
node.cpp scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
output_script.cpp refactor: Fix remaining clang-tidy performance-inefficient-vector errors 2024-11-25 20:09:44 +01:00
protocol.h rpc: clarify ALREADY_IN_CHAIN rpc errors 2024-08-05 15:45:58 +01:00
rawtransaction.cpp Merge bitcoin/bitcoin#30708: rpc: add getdescriptoractivity 2024-11-27 12:23:35 -05:00
rawtransaction_util.cpp Merge bitcoin/bitcoin#28307: rpc, wallet: fix incorrect segwit redeem script size limit 2024-06-04 21:39:49 -04:00
rawtransaction_util.h rpc: bugfix, incorrect segwit redeem script size used in signrawtransactionwithkey 2024-05-03 14:20:45 -03:00
register.h scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
request.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
request.h Merge bitcoin/bitcoin#28167: init: Add option for rpccookie permissions (replace 26088) 2024-06-27 17:35:08 -04:00
server.cpp scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
server.h refactor: Split up NodeContext shutdown_signal and shutdown_request 2024-10-01 09:10:54 +02:00
server_util.cpp Introduce Mining interface 2024-06-18 18:47:51 +02:00
server_util.h Introduce Mining interface 2024-06-18 18:47:51 +02:00
signmessage.cpp util: move util/message to common/signmessage 2024-05-16 11:16:08 -04:00
txoutproof.cpp rpc: Improve gettxoutproof error when only header is available. 2024-09-13 10:50:49 -04:00
util.cpp Merge bitcoin/bitcoin#30708: rpc: add getdescriptoractivity 2024-11-27 12:23:35 -05:00
util.h Merge bitcoin/bitcoin#30708: rpc: add getdescriptoractivity 2024-11-27 12:23:35 -05:00