corepc_client/client_sync/v17/
mining.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 `== Mining ==` 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 `getblocktemplate`.
13#[macro_export]
14macro_rules! impl_client_v17__get_block_template {
15    () => {
16        impl Client {
17            pub fn get_block_template(
18                &self,
19                request: &TemplateRequest,
20            ) -> Result<GetBlockTemplate> {
21                self.call("getblocktemplate", &[into_json(request)?])
22            }
23        }
24    };
25}
26
27/// Implements Bitcoin Core JSON-RPC API method `getmininginfo`.
28#[macro_export]
29macro_rules! impl_client_v17__get_mining_info {
30    () => {
31        impl Client {
32            pub fn get_mining_info(&self) -> Result<GetMiningInfo> {
33                self.call("getmininginfo", &[])
34            }
35        }
36    };
37}
38
39/// Implements Bitcoin Core JSON-RPC API method `getnetworkhashps`.
40#[macro_export]
41macro_rules! impl_client_v17__get_network_hashes_per_second {
42    () => {
43        impl Client {
44            pub fn get_network_hash_ps(&self) -> Result<f64> { self.call("getnetworkhashps", &[]) }
45        }
46    };
47}
48
49/// Implements Bitcoin Core JSON-RPC API method `prioritisetransaction`.
50#[macro_export]
51macro_rules! impl_client_v17__prioritise_transaction {
52    () => {
53        impl Client {
54            pub fn prioritise_transaction(
55                &self,
56                txid: &Txid,
57                fee_delta: bitcoin::SignedAmount,
58            ) -> Result<bool> {
59                let sats = fee_delta.to_sat();
60                self.call("prioritisetransaction", &[into_json(txid)?, 0.into(), sats.into()])
61            }
62        }
63    };
64}
65
66/// Implements Bitcoin Core JSON-RPC API method `submitblock`.
67#[macro_export]
68macro_rules! impl_client_v17__submit_block {
69    () => {
70        impl Client {
71            pub fn submit_block(&self, block: &Block) -> Result<()> {
72                let hex: String = bitcoin::consensus::encode::serialize_hex(block);
73                match self.call("submitblock", &[into_json(hex)?]) {
74                    Ok(serde_json::Value::Null) => Ok(()),
75                    Ok(res) => Err(Error::Returned(res.to_string())),
76                    Err(err) => Err(err.into()),
77                }
78            }
79        }
80    };
81}