corepc_client/client_sync/v23/
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 `v23`.
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 `createwallet`.
13#[macro_export]
14macro_rules! impl_client_v23__createwallet {
15    () => {
16        impl Client {
17            /// Calls `createwallet` with `wallet` as the only argument.
18            pub fn create_wallet(&self, wallet: &str) -> Result<CreateWallet> {
19                self.call("createwallet", &[wallet.into()])
20            }
21
22            /// Creates a legacy wallet (i.e not a native descriptor wallet).
23            ///
24            /// > createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup external_signer )
25            /// >
26            /// > Creates and loads a new wallet.
27            /// >
28            /// > Arguments:
29            /// > 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.
30            /// > 2. disable_private_keys    (boolean, optional, default=false) Disable the possibility of private keys (only watchonlys are possible in this mode).
31            /// > 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.
32            /// > 4. passphrase              (string, optional) Encrypt the wallet with this passphrase.
33            /// > 5. avoid_reuse             (boolean, optional, default=false) Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind.
34            /// > 6. descriptors             (boolean, optional, default=true) Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation
35            /// > 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.
36            /// > 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.
37            pub fn create_legacy_wallet(&self, wallet: &str) -> Result<CreateWallet> {
38                let disable_private_keys = false;
39                let blank = false;
40                let passphrase = String::new();
41                let avoid_reuse = false;
42                let descriptors = false;
43
44                self.call(
45                    "createwallet",
46                    &[
47                        wallet.into(),
48                        disable_private_keys.into(),
49                        blank.into(),
50                        passphrase.into(),
51                        avoid_reuse.into(),
52                        descriptors.into(),
53                    ],
54                )
55            }
56        }
57    };
58}