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 39a6739
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 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
5 changes: 5 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 Expand Up @@ -88,6 +90,9 @@ impl fmt::Display for Error {
Error::InvalidCookieFile => write!(f, "invalid cookie file"),
Error::UnexpectedStructure => write!(f, "the JSON result had an unexpected structure"),
Error::ReturnedError(ref s) => write!(f, "the daemon returned an error string: {}", s),
Error::Unsupported => {
write!(f, "the daemon version does not support the accessed feature")
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn main() {
unsafe { VERSION = cl.version().unwrap() };
println!("Version: {}", version());

cl.create_wallet("testwallet", None, None, None, None).unwrap();
cl.create_wallet("testwallet", None, None, None, None, None).unwrap();

test_get_mining_info(&cl);
test_get_blockchain_info(&cl);
Expand Down Expand Up @@ -1062,6 +1062,7 @@ fn test_create_wallet(cl: &Client) {
blank: Option<bool>,
passphrase: Option<&'a str>,
avoid_reuse: Option<bool>,
descriptor: Option<bool>,
}

let mut wallet_params = vec![
Expand All @@ -1071,20 +1072,23 @@ fn test_create_wallet(cl: &Client) {
blank: None,
passphrase: None,
avoid_reuse: None,
descriptor: None,
},
WalletParams {
name: wallet_names[1],
disable_private_keys: Some(true),
blank: None,
passphrase: None,
avoid_reuse: None,
descriptor: None,
},
WalletParams {
name: wallet_names[2],
disable_private_keys: None,
blank: Some(true),
passphrase: None,
avoid_reuse: None,
descriptor: None,
},
];

Expand All @@ -1095,13 +1099,15 @@ fn test_create_wallet(cl: &Client) {
blank: None,
passphrase: Some("pass"),
avoid_reuse: None,
descriptor: None,
});
wallet_params.push(WalletParams {
name: wallet_names[4],
disable_private_keys: None,
blank: None,
passphrase: None,
avoid_reuse: Some(true),
descriptor: Some(false),
});
}

Expand All @@ -1113,6 +1119,7 @@ fn test_create_wallet(cl: &Client) {
wallet_param.blank,
wallet_param.passphrase,
wallet_param.avoid_reuse,
wallet_param.descriptor,
)
.unwrap();

Expand Down

0 comments on commit 39a6739

Please sign in to comment.