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_minreq_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            pub fn get_deployment_info(&self, blockhash: &BlockHash) -> Result<GetDeploymentInfo> {
34                self.call("getdeploymentinfo", &[into_json(blockhash)?])
35            }
36        }
37    };
38}
39
40/// Implements Bitcoin Core JSON-RPC API method `savemempool`.
41#[macro_export]
42macro_rules! impl_client_v23__save_mempool {
43    () => {
44        impl Client {
45            pub fn save_mempool(&self) -> Result<SaveMempool> { self.call("savemempool", &[]) }
46        }
47    };
48}