Skip to main content

corepc_client/client_sync/v26/
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 `v26`.
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_v26__dump_tx_out_set {
15    () => {
16        impl Client {
17            pub fn dump_tx_out_set(&self, path: &str) -> Result<DumpTxOutSet> {
18                self.call("dumptxoutset", &[path.into()])
19            }
20        }
21    };
22}
23
24/// Implements Bitcoin Core JSON-RPC API method `getchainstates`.
25#[macro_export]
26macro_rules! impl_client_v26__get_chain_states {
27    () => {
28        impl Client {
29            pub fn get_chain_states(&self) -> Result<GetChainStates> {
30                self.call("getchainstates", &[])
31            }
32        }
33    };
34}
35
36/// Implements Bitcoin Core JSON-RPC API method `gettxoutsetinfo`.
37#[macro_export]
38macro_rules! impl_client_v26__get_tx_out_set_info {
39    () => {
40        impl Client {
41            pub fn get_tx_out_set_info(&self) -> Result<GetTxOutSetInfo> {
42                self.call("gettxoutsetinfo", &[])
43            }
44        }
45    };
46}
47
48/// Implements Bitcoin Core JSON-RPC API method `importmempool`.
49#[macro_export]
50macro_rules! impl_client_v26__import_mempool {
51    () => {
52        impl Client {
53            pub fn import_mempool(&self, filepath: &str) -> Result<()> {
54                match self.call("importmempool", &[filepath.into()]) {
55                    Ok(serde_json::Value::Object(ref map)) if map.is_empty() => Ok(()),
56                    Ok(res) => Err(Error::Returned(res.to_string())),
57                    Err(err) => Err(err.into()),
58                }
59            }
60        }
61    };
62}
63
64/// Implements Bitcoin Core JSON-RPC API method `loadtxoutset`.
65#[macro_export]
66macro_rules! impl_client_v26__load_tx_out_set {
67    () => {
68        impl Client {
69            pub fn load_tx_out_set(&self, path: &str) -> Result<LoadTxOutSet> {
70                self.call("loadtxoutset", &[path.into()])
71            }
72        }
73    };
74}