Skip to content

Commit 4f0a70a

Browse files
committed
Add the descriptor argument to createwallet
1 parent b469e3f commit 4f0a70a

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

client/src/client.rs

+47-11
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

+2
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 {

0 commit comments

Comments
 (0)