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