From 53876cdffffd5a698a006e45c1c183a3680493bf Mon Sep 17 00:00:00 2001 From: Oscar Pepper Date: Sun, 13 Oct 2024 14:10:15 +0100 Subject: [PATCH 1/3] fixes 24 word parsing error for ufvks --- zingocli/src/lib.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/zingocli/src/lib.rs b/zingocli/src/lib.rs index 23c0f9a2e..aa89d6ba9 100644 --- a/zingocli/src/lib.rs +++ b/zingocli/src/lib.rs @@ -37,15 +37,16 @@ pub fn build_clap_app() -> clap::ArgMatches { .arg(Arg::new("chain") .long("chain").short('c') .help(r#"What chain to expect, if it's not inferable from the server URI. One of "mainnet", "testnet", or "regtest""#)) - .arg(Arg::new("from") - .short('f') - .short_alias('s') - .long("from") - .alias("seed") - .alias("viewing-key") - .value_name("from") + .arg(Arg::new("seed") + .short('s') + .long("seed") + .value_name("SEED") .value_parser(parse_seed) - .help("Create a new wallet with the given key. Can be a 24-word seed phrase or a viewkey. Will fail if wallet already exists")) + .help("Create a new wallet with the given 24-word seed phrase. Will fail if wallet already exists")) + .arg(Arg::new("viewkey`") + .long("viewkey") + .value_name("UFVK") + .help("Create a new wallet with the given encoded unified full viewing key. Will fail if wallet already exists")) .arg(Arg::new("birthday") .long("birthday") .value_name("birthday") @@ -295,7 +296,17 @@ impl ConfigTemplate { } else { None }; - let from = matches.get_one::("from"); + let seed = matches.get_one::("seed"); + let viewkey = matches.get_one::("viewkey"); + let from = if seed.is_some() && viewkey.is_some() { + return Err("Cannot load a wallet from both seed phrase and viewkey!".to_string()); + } else if seed.is_some() { + seed + } else if viewkey.is_some() { + viewkey + } else { + None + }; let maybe_birthday = matches .get_one::("birthday") .map(|bday| bday.to_string()); From 47648fd1143033c3c470d61add279a7c403db992 Mon Sep 17 00:00:00 2001 From: Oscar Pepper Date: Mon, 14 Oct 2024 09:50:25 +0100 Subject: [PATCH 2/3] fix viewkey id --- zingocli/src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/zingocli/src/lib.rs b/zingocli/src/lib.rs index aa89d6ba9..ad2961a3e 100644 --- a/zingocli/src/lib.rs +++ b/zingocli/src/lib.rs @@ -40,12 +40,13 @@ pub fn build_clap_app() -> clap::ArgMatches { .arg(Arg::new("seed") .short('s') .long("seed") - .value_name("SEED") + .value_name("SEED PHRASE") .value_parser(parse_seed) .help("Create a new wallet with the given 24-word seed phrase. Will fail if wallet already exists")) - .arg(Arg::new("viewkey`") + .arg(Arg::new("viewkey") .long("viewkey") .value_name("UFVK") + .value_parser(parse_ufvk) .help("Create a new wallet with the given encoded unified full viewing key. Will fail if wallet already exists")) .arg(Arg::new("birthday") .long("birthday") @@ -94,6 +95,19 @@ fn parse_seed(s: &str) -> Result { Err("Unexpected failure to parse String!!".to_string()) } } +/// Parse encoded UFVK to String and check for whitespaces +fn parse_ufvk(s: &str) -> Result { + if let Ok(s) = s.parse::() { + let count = s.split_whitespace().count(); + if count == 1 { + Ok(s) + } else { + Err(format!("Encoded UFVK should not contain whitespace!")) + } + } else { + Err("Unexpected failure to parse String!!".to_string()) + } +} #[cfg(target_os = "linux")] /// This function is only tested against Linux. fn report_permission_error() { @@ -283,6 +297,7 @@ fn short_circuit_on_help(params: Vec) { impl ConfigTemplate { fn fill(matches: clap::ArgMatches) -> Result { let is_regtest = matches.get_flag("regtest"); // Begin short_circuit section + let params = if let Some(vals) = matches.get_many::("extra_args") { vals.cloned().collect() } else { From 21ddf4e80825a19e74ce09608e96a7109974a05c Mon Sep 17 00:00:00 2001 From: Oscar Pepper Date: Mon, 14 Oct 2024 14:52:31 +0100 Subject: [PATCH 3/3] fix clippy warnings --- zingocli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zingocli/src/lib.rs b/zingocli/src/lib.rs index ad2961a3e..33c37c86b 100644 --- a/zingocli/src/lib.rs +++ b/zingocli/src/lib.rs @@ -102,7 +102,7 @@ fn parse_ufvk(s: &str) -> Result { if count == 1 { Ok(s) } else { - Err(format!("Encoded UFVK should not contain whitespace!")) + Err("Encoded UFVK should not contain whitespace!".to_string()) } } else { Err("Unexpected failure to parse String!!".to_string())