Skip to content

Commit

Permalink
Add the descriptor argument to createwallet
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Feb 17, 2023
1 parent b469e3f commit 4f0a70a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
58 changes: 47 additions & 11 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,54 @@ pub trait RpcApi: Sized {
blank: Option<bool>,
passphrase: Option<&str>,
avoid_reuse: Option<bool>,
descriptors: Option<bool>,
) -> Result<json::LoadWalletResult> {
let mut args = [
wallet.into(),
opt_into_json(disable_private_keys)?,
opt_into_json(blank)?,
opt_into_json(passphrase)?,
opt_into_json(avoid_reuse)?,
];
self.call(
"createwallet",
handle_defaults(&mut args, &[false.into(), false.into(), into_json("")?, false.into()]),
)
// the descriptors argument was added in version 21
if self.version()? < 210000 {
// note: we allow Some(false) since it's the default behavior
if let Some(true) = descriptors {
return Err(Error::Unsupported);
}
// no descriptors argument yet
let mut args = [
wallet.into(),
opt_into_json(disable_private_keys)?,
opt_into_json(blank)?,
opt_into_json(passphrase)?,
opt_into_json(avoid_reuse)?,
];
self.call(
"createwallet",
handle_defaults(
&mut args,
&[false.into(), false.into(), into_json("")?, false.into()],
),
)
} else {
let mut args = [
wallet.into(),
opt_into_json(disable_private_keys)?,
opt_into_json(blank)?,
opt_into_json(passphrase)?,
opt_into_json(avoid_reuse)?,
opt_into_json(descriptors)?,
];
// from 23 on, the default value of the descriptors argument is true
let default_descriptors = self.version()? >= 230000;
self.call(
"createwallet",
handle_defaults(
&mut args,
&[
false.into(),
false.into(),
into_json("")?,
false.into(),
default_descriptors.into(),
],
),
)
}
}

fn list_wallets(&self) -> Result<Vec<String>> {
Expand Down
2 changes: 2 additions & 0 deletions client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum Error {
UnexpectedStructure,
/// The daemon returned an error string.
ReturnedError(String),
/// Feature not supported by the connected bitcoin version.
Unsupported,
}

impl From<jsonrpc::error::Error> for Error {
Expand Down

0 comments on commit 4f0a70a

Please sign in to comment.