Skip to content

Commit

Permalink
Merge pull request #756 from zancas/debug_clap_cli
Browse files Browse the repository at this point in the history
Debug clap cli
  • Loading branch information
fluidvanadium authored Dec 14, 2023
2 parents 588ac64 + 0de7dc6 commit 6f020eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion zingocli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.2.0"
edition = "2021"

[dependencies]
zingolib = { path = "../zingolib/" }
zingolib = { path = "../zingolib/", features = ["deprecations"] }
zingoconfig = { path = "../zingoconfig/" }
zingo-testutils = { path = "../zingo-testutils" }

Expand Down
28 changes: 25 additions & 3 deletions zingocli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ pub fn build_clap_app() -> clap::ArgMatches {
.alias("seed")
.alias("viewing-key")
.value_name("from")
.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"))
.arg(Arg::new("birthday")
.long("birthday")
.value_name("birthday")
.value_parser(clap::value_parser!(u32))
.help("Specify wallet birthday when restoring from seed. This is the earlist block height where the wallet has a transaction."))
.arg(Arg::new("server")
.long("server")
.value_name("server")
.help("Lightwalletd server to connect to.")
.value_parser(parse_uri)
.default_value(zingoconfig::DEFAULT_LIGHTWALLETD_SERVER))
.arg(Arg::new("data-dir")
.long("data-dir")
Expand All @@ -65,6 +68,25 @@ pub fn build_clap_app() -> clap::ArgMatches {
).get_matches()
}

/// Custom function to parse a string into an http::Uri
fn parse_uri(s: &str) -> Result<http::Uri, String> {
s.parse::<http::Uri>().map_err(|e| e.to_string())
}
/// Custom function to parse a string into a compliant ZIP32/BIP39 mnemonic phrase
/// currently this is just a whitespace delimited string of 24 words. I am
/// poking around to use the actual BIP39 parser (presumably from librustzcash).
fn parse_seed(s: &str) -> Result<String, String> {
if let Ok(s) = s.parse::<String>() {
let count = s.split_whitespace().count();
if count == 24 {
Ok(s)
} else {
Err(format!("Expected 24 words, but received: {}.", count))
}
} else {
Err("Unexpected failure to parse String!!".to_string())
}
}
#[cfg(target_os = "linux")]
/// This function is only tested against Linux.
fn report_permission_error() {
Expand Down Expand Up @@ -280,9 +302,9 @@ impl ConfigTemplate {
} else {
None
};
let from = matches.get_one::<&str>("from");
let from = matches.get_one::<String>("from");
let maybe_birthday = matches
.get_one::<&str>("birthday")
.get_one::<u32>("birthday")
.map(|bday| bday.to_string());
if from.is_some() && maybe_birthday.is_none() {
eprintln!("ERROR!");
Expand Down Expand Up @@ -322,7 +344,7 @@ to scan from the start of the blockchain."
};
log::info!("data_dir: {}", &data_dir.to_str().unwrap());
let mut server = matches
.get_one::<String>("server")
.get_one::<http::Uri>("server")
.map(|server| server.to_string());
let mut child_process_handler = None;
// Regtest specific launch:
Expand Down

0 comments on commit 6f020eb

Please sign in to comment.