Skip to content

Commit f00ea0f

Browse files
committed
Merge #293: Follow up to v21 TODO
e396ad0 Improve import_descriptors test (Jamil Lambert, PhD) 746c5dc Add a constructor for ImportDescriptorsRequest (Jamil Lambert, PhD) 4f534f3 Rewrite create descriptor wallet client macro (Jamil Lambert, PhD) 62e01e5 Improve getindexinfo test (Jamil Lambert, PhD) Pull request description: There were a couple of points in the review of #289 that needed to be addressed. Improve the tests as suggested, and add a comment to the rustdocs. Redefine the `create_wallet` client macro so that for v21 and v22 where the default is a legacy wallet there is a separate function to create a descriptor wallet. Similarly for v23 and above where the default is a descriptor wallet there is a separate function to create a legacy wallet. Closes #292 ACKs for top commit: tcharding: ACK e396ad0 Tree-SHA512: e035315a926e9a789068a72b0e21f838f30d5c7feb2eba7245dbeea73f500b0c433a11b24620e5141550199a3173cabf3bb478b174d34194806f89b020b8eb05
2 parents 68700ef + e396ad0 commit f00ea0f

File tree

13 files changed

+104
-40
lines changed

13 files changed

+104
-40
lines changed

client/src/client_sync/v21/mod.rs

Lines changed: 8 additions & 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!();
@@ -193,3 +192,10 @@ pub struct ImportDescriptorsRequest {
193192
/// Time from which to start rescanning the blockchain for this descriptor, in UNIX epoch time or "now".
194193
pub timestamp: serde_json::Value,
195194
}
195+
196+
impl ImportDescriptorsRequest {
197+
/// Constructs a new ImportDescriptorsRequest.
198+
pub fn new(descriptor: impl Into<String>, timestamp: impl Into<serde_json::Value>) -> Self {
199+
ImportDescriptorsRequest { descriptor: descriptor.into(), timestamp: timestamp.into() }
200+
}
201+
}

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)