forked from rust-bitcoin/corepc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerating.rs
More file actions
55 lines (51 loc) · 1.72 KB
/
generating.rs
File metadata and controls
55 lines (51 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: CC0-1.0
//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is methods found under the `== Generating ==` section of the
//! API docs of Bitcoin Core `v0.17`.
//!
//! All macros require `Client` to be in scope.
//!
//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`.
/// Implements Bitcoin Core JSON-RPC API method `generatetoaddress`.
#[macro_export]
macro_rules! impl_client_v17__generate_to_address {
() => {
impl Client {
pub fn generate_to_address(
&self,
nblocks: usize,
address: &bitcoin::Address,
) -> Result<GenerateToAddress> {
self.call("generatetoaddress", &[nblocks.into(), into_json(address)?])
}
}
};
}
/// Implements Bitcoin Core JSON-RPC API method `generate`.
#[macro_export]
macro_rules! impl_client_v17__generate {
() => {
impl Client {
pub fn generate(&self, nblocks: usize) -> Result<Generate> {
self.call("generate", &[nblocks.into()])
}
}
};
}
/// Implements Bitcoin Core JSON-RPC API method `invalidateblock`.
// This method does not appear in the output of `bitcoin-cli help`.
#[macro_export]
macro_rules! impl_client_v17__invalidate_block {
() => {
impl Client {
pub fn invalidate_block(&self, hash: BlockHash) -> Result<()> {
match self.call("invalidateblock", &[into_json(hash)?]) {
Ok(serde_json::Value::Null) => Ok(()),
Ok(res) => Err(Error::Returned(res.to_string())),
Err(err) => Err(err.into()),
}
}
}
};
}