]> Untitled Git - bdk-cli/commitdiff
Use directly FromStr types in StructOpt
authorRiccardo Casatta <riccardo@casatta.it>
Tue, 21 Sep 2021 13:32:52 +0000 (15:32 +0200)
committerRiccardo Casatta <riccardo@casatta.it>
Tue, 21 Sep 2021 13:32:52 +0000 (15:32 +0200)
With wrong values instead of getting:
[2021-09-21T13:25:13Z ERROR bdk_cli] Bip32(Base58(BadChecksum(12929142291275556062)))

you get:
error: Invalid value for '--xprv <XPRV>': base58 encoding error: base58ck checksum 0x4c0770de does not match expected 0x4d104e35

src/lib.rs

index ac8d6dd81572d67207cb31e681533754612b9e4a..e62b4f73e1ca3e9c7b5382ed209f9386c0d9b8d9 100644 (file)
@@ -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<Segwitv0> =
                 derived_xprv.into_descriptor_key(Some(origin), DerivationPath::default())?;