bitcoind_json_rpc_client/client_sync/v17/
network.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! Macros for implementing JSON-RPC methods on a client.
4//!
5//! Requires `Client` to be in scope.
6//!
7//! Specifically this is methods found under the `== Network ==` section of the
8//! API docs of `bitcoind v0.17.1`.
9//!
10//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11
12/// Implements bitcoind JSON-RPC API method `getaddednodeinfo`
13#[macro_export]
14macro_rules! impl_client_v17__getaddednodeinfo {
15    () => {
16        impl Client {
17            pub fn get_added_node_info(&self) -> Result<GetAddedNodeInfo> {
18                self.call("getaddednodeinfo", &[])
19            }
20        }
21    };
22}
23
24/// Implements bitcoind JSON-RPC API method `getnettotals`
25#[macro_export]
26macro_rules! impl_client_v17__getnettotals {
27    () => {
28        impl Client {
29            pub fn get_net_totals(&self) -> Result<GetNetTotals> { self.call("getnettotals", &[]) }
30        }
31    };
32}
33
34/// Implements bitcoind JSON-RPC API method `getnetworkinfo`
35#[macro_export]
36macro_rules! impl_client_v17__getnetworkinfo {
37    () => {
38        impl Client {
39            /// Returns the server version field of `GetNetworkInfo`.
40            pub fn server_version(&self) -> Result<usize> {
41                let info = self.get_network_info()?;
42                Ok(info.version)
43            }
44
45            pub fn get_network_info(&self) -> Result<GetNetworkInfo> {
46                self.call("getnetworkinfo", &[])
47            }
48        }
49    };
50}
51
52/// Implements bitcoind JSON-RPC API method `getpeerinfo`
53#[macro_export]
54macro_rules! impl_client_v17__getpeerinfo {
55    () => {
56        impl Client {
57            pub fn get_peer_info(&self) -> Result<GetPeerInfo> { self.call("getpeerinfo", &[]) }
58        }
59    };
60}