corepc_client/client_sync/v17/
generating.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 `== Generating ==` section of the
6//! API docs of Bitcoin Core `v0.17`.
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 `generatetoaddress`.
13#[macro_export]
14macro_rules! impl_client_v17__generate_to_address {
15    () => {
16        impl Client {
17            pub fn generate_to_address(
18                &self,
19                nblocks: usize,
20                address: &bitcoin::Address,
21            ) -> Result<GenerateToAddress> {
22                self.call("generatetoaddress", &[nblocks.into(), into_json(address)?])
23            }
24        }
25    };
26}
27
28/// Implements Bitcoin Core JSON-RPC API method `generate`.
29#[macro_export]
30macro_rules! impl_client_v17__generate {
31    () => {
32        impl Client {
33            pub fn generate(&self, nblocks: usize) -> Result<Generate> {
34                self.call("generate", &[nblocks.into()])
35            }
36        }
37    };
38}
39
40/// Implements Bitcoin Core JSON-RPC API method `invalidateblock`.
41// This method does not appear in the output of `bitcoin-cli help`.
42#[macro_export]
43macro_rules! impl_client_v17__invalidate_block {
44    () => {
45        impl Client {
46            pub fn invalidate_block(&self, hash: BlockHash) -> Result<()> {
47                match self.call("invalidateblock", &[into_json(hash)?]) {
48                    Ok(serde_json::Value::Null) => Ok(()),
49                    Ok(res) => Err(Error::Returned(res.to_string())),
50                    Err(err) => Err(err.into()),
51                }
52            }
53        }
54    };
55}