Skip to content

Commit 4f534f3

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 62e01e5 commit 4f534f3

File tree

12 files changed

+55
-26
lines changed

12 files changed

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

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ crate::impl_client_v17__abort_rescan!();
130130
crate::impl_client_v17__add_multisig_address!();
131131
crate::impl_client_v17__backup_wallet!();
132132
crate::impl_client_v17__bump_fee!();
133-
crate::impl_client_v17__create_wallet!();
134-
crate::impl_client_v21__create_wallet_with_descriptors!();
133+
crate::impl_client_v21__create_wallet!();
135134
crate::impl_client_v17__dump_priv_key!();
136135
crate::impl_client_v17__dump_wallet!();
137136
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
@@ -134,7 +134,6 @@ crate::impl_client_v17__add_multisig_address!();
134134
crate::impl_client_v17__backup_wallet!();
135135
crate::impl_client_v17__bump_fee!();
136136
crate::impl_client_v23__create_wallet!();
137-
crate::impl_client_v21__create_wallet_with_descriptors!();
138137
crate::impl_client_v17__dump_priv_key!();
139138
crate::impl_client_v17__dump_wallet!();
140139
crate::impl_client_v17__encrypt_wallet!();

client/src/client_sync/v23/wallet.rs

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

client/src/client_sync/v24/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ crate::impl_client_v17__add_multisig_address!();
131131
crate::impl_client_v17__backup_wallet!();
132132
crate::impl_client_v17__bump_fee!();
133133
crate::impl_client_v23__create_wallet!();
134-
crate::impl_client_v21__create_wallet_with_descriptors!();
135134
crate::impl_client_v17__dump_priv_key!();
136135
crate::impl_client_v17__dump_wallet!();
137136
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
@@ -133,7 +133,6 @@ crate::impl_client_v17__add_multisig_address!();
133133
crate::impl_client_v17__backup_wallet!();
134134
crate::impl_client_v17__bump_fee!();
135135
crate::impl_client_v23__create_wallet!();
136-
crate::impl_client_v21__create_wallet_with_descriptors!();
137136
crate::impl_client_v17__dump_priv_key!();
138137
crate::impl_client_v17__dump_wallet!();
139138
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
@@ -137,7 +137,6 @@ crate::impl_client_v17__add_multisig_address!();
137137
crate::impl_client_v17__backup_wallet!();
138138
crate::impl_client_v17__bump_fee!();
139139
crate::impl_client_v23__create_wallet!();
140-
crate::impl_client_v21__create_wallet_with_descriptors!();
141140
crate::impl_client_v17__dump_priv_key!();
142141
crate::impl_client_v17__dump_wallet!();
143142
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
@@ -133,7 +133,6 @@ crate::impl_client_v17__add_multisig_address!();
133133
crate::impl_client_v17__backup_wallet!();
134134
crate::impl_client_v17__bump_fee!();
135135
crate::impl_client_v23__create_wallet!();
136-
crate::impl_client_v21__create_wallet_with_descriptors!();
137136
crate::impl_client_v17__dump_priv_key!();
138137
crate::impl_client_v17__dump_wallet!();
139138
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
@@ -135,7 +135,6 @@ crate::impl_client_v17__add_multisig_address!();
135135
crate::impl_client_v17__backup_wallet!();
136136
crate::impl_client_v17__bump_fee!();
137137
crate::impl_client_v23__create_wallet!();
138-
crate::impl_client_v21__create_wallet_with_descriptors!();
139138
crate::impl_client_v17__dump_priv_key!();
140139
crate::impl_client_v17__dump_wallet!();
141140
crate::impl_client_v17__encrypt_wallet!();

0 commit comments

Comments
 (0)