Skip to content

Commit 39a6739

Browse files
committed
Add the descriptor argument to createwallet
1 parent b469e3f commit 39a6739

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

client/src/client.rs

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

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

client/src/error.rs

Lines changed: 5 additions & 0 deletions
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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn main() {
131131
unsafe { VERSION = cl.version().unwrap() };
132132
println!("Version: {}", version());
133133

134-
cl.create_wallet("testwallet", None, None, None, None).unwrap();
134+
cl.create_wallet("testwallet", None, None, None, None, None).unwrap();
135135

136136
test_get_mining_info(&cl);
137137
test_get_blockchain_info(&cl);
@@ -1062,6 +1062,7 @@ fn test_create_wallet(cl: &Client) {
10621062
blank: Option<bool>,
10631063
passphrase: Option<&'a str>,
10641064
avoid_reuse: Option<bool>,
1065+
descriptor: Option<bool>,
10651066
}
10661067

10671068
let mut wallet_params = vec![
@@ -1071,20 +1072,23 @@ fn test_create_wallet(cl: &Client) {
10711072
blank: None,
10721073
passphrase: None,
10731074
avoid_reuse: None,
1075+
descriptor: None,
10741076
},
10751077
WalletParams {
10761078
name: wallet_names[1],
10771079
disable_private_keys: Some(true),
10781080
blank: None,
10791081
passphrase: None,
10801082
avoid_reuse: None,
1083+
descriptor: None,
10811084
},
10821085
WalletParams {
10831086
name: wallet_names[2],
10841087
disable_private_keys: None,
10851088
blank: Some(true),
10861089
passphrase: None,
10871090
avoid_reuse: None,
1091+
descriptor: None,
10881092
},
10891093
];
10901094

@@ -1095,13 +1099,15 @@ fn test_create_wallet(cl: &Client) {
10951099
blank: None,
10961100
passphrase: Some("pass"),
10971101
avoid_reuse: None,
1102+
descriptor: None,
10981103
});
10991104
wallet_params.push(WalletParams {
11001105
name: wallet_names[4],
11011106
disable_private_keys: None,
11021107
blank: None,
11031108
passphrase: None,
11041109
avoid_reuse: Some(true),
1110+
descriptor: Some(false),
11051111
});
11061112
}
11071113

@@ -1113,6 +1119,7 @@ fn test_create_wallet(cl: &Client) {
11131119
wallet_param.blank,
11141120
wallet_param.passphrase,
11151121
wallet_param.avoid_reuse,
1122+
wallet_param.descriptor,
11161123
)
11171124
.unwrap();
11181125

0 commit comments

Comments
 (0)