From: Riccardo Casatta Date: Tue, 21 Sep 2021 13:32:52 +0000 (+0200) Subject: Use directly FromStr types in StructOpt X-Git-Tag: v0.3.0~9^2~1 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/enum.FromScriptError.html?a=commitdiff_plain;h=2b37b921388de0c3d395054270752d41ec8c5ffa;p=bdk-cli Use directly FromStr types in StructOpt With wrong values instead of getting: [2021-09-21T13:25:13Z ERROR bdk_cli] Bip32(Base58(BadChecksum(1292914229, 1275556062))) you get: error: Invalid value for '--xprv ': base58 encoding error: base58ck checksum 0x4c0770de does not match expected 0x4d104e35 --- diff --git a/src/lib.rs b/src/lib.rs index ac8d6dd..e62b4f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -973,10 +973,10 @@ pub enum KeySubCommand { Derive { /// Extended private key to derive from #[structopt(name = "XPRV", short = "x", long = "xprv")] - xprv: String, + xprv: ExtendedPrivKey, /// Path to use to derive extended public key from extended private key #[structopt(name = "PATH", short = "p", long = "path")] - path: String, + path: DerivationPath, }, } @@ -1021,14 +1021,12 @@ pub fn handle_key_subcommand( Ok(json!({ "xprv": xprv.to_string(), "fingerprint": fingerprint.to_string() })) } KeySubCommand::Derive { xprv, path } => { - let xprv = ExtendedPrivKey::from_str(xprv.as_str())?; if xprv.network != network { return Err(Error::Key(InvalidNetwork)); } - let deriv_path: DerivationPath = DerivationPath::from_str(path.as_str())?; - let derived_xprv = &xprv.derive_priv(&secp, &deriv_path)?; + let derived_xprv = &xprv.derive_priv(&secp, &path)?; - let origin: KeySource = (xprv.fingerprint(&secp), deriv_path); + let origin: KeySource = (xprv.fingerprint(&secp), path); let derived_xprv_desc_key: DescriptorKey = derived_xprv.into_descriptor_key(Some(origin), DerivationPath::default())?;