Skip to content

Commit 11a0201

Browse files
committed
Rewrite create descriptor wallet client macro
Change the client macro for v21 to match the style of the v23 definition. Only use this for v21 and v22 where the default wallet is a legacy wallet. Change the test to use the new function. Add a comment to the v23 definition clarifying why the legacy wallet function is needed.
1 parent 6e86402 commit 11a0201

File tree

12 files changed

+46
-28
lines changed

12 files changed

+46
-28
lines changed

client/src/client_sync/v21/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ crate::impl_client_v17__abort_rescan!();
128128
crate::impl_client_v17__add_multisig_address!();
129129
crate::impl_client_v17__backup_wallet!();
130130
crate::impl_client_v17__bump_fee!();
131-
crate::impl_client_v17__create_wallet!();
132-
crate::impl_client_v21__create_wallet_with_descriptors!();
131+
crate::impl_client_v21__create_wallet!();
133132
crate::impl_client_v17__dump_priv_key!();
134133
crate::impl_client_v17__dump_wallet!();
135134
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v21/wallet.rs

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,50 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12-
/// Implements Bitcoin Core JSON-RPC API method `createwallet` with descriptors=true (descriptor wallet)
13-
///
14-
/// This is a helper function only needed in v21 and v22 to create a wallet with descriptors.
15-
/// From v23 onwards descriptors=true is the default.
12+
/// Implements Bitcoin Core JSON-RPC API method `createwallet`.
1613
#[macro_export]
17-
macro_rules! impl_client_v21__create_wallet_with_descriptors {
14+
macro_rules! impl_client_v21__create_wallet {
1815
() => {
1916
impl Client {
20-
pub fn create_wallet_with_descriptors(&self, wallet: &str) -> Result<CreateWallet> {
21-
let args = [
22-
wallet.into(),
23-
false.into(), // disable_private_keys
24-
false.into(), // blank
25-
serde_json::Value::Null, // passphrase
26-
false.into(), // avoid_reuse
27-
true.into(), // descriptors=true
28-
serde_json::Value::Null, // load_on_startup
29-
];
30-
self.call("createwallet", &args)
17+
/// Calls `createwallet` with `wallet` as the only argument.
18+
/// In v21 and v22 this creates a legacy wallet. Use `create_descriptor_wallet` to create
19+
/// a descriptor wallet.
20+
pub fn create_wallet(&self, wallet: &str) -> Result<CreateWallet> {
21+
self.call("createwallet", &[wallet.into()])
22+
}
23+
24+
/// Creates a wallet with descriptors=true (descriptor wallet).
25+
///
26+
/// > createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup )
27+
/// >
28+
/// > Creates and loads a new wallet.
29+
/// >
30+
/// > Arguments:
31+
/// > 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.
32+
/// > 2. disable_private_keys (boolean, optional, default=false) Disable the possibility of private keys (only watchonlys are possible in this mode).
33+
/// > 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.
34+
/// > 4. passphrase (string, optional) Encrypt the wallet with this passphrase.
35+
/// > 5. avoid_reuse (boolean, optional, default=false) Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind.
36+
/// > 6. descriptors (boolean, optional, default=true) Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation
37+
/// > 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.
38+
pub fn create_descriptor_wallet(&self, wallet: &str) -> Result<CreateWallet> {
39+
let disable_private_keys = false;
40+
let blank = false;
41+
let passphrase = String::new();
42+
let avoid_reuse = false;
43+
let descriptors = true;
44+
45+
self.call(
46+
"createwallet",
47+
&[
48+
wallet.into(),
49+
disable_private_keys.into(),
50+
blank.into(),
51+
passphrase.into(),
52+
avoid_reuse.into(),
53+
descriptors.into(),
54+
],
55+
)
3156
}
3257
}
3358
};

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ crate::impl_client_v17__abort_rescan!();
126126
crate::impl_client_v17__add_multisig_address!();
127127
crate::impl_client_v17__backup_wallet!();
128128
crate::impl_client_v17__bump_fee!();
129-
crate::impl_client_v17__create_wallet!();
130-
crate::impl_client_v21__create_wallet_with_descriptors!();
129+
crate::impl_client_v21__create_wallet!();
131130
crate::impl_client_v17__dump_priv_key!();
132131
crate::impl_client_v17__dump_wallet!();
133132
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v23/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ crate::impl_client_v17__add_multisig_address!();
129129
crate::impl_client_v17__backup_wallet!();
130130
crate::impl_client_v17__bump_fee!();
131131
crate::impl_client_v23__create_wallet!();
132-
crate::impl_client_v21__create_wallet_with_descriptors!();
133132
crate::impl_client_v17__dump_priv_key!();
134133
crate::impl_client_v17__dump_wallet!();
135134
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v23/wallet.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ macro_rules! impl_client_v23__create_wallet {
1515
() => {
1616
impl Client {
1717
/// Calls `createwallet` with `wallet` as the only argument.
18+
/// In v23 and later this creates a descriptor wallet. Use `create_legacy_wallet` to create
19+
/// a legacy wallet.
1820
pub fn create_wallet(&self, wallet: &str) -> Result<CreateWallet> {
1921
self.call("createwallet", &[wallet.into()])
2022
}

client/src/client_sync/v24/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ crate::impl_client_v17__add_multisig_address!();
126126
crate::impl_client_v17__backup_wallet!();
127127
crate::impl_client_v17__bump_fee!();
128128
crate::impl_client_v23__create_wallet!();
129-
crate::impl_client_v21__create_wallet_with_descriptors!();
130129
crate::impl_client_v17__dump_priv_key!();
131130
crate::impl_client_v17__dump_wallet!();
132131
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v25/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ crate::impl_client_v17__add_multisig_address!();
128128
crate::impl_client_v17__backup_wallet!();
129129
crate::impl_client_v17__bump_fee!();
130130
crate::impl_client_v23__create_wallet!();
131-
crate::impl_client_v21__create_wallet_with_descriptors!();
132131
crate::impl_client_v17__dump_priv_key!();
133132
crate::impl_client_v17__dump_wallet!();
134133
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v26/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ crate::impl_client_v17__add_multisig_address!();
132132
crate::impl_client_v17__backup_wallet!();
133133
crate::impl_client_v17__bump_fee!();
134134
crate::impl_client_v23__create_wallet!();
135-
crate::impl_client_v21__create_wallet_with_descriptors!();
136135
crate::impl_client_v17__dump_priv_key!();
137136
crate::impl_client_v17__dump_wallet!();
138137
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v27/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ crate::impl_client_v17__add_multisig_address!();
128128
crate::impl_client_v17__backup_wallet!();
129129
crate::impl_client_v17__bump_fee!();
130130
crate::impl_client_v23__create_wallet!();
131-
crate::impl_client_v21__create_wallet_with_descriptors!();
132131
crate::impl_client_v17__dump_priv_key!();
133132
crate::impl_client_v17__dump_wallet!();
134133
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v28/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ crate::impl_client_v17__add_multisig_address!();
130130
crate::impl_client_v17__backup_wallet!();
131131
crate::impl_client_v17__bump_fee!();
132132
crate::impl_client_v23__create_wallet!();
133-
crate::impl_client_v21__create_wallet_with_descriptors!();
134133
crate::impl_client_v17__dump_priv_key!();
135134
crate::impl_client_v17__dump_wallet!();
136135
crate::impl_client_v17__encrypt_wallet!();

0 commit comments

Comments
 (0)