corepc_client/client_sync/v17/
util.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 `== Util ==` 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 `createmultisig`.
13#[macro_export]
14macro_rules! impl_client_v17__create_multisig {
15    () => {
16        impl Client {
17            pub fn create_multisig(
18                &self,
19                nrequired: u32,
20                keys: Vec<PublicKey>,
21            ) -> Result<CreateMultisig> {
22                self.call("createmultisig", &[nrequired.into(), into_json(keys)?])
23            }
24        }
25    };
26}
27
28/// Implements Bitcoin Core JSON-RPC API method `estimatesmartfee`.
29#[macro_export]
30macro_rules! impl_client_v17__estimate_smart_fee {
31    () => {
32        impl Client {
33            pub fn estimate_smart_fee(&self, blocks: u32) -> Result<EstimateSmartFee> {
34                self.call("estimatesmartfee", &[blocks.into()])
35            }
36        }
37    };
38}
39
40/// Implements Bitcoin Core JSON-RPC API method `signmessagewithprivkey`.
41#[macro_export]
42macro_rules! impl_client_v17__sign_message_with_priv_key {
43    () => {
44        impl Client {
45            pub fn sign_message_with_privkey(
46                &self,
47                privkey: &bitcoin::PrivateKey,
48                message: &str,
49            ) -> Result<SignMessageWithPrivKey> {
50                self.call("signmessagewithprivkey", &[into_json(privkey)?, message.into()])
51            }
52        }
53    };
54}
55
56/// Implements Bitcoin Core JSON-RPC API method `validateaddress`.
57#[macro_export]
58macro_rules! impl_client_v17__validate_address {
59    () => {
60        impl Client {
61            pub fn validate_address(
62                &self,
63                address: &Address<NetworkChecked>,
64            ) -> Result<ValidateAddress> {
65                self.call("validateaddress", &[address.to_string().into()])
66            }
67        }
68    };
69}
70
71/// Implements Bitcoin Core JSON-RPC API method `verifymessage`.
72#[macro_export]
73macro_rules! impl_client_v17__verify_message {
74    () => {
75        impl Client {
76            pub fn verify_message(
77                &self,
78                address: &Address<NetworkChecked>,
79                signature: &sign_message::MessageSignature,
80                message: &str,
81            ) -> Result<VerifyMessage> {
82                self.call(
83                    "verifymessage",
84                    &[address.to_string().into(), signature.to_string().into(), message.into()],
85                )
86            }
87        }
88    };
89}