Skip to main content

corepc_client/client_sync/v23/
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 `v23`.
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 `getblockfrompeer`.
13#[macro_export]
14macro_rules! impl_client_v23__get_block_from_peer {
15    () => {
16        impl Client {
17            pub fn get_block_from_peer(&self, block_hash: BlockHash, peer_id: u32) -> Result<()> {
18                match self.call("getblockfrompeer", &[into_json(block_hash)?, into_json(peer_id)?])
19                {
20                    Ok(serde_json::Value::Object(ref map)) if map.is_empty() => Ok(()),
21                    Ok(res) => Err(Error::Returned(res.to_string())),
22                    Err(err) => Err(err.into()),
23                }
24            }
25        }
26    };
27}
28
29/// Implements Bitcoin Core JSON-RPC API method `getdeploymentinfo`.
30#[macro_export]
31macro_rules! impl_client_v23__get_deployment_info {
32    () => {
33        impl Client {
34            /// Query deployment info at the current chain tip.
35            pub fn get_deployment_info_tip(&self) -> Result<GetDeploymentInfo> {
36                self.call("getdeploymentinfo", &[])
37            }
38
39            /// Query deployment info at the given block hash.
40            pub fn get_deployment_info(&self, block_hash: &BlockHash) -> Result<GetDeploymentInfo> {
41                self.call("getdeploymentinfo", &[into_json(block_hash)?])
42            }
43        }
44    };
45}
46
47/// Implements Bitcoin Core JSON-RPC API method `savemempool`.
48#[macro_export]
49macro_rules! impl_client_v23__save_mempool {
50    () => {
51        impl Client {
52            pub fn save_mempool(&self) -> Result<SaveMempool> { self.call("savemempool", &[]) }
53        }
54    };
55}