Skip to main content

corepc_client/client_sync/v29/
blockchain.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! Macros for implementing JSON-RPC methods on a client.
4//!
5//! Specifically this is methods found under the `== Blockchain ==` section of the
6//! API docs of Bitcoin Core `v29`.
7//!
8//! All macros require `Client` to be in scope.
9//!
10//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`.
11
12/// Implements Bitcoin Core JSON-RPC API method `dumptxoutset`.
13#[macro_export]
14macro_rules! impl_client_v29__dump_tx_out_set {
15    () => {
16        impl Client {
17            pub fn dump_tx_out_set(&self, path: &str, snapshot_type: &str) -> Result<DumpTxOutSet> {
18                self.call("dumptxoutset", &[path.into(), snapshot_type.into()])
19            }
20        }
21    };
22}
23
24/// Implements Bitcoin Core JSON-RPC API method `getdescriptoractivity`.
25#[macro_export]
26macro_rules! impl_client_v29__get_descriptor_activity {
27    () => {
28        impl Client {
29            pub fn get_descriptor_activity(&self) -> Result<GetDescriptorActivity> {
30                let block_hashes: &[BlockHash] = &[];
31                let scan_objects: &[&str] = &[];
32                // FIXME: Core errors if we don't pass empty arrays?
33                let params = vec![json!(block_hashes), json!(scan_objects)];
34                self.call("getdescriptoractivity", &params)
35            }
36        }
37    };
38}
39
40/// Implements Bitcoin Core JSON-RPC API method `getblock`.
41#[macro_export]
42macro_rules! impl_client_v29__get_block {
43    () => {
44        impl Client {
45            /// Gets a block by blockhash. Kept for compatibility; uses verbose set to 0.
46            pub fn get_block(&self, hash: BlockHash) -> Result<Block> {
47                let json = self.get_block_verbose_zero(hash)?;
48                Ok(json.block()?)
49            }
50
51            /// Gets a block by blockhash with verbose set to 0.
52            pub fn get_block_verbose_zero(&self, hash: BlockHash) -> Result<GetBlockVerboseZero> {
53                self.call("getblock", &[into_json(hash)?, 0.into()])
54            }
55
56            /// Gets a block by blockhash with verbose set to 1.
57            pub fn get_block_verbose_one(&self, hash: BlockHash) -> Result<GetBlockVerboseOne> {
58                self.call("getblock", &[into_json(hash)?, 1.into()])
59            }
60
61            /// Gets a block by blockhash with verbose set to 2.
62            pub fn get_block_verbose_two(&self, hash: BlockHash) -> Result<GetBlockVerboseTwo> {
63                self.call("getblock", &[into_json(hash)?, 2.into()])
64            }
65
66            /// Gets a block by blockhash with verbose set to 3.
67            pub fn get_block_verbose_three(&self, hash: BlockHash) -> Result<GetBlockVerboseThree> {
68                self.call("getblock", &[into_json(hash)?, 3.into()])
69            }
70        }
71    };
72}