Skip to main content

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_bitreq_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            pub fn estimate_smart_fee_with_mode(
38                &self,
39                blocks: u32,
40                mode: FeeEstimateMode,
41            ) -> Result<EstimateSmartFee> {
42                self.call("estimatesmartfee", &[blocks.into(), into_json(mode)?])
43            }
44        }
45    };
46}
47
48/// Implements Bitcoin Core JSON-RPC API method `signmessagewithprivkey`.
49#[macro_export]
50macro_rules! impl_client_v17__sign_message_with_priv_key {
51    () => {
52        impl Client {
53            pub fn sign_message_with_privkey(
54                &self,
55                privkey: &bitcoin::PrivateKey,
56                message: &str,
57            ) -> Result<SignMessageWithPrivKey> {
58                self.call("signmessagewithprivkey", &[into_json(privkey)?, message.into()])
59            }
60        }
61    };
62}
63
64/// Implements Bitcoin Core JSON-RPC API method `validateaddress`.
65#[macro_export]
66macro_rules! impl_client_v17__validate_address {
67    () => {
68        impl Client {
69            pub fn validate_address(
70                &self,
71                address: &Address<NetworkChecked>,
72            ) -> Result<ValidateAddress> {
73                self.call("validateaddress", &[address.to_string().into()])
74            }
75        }
76    };
77}
78
79/// Implements Bitcoin Core JSON-RPC API method `verifymessage`.
80#[macro_export]
81macro_rules! impl_client_v17__verify_message {
82    () => {
83        impl Client {
84            pub fn verify_message(
85                &self,
86                address: &Address<NetworkChecked>,
87                signature: &sign_message::MessageSignature,
88                message: &str,
89            ) -> Result<VerifyMessage> {
90                self.call(
91                    "verifymessage",
92                    &[address.to_string().into(), signature.to_string().into(), message.into()],
93                )
94            }
95        }
96    };
97}