Skip to content

Commit e51c69c

Browse files
committed
Add the descriptor argument to createwallet
1 parent 7bd815f commit e51c69c

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

client/src/client.rs

+47-11
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,54 @@ pub trait RpcApi: Sized {
284284
blank: Option<bool>,
285285
passphrase: Option<&str>,
286286
avoid_reuse: Option<bool>,
287+
descriptors: Option<bool>,
287288
) -> Result<json::LoadWalletResult> {
288-
let mut args = [
289-
wallet.into(),
290-
opt_into_json(disable_private_keys)?,
291-
opt_into_json(blank)?,
292-
opt_into_json(passphrase)?,
293-
opt_into_json(avoid_reuse)?,
294-
];
295-
self.call(
296-
"createwallet",
297-
handle_defaults(&mut args, &[false.into(), false.into(), into_json("")?, false.into()]),
298-
)
289+
// the descriptors argument was added in version 21
290+
if self.version()? < 210000 {
291+
// note: we allow Some(false) since it's the default behavior
292+
if let Some(true) = descriptors {
293+
return Err(Error::Unsupported);
294+
}
295+
// no descriptors argument yet
296+
let mut args = [
297+
wallet.into(),
298+
opt_into_json(disable_private_keys)?,
299+
opt_into_json(blank)?,
300+
opt_into_json(passphrase)?,
301+
opt_into_json(avoid_reuse)?,
302+
];
303+
self.call(
304+
"createwallet",
305+
handle_defaults(
306+
&mut args,
307+
&[false.into(), false.into(), into_json("")?, false.into()],
308+
),
309+
)
310+
} else {
311+
let mut args = [
312+
wallet.into(),
313+
opt_into_json(disable_private_keys)?,
314+
opt_into_json(blank)?,
315+
opt_into_json(passphrase)?,
316+
opt_into_json(avoid_reuse)?,
317+
opt_into_json(descriptors)?,
318+
];
319+
// from 23 on, the default value of the descriptors argument is true
320+
let default_descriptors = self.version()? >= 230000;
321+
self.call(
322+
"createwallet",
323+
handle_defaults(
324+
&mut args,
325+
&[
326+
false.into(),
327+
false.into(),
328+
into_json("")?,
329+
false.into(),
330+
default_descriptors.into(),
331+
],
332+
),
333+
)
334+
}
299335
}
300336

301337
fn list_wallets(&self) -> Result<Vec<String>> {

client/src/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub enum Error {
3131
UnexpectedStructure,
3232
/// The daemon returned an error string.
3333
ReturnedError(String),
34+
/// Feature not supported by the connected bitcoin version.
35+
Unsupported,
3436
}
3537

3638
impl From<jsonrpc::error::Error> for Error {
@@ -88,6 +90,9 @@ impl fmt::Display for Error {
8890
Error::InvalidCookieFile => write!(f, "invalid cookie file"),
8991
Error::UnexpectedStructure => write!(f, "the JSON result had an unexpected structure"),
9092
Error::ReturnedError(ref s) => write!(f, "the daemon returned an error string: {}", s),
93+
Error::Unsupported => {
94+
write!(f, "the daemon version does not support the accessed feature")
95+
}
9196
}
9297
}
9398
}

integration_test/src/main.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn main() {
140140
unsafe { VERSION = cl.version().unwrap() };
141141
println!("Version: {}", version());
142142

143-
cl.create_wallet("testwallet", None, None, None, None).unwrap();
143+
cl.create_wallet("testwallet", None, None, None, None, None).unwrap();
144144

145145
test_get_mining_info(&cl);
146146
test_get_blockchain_info(&cl);
@@ -1074,6 +1074,7 @@ fn test_create_wallet(cl: &Client) {
10741074
blank: Option<bool>,
10751075
passphrase: Option<&'a str>,
10761076
avoid_reuse: Option<bool>,
1077+
descriptor: Option<bool>,
10771078
}
10781079

10791080
let mut wallet_params = vec![
@@ -1083,20 +1084,23 @@ fn test_create_wallet(cl: &Client) {
10831084
blank: None,
10841085
passphrase: None,
10851086
avoid_reuse: None,
1087+
descriptor: None,
10861088
},
10871089
WalletParams {
10881090
name: wallet_names[1],
10891091
disable_private_keys: Some(true),
10901092
blank: None,
10911093
passphrase: None,
10921094
avoid_reuse: None,
1095+
descriptor: None,
10931096
},
10941097
WalletParams {
10951098
name: wallet_names[2],
10961099
disable_private_keys: None,
10971100
blank: Some(true),
10981101
passphrase: None,
10991102
avoid_reuse: None,
1103+
descriptor: None,
11001104
},
11011105
];
11021106

@@ -1107,13 +1111,15 @@ fn test_create_wallet(cl: &Client) {
11071111
blank: None,
11081112
passphrase: Some("pass"),
11091113
avoid_reuse: None,
1114+
descriptor: None,
11101115
});
11111116
wallet_params.push(WalletParams {
11121117
name: wallet_names[4],
11131118
disable_private_keys: None,
11141119
blank: None,
11151120
passphrase: None,
11161121
avoid_reuse: Some(true),
1122+
descriptor: Some(false),
11171123
});
11181124
}
11191125

@@ -1125,6 +1131,7 @@ fn test_create_wallet(cl: &Client) {
11251131
wallet_param.blank,
11261132
wallet_param.passphrase,
11271133
wallet_param.avoid_reuse,
1134+
wallet_param.descriptor,
11281135
)
11291136
.unwrap();
11301137

0 commit comments

Comments
 (0)