Skip to content

Commit

Permalink
value parser for mnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Feb 24, 2024
1 parent 4743a2c commit e05b856
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
26 changes: 19 additions & 7 deletions account_manager/src/wallet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,29 @@ pub fn cli_app() -> Command {
.value_name("MNEMONIC_LENGTH")
.help("The number of words to use for the mnemonic phrase.")
.action(ArgAction::Set)
// TODO
// .value_parser(|len: &str| {
// match len.parse::<usize>().ok().and_then(|words| MnemonicType::for_word_count(words).ok()) {
// Some(_) => Ok(()),
// None => Err(format!("Mnemonic length must be one of {}", MNEMONIC_TYPES.iter().map(|t| t.word_count().to_string()).collect::<Vec<_>>().join(", "))),
// }
// })
.value_parser(check_mnemonic_length)
.default_value("24"),
)
}

fn check_mnemonic_length(len: &str) -> Result<String, String> {
match len
.parse::<usize>()
.ok()
.and_then(|words| MnemonicType::for_word_count(words).ok())
{
Some(_) => Ok(len.to_string()),
None => Err(format!(
"Mnemonic length must be one of {}",
MNEMONIC_TYPES
.iter()
.map(|t| t.word_count().to_string())
.collect::<Vec<_>>()
.join(", ")
)),
}
}

pub fn cli_run(matches: &ArgMatches, wallet_base_dir: PathBuf) -> Result<(), String> {
let mnemonic_output_path: Option<PathBuf> = clap_utils::parse_optional(matches, MNEMONIC_FLAG)?;

Expand Down
7 changes: 2 additions & 5 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,7 @@ pub fn get_config<E: EthSpec>(
client_config.chain.fork_choice_before_proposal_timeout_ms = timeout;
}

client_config.chain.always_reset_payload_statuses =
cli_args.get_flag("reset-payload-statuses");
client_config.chain.always_reset_payload_statuses = cli_args.get_flag("reset-payload-statuses");

client_config.chain.paranoid_block_proposal = cli_args.get_flag("paranoid-block-proposal");

Expand Down Expand Up @@ -959,7 +958,6 @@ pub fn parse_listening_addresses(
format!("Failed to parse --quic6-port as an integer: {parse_error}")
})?;


// Now put everything together
let listening_addresses = match (maybe_ipv4, maybe_ipv6) {
(None, None) => {
Expand Down Expand Up @@ -1057,7 +1055,6 @@ pub fn parse_listening_addresses(
ipv4_tcp_port + 1
});


// Defaults to 9090 when required
let ipv6_tcp_port = use_zero_ports
.then(unused_port::unused_tcp6_port)
Expand Down Expand Up @@ -1428,7 +1425,7 @@ pub fn set_network_config(
if config_str.as_str() == "disabled" {
None
} else {
Some(config_str.parse()?)
Some(config_str.parse()?)
}
// Enabled with a custom configuration
// Some(config_str.parse()?)
Expand Down
2 changes: 1 addition & 1 deletion lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ lazy_static! {
Allocator: {}\n\
Profile: {}\n\
Specs: mainnet (true), minimal ({}), gnosis ({})",
SHORT_VERSION.as_str(),
SHORT_VERSION.as_str(),
bls_library_name(),
have_sha_extensions(),
allocator_name(),
Expand Down
4 changes: 1 addition & 3 deletions testing/simulator/src/eth1_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
let node_count = *matches
.get_one::<usize>("nodes")
.expect("missing nodes default");
let proposer_nodes = *matches
.get_one::<usize>("proposer-nodes")
.unwrap_or(&0);
let proposer_nodes = *matches.get_one::<usize>("proposer-nodes").unwrap_or(&0);
println!("PROPOSER-NODES: {}", proposer_nodes);
let validators_per_node = *matches
.get_one::<usize>("validators_per_node")
Expand Down
3 changes: 2 additions & 1 deletion validator_client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ impl Config {

config.builder_boost_factor = parse_optional(cli_args, "builder-boost-factor")?;

config.enable_latency_measurement_service = cli_args.get_flag("latency-measurement-service");
config.enable_latency_measurement_service =
cli_args.get_flag("latency-measurement-service");

config.validator_registration_batch_size =
parse_required(cli_args, "validator-registration-batch-size")?;
Expand Down
6 changes: 3 additions & 3 deletions validator_manager/src/create_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn cli_app() -> Command {
Using this flag will save several seconds per validator if the \
user has an alternate strategy for submitting deposits.",
)
.action(ArgAction::SetTrue)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(SPECIFY_VOTING_KEYSTORE_PASSWORD_FLAG)
Expand All @@ -118,7 +118,7 @@ pub fn cli_app() -> Command {
necessary to keep backups of voting keystore passwords if the \
mnemonic is safely backed up.",
)
.action(ArgAction::SetTrue)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(ETH1_WITHDRAWAL_ADDRESS_FLAG)
Expand Down Expand Up @@ -217,7 +217,7 @@ pub fn cli_app() -> Command {
.hide(true)
.help("Dumps the config to a desired location. Used for testing only.")
.action(ArgAction::Set)
.global(true)
.global(true),
)
}

Expand Down

0 comments on commit e05b856

Please sign in to comment.