Skip to main content

corepc_client/client_sync/v22/
wallet.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 `== Wallet ==` section of the
6//! API docs of Bitcoin Core `v22`.
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 `listdescriptors`.
13#[macro_export]
14macro_rules! impl_client_v22__list_descriptors {
15    () => {
16        impl Client {
17            pub fn list_descriptors(&self) -> Result<ListDescriptors> {
18                self.call("listdescriptors", &[])
19            }
20        }
21    };
22}
23
24/// Implements Bitcoin Core JSON-RPC API method `loadwallet`.
25#[macro_export]
26macro_rules! impl_client_v22__load_wallet {
27    () => {
28        impl Client {
29            pub fn load_wallet(&self, wallet: &str) -> Result<LoadWallet> {
30                self.call("loadwallet", &[wallet.into()])
31            }
32        }
33    };
34}
35
36/// Implements Bitcoin Core JSON-RPC API method `walletdisplayaddress`.
37#[macro_export]
38macro_rules! impl_client_v22__wallet_display_address {
39    () => {
40        impl Client {
41            pub fn wallet_display_address(&self, address: &str) -> Result<WalletDisplayAddress> {
42                self.call("walletdisplayaddress", &[address.into()])
43            }
44        }
45    };
46}
47
48/// Implements Bitcoin Core JSON-RPC API method `createwallet`.
49#[macro_export]
50macro_rules! impl_client_v22__create_wallet {
51    () => {
52        impl Client {
53            /// Creates a wallet with external_signer=true.
54            ///
55            /// > createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup external_signer )
56            /// >
57            /// > Creates and loads a new wallet.
58            /// >
59            /// > Arguments:
60            /// > 1. wallet_name             (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.
61            /// > 2. disable_private_keys    (boolean, optional, default=false) Disable the possibility of private keys (only watchonlys are possible in this mode).
62            /// > 3. blank                   (boolean, optional, default=false) Create a blank wallet. A blank wallet has no keys or HD seed. One can be set using sethdseed.
63            /// > 4. passphrase              (string, optional) Encrypt the wallet with this passphrase.
64            /// > 5. avoid_reuse             (boolean, optional, default=false) Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind.
65            /// > 6. descriptors             (boolean, optional, default=true) Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation
66            /// > 7. load_on_startup         (boolean, optional) Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged.
67            /// > 8. external_signer         (boolean, optional, default=false) Use an external signer such as a hardware wallet. Requires -signer to be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys and descriptors set to true.
68            pub fn create_wallet_external_signer(&self, wallet: &str) -> Result<CreateWallet> {
69                let disable_private_keys = true;
70                let blank = false;
71                let passphrase = String::new();
72                let avoid_reuse = false;
73                let descriptors = true;
74                let load_on_startup = false;
75                let external_signer = true;
76
77                self.call(
78                    "createwallet",
79                    &[
80                        wallet.into(),
81                        disable_private_keys.into(),
82                        blank.into(),
83                        passphrase.into(),
84                        avoid_reuse.into(),
85                        descriptors.into(),
86                        load_on_startup.into(),
87                        external_signer.into(),
88                    ],
89                )
90            }
91        }
92    };
93}