Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions account_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod validator;
pub mod wallet;

use clap::App;
use clap::ArgMatches;
use clap_utils::matches::Matches as ArgMatches;
use environment::Environment;
use types::EthSpec;

Expand All @@ -23,8 +23,8 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
/// Run the account manager, returning an error if the operation did not succeed.
pub fn run<T: EthSpec>(matches: &ArgMatches<'_>, env: Environment<T>) -> Result<(), String> {
match matches.subcommand() {
(wallet::CMD, Some(matches)) => wallet::cli_run(matches)?,
(validator::CMD, Some(matches)) => validator::cli_run(matches, env)?,
(wallet::CMD, Some(matches)) => wallet::cli_run(&matches)?,
(validator::CMD, Some(matches)) => validator::cli_run(&matches, env)?,
(unknown, _) => {
return Err(format!(
"{} is not a valid {} command. See --help.",
Expand Down
3 changes: 2 additions & 1 deletion account_manager/src/validator/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::{SECRETS_DIR_FLAG, WALLETS_DIR_FLAG};
use account_utils::{
random_password, read_password_from_user, strip_off_newlines, validator_definitions, PlainText,
};
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use directory::{
ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_SECRET_DIR, DEFAULT_WALLET_DIR,
};
Expand Down
3 changes: 2 additions & 1 deletion account_manager/src/validator/exit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::wallet::create::STDIN_INPUTS_FLAG;
use bls::{Keypair, PublicKey};
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use environment::Environment;
use eth2::{
types::{GenesisData, StateId, ValidatorData, ValidatorId, ValidatorStatus},
Expand Down
9 changes: 5 additions & 4 deletions account_manager/src/validator/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use account_utils::{
},
ZeroizeString,
};
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME};
use std::fs;
use std::path::PathBuf;
Expand Down Expand Up @@ -83,12 +84,12 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}

pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), String> {
let keystore: Option<PathBuf> = clap_utils::parse_optional(matches, KEYSTORE_FLAG)?;
let keystores_dir: Option<PathBuf> = clap_utils::parse_optional(matches, DIR_FLAG)?;
let keystore: Option<PathBuf> = clap_utils::parse_optional(&matches, KEYSTORE_FLAG)?;
let keystores_dir: Option<PathBuf> = clap_utils::parse_optional(&matches, DIR_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);
let reuse_password = matches.is_present(REUSE_PASSWORD_FLAG);
let keystore_password_path: Option<PathBuf> =
clap_utils::parse_optional(matches, PASSWORD_FLAG)?;
clap_utils::parse_optional(&matches, PASSWORD_FLAG)?;

let mut defs = ValidatorDefinitions::open_or_create(&validator_dir)
.map_err(|e| format!("Unable to open {}: {:?}", CONFIG_FILENAME, e))?;
Expand Down
15 changes: 8 additions & 7 deletions account_manager/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub mod recover;
pub mod slashing_protection;

use crate::VALIDATOR_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use directory::{parse_path_or_default_with_flag, DEFAULT_VALIDATOR_DIR};
use environment::Environment;
use std::path::PathBuf;
Expand Down Expand Up @@ -48,15 +49,15 @@ pub fn cli_run<T: EthSpec>(matches: &ArgMatches, env: Environment<T>) -> Result<
eprintln!("validator-dir path: {:?}", validator_base_dir);

match matches.subcommand() {
(create::CMD, Some(matches)) => create::cli_run::<T>(matches, env, validator_base_dir),
(modify::CMD, Some(matches)) => modify::cli_run(matches, validator_base_dir),
(import::CMD, Some(matches)) => import::cli_run(matches, validator_base_dir),
(create::CMD, Some(matches)) => create::cli_run::<T>(&matches, env, validator_base_dir),
(modify::CMD, Some(matches)) => modify::cli_run(&matches, validator_base_dir),
(import::CMD, Some(matches)) => import::cli_run(&matches, validator_base_dir),
(list::CMD, Some(_)) => list::cli_run(validator_base_dir),
(recover::CMD, Some(matches)) => recover::cli_run(matches, validator_base_dir),
(recover::CMD, Some(matches)) => recover::cli_run(&matches, validator_base_dir),
(slashing_protection::CMD, Some(matches)) => {
slashing_protection::cli_run(matches, env, validator_base_dir)
slashing_protection::cli_run(&matches, env, validator_base_dir)
}
(exit::CMD, Some(matches)) => exit::cli_run(matches, env),
(exit::CMD, Some(matches)) => exit::cli_run(&matches, env),
(unknown, _) => Err(format!(
"{} does not have a {} command. See --help",
CMD, unknown
Expand Down
5 changes: 3 additions & 2 deletions account_manager/src/validator/modify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use account_utils::validator_definitions::ValidatorDefinitions;
use bls::PublicKey;
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use std::{collections::HashSet, path::PathBuf};

pub const CMD: &str = "modify";
Expand Down Expand Up @@ -76,7 +77,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
.map(|def| def.voting_public_key.clone())
.collect::<HashSet<_>>()
} else {
let public_key: PublicKey = clap_utils::parse_required(sub_matches, PUBKEY_FLAG)?;
let public_key: PublicKey = clap_utils::parse_required(&sub_matches, PUBKEY_FLAG)?;
std::iter::once(public_key).collect::<HashSet<PublicKey>>()
};

Expand Down
13 changes: 7 additions & 6 deletions account_manager/src/validator/recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::wallet::create::STDIN_INPUTS_FLAG;
use crate::SECRETS_DIR_FLAG;
use account_utils::eth2_keystore::{keypair_from_secret, Keystore, KeystoreBuilder};
use account_utils::random_password;
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use directory::ensure_dir_exists;
use directory::{parse_path_or_default_with_flag, DEFAULT_SECRET_DIR};
use eth2_wallet::bip39::Seed;
Expand Down Expand Up @@ -80,14 +81,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {

pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), String> {
let secrets_dir = if matches.value_of("datadir").is_some() {
let path: PathBuf = clap_utils::parse_required(matches, "datadir")?;
let path: PathBuf = clap_utils::parse_required(&matches, "datadir")?;
path.join(DEFAULT_SECRET_DIR)
} else {
parse_path_or_default_with_flag(matches, SECRETS_DIR_FLAG, DEFAULT_SECRET_DIR)?
parse_path_or_default_with_flag(&matches, SECRETS_DIR_FLAG, DEFAULT_SECRET_DIR)?
};
let first_index: u32 = clap_utils::parse_required(matches, FIRST_INDEX_FLAG)?;
let count: u32 = clap_utils::parse_required(matches, COUNT_FLAG)?;
let mnemonic_path: Option<PathBuf> = clap_utils::parse_optional(matches, MNEMONIC_FLAG)?;
let first_index: u32 = clap_utils::parse_required(&matches, FIRST_INDEX_FLAG)?;
let count: u32 = clap_utils::parse_required(&matches, COUNT_FLAG)?;
let mnemonic_path: Option<PathBuf> = clap_utils::parse_optional(&matches, MNEMONIC_FLAG)?;
let stdin_inputs = cfg!(windows) || matches.is_present(STDIN_INPUTS_FLAG);

eprintln!("secrets-dir path: {:?}", secrets_dir);
Expand Down
13 changes: 7 additions & 6 deletions account_manager/src/validator/slashing_protection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use environment::Environment;
use slashing_protection::{
interchange::Interchange, InterchangeError, InterchangeImportOutcome, SlashingDatabase,
Expand Down Expand Up @@ -98,8 +99,8 @@ pub fn cli_run<T: EthSpec>(

match matches.subcommand() {
(IMPORT_CMD, Some(matches)) => {
let import_filename: PathBuf = clap_utils::parse_required(matches, IMPORT_FILE_ARG)?;
let minify: Option<bool> = clap_utils::parse_optional(matches, MINIFY_FLAG)?;
let import_filename: PathBuf = clap_utils::parse_required(&matches, IMPORT_FILE_ARG)?;
let minify: Option<bool> = clap_utils::parse_optional(&matches, MINIFY_FLAG)?;
let import_file = File::open(&import_filename).map_err(|e| {
format!(
"Unable to open import file at {}: {:?}",
Expand Down Expand Up @@ -212,11 +213,11 @@ pub fn cli_run<T: EthSpec>(
Ok(())
}
(EXPORT_CMD, Some(matches)) => {
let export_filename: PathBuf = clap_utils::parse_required(matches, EXPORT_FILE_ARG)?;
let minify: bool = clap_utils::parse_required(matches, MINIFY_FLAG)?;
let export_filename: PathBuf = clap_utils::parse_required(&matches, EXPORT_FILE_ARG)?;
let minify: bool = clap_utils::parse_required(&matches, MINIFY_FLAG)?;

let selected_pubkeys = if let Some(pubkeys) =
clap_utils::parse_optional::<String>(matches, PUBKEYS_FLAG)?
clap_utils::parse_optional::<String>(&matches, PUBKEYS_FLAG)?
{
let pubkeys = pubkeys
.split(',')
Expand Down
8 changes: 5 additions & 3 deletions account_manager/src/wallet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::WALLETS_DIR_FLAG;
use account_utils::{
is_password_sufficiently_complex, random_password, read_password_from_user, strip_off_newlines,
};
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use eth2_wallet::{
bip39::{Language, Mnemonic, MnemonicType},
PlainText,
Expand Down Expand Up @@ -103,12 +104,13 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}

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)?;
let mnemonic_output_path: Option<PathBuf> =
clap_utils::parse_optional(&matches, MNEMONIC_FLAG)?;

// Create a new random mnemonic.
//
// The `tiny-bip39` crate uses `thread_rng()` for this entropy.
let mnemonic_length = clap_utils::parse_required(matches, MNEMONIC_LENGTH_FLAG)?;
let mnemonic_length = clap_utils::parse_required(&matches, MNEMONIC_LENGTH_FLAG)?;
let mnemonic = Mnemonic::new(
MnemonicType::for_word_count(mnemonic_length).expect("Mnemonic length already validated"),
Language::English,
Expand Down
7 changes: 4 additions & 3 deletions account_manager/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub mod list;
pub mod recover;

use crate::WALLETS_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use directory::{ensure_dir_exists, parse_path_or_default_with_flag, DEFAULT_WALLET_DIR};
use std::path::PathBuf;

Expand Down Expand Up @@ -37,9 +38,9 @@ pub fn cli_run(matches: &ArgMatches) -> Result<(), String> {
eprintln!("wallet-dir path: {:?}", wallet_base_dir);

match matches.subcommand() {
(create::CMD, Some(matches)) => create::cli_run(matches, wallet_base_dir),
(create::CMD, Some(matches)) => create::cli_run(&matches, wallet_base_dir),
(list::CMD, Some(_)) => list::cli_run(wallet_base_dir),
(recover::CMD, Some(matches)) => recover::cli_run(matches, wallet_base_dir),
(recover::CMD, Some(matches)) => recover::cli_run(&matches, wallet_base_dir),
(unknown, _) => Err(format!(
"{} does not have a {} command. See --help",
CMD, unknown
Expand Down
3 changes: 2 additions & 1 deletion account_manager/src/wallet/recover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::common::read_mnemonic_from_cli;
use crate::wallet::create::{create_wallet_from_mnemonic, STDIN_INPUTS_FLAG};
use crate::wallet::create::{HD_TYPE, NAME_FLAG, PASSWORD_FLAG, TYPE_FLAG};
use clap::{App, Arg, ArgMatches};
use clap::{App, Arg};
use clap_utils::matches::Matches as ArgMatches;
use std::path::PathBuf;

pub const CMD: &str = "recover";
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::ArgMatches;
use clap_utils::matches::Matches as ArgMatches;
use clap_utils::{flags::DISABLE_MALLOC_TUNING_FLAG, BAD_TESTNET_DIR_MESSAGE};
use client::{ClientConfig, ClientGenesis};
use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR};
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use beacon_chain::{
builder::Witness, eth1_chain::CachingEth1Backend, slot_clock::SystemTimeSlotClock,
TimeoutRwLock,
};
use clap::ArgMatches;
use clap_utils::matches::Matches as ArgMatches;
pub use cli::cli_app;
pub use client::{Client, ClientBuilder, ClientConfig, ClientGenesis};
pub use config::{get_config, get_data_dir, get_eth2_network_config, set_network_config};
Expand Down
1 change: 1 addition & 0 deletions boot_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
beacon_node = { path = "../beacon_node" }
clap = "2.33.3"
clap_utils = { path = "../common/clap_utils" }
lighthouse_network = { path = "../beacon_node/lighthouse_network" }
types = { path = "../consensus/types" }
eth2_ssz = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion boot_node/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use beacon_node::{get_data_dir, get_eth2_network_config, set_network_config};
use clap::ArgMatches;
use clap_utils::matches::Matches as ArgMatches;
use lighthouse_network::discv5::{enr::CombinedKey, Discv5Config, Enr};
use lighthouse_network::{
discovery::{create_enr_builder_from_config, load_enr_from_disk, use_or_load_enr},
Expand Down
2 changes: 1 addition & 1 deletion boot_node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Creates a simple DISCV5 server which can be used to bootstrap an Eth2 network.
use clap::ArgMatches;
use clap_utils::matches::Matches as ArgMatches;
use slog::{o, Drain, Level, Logger};

use std::convert::TryFrom;
Expand Down
2 changes: 2 additions & 0 deletions common/clap_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ hex = "0.4.2"
dirs = "3.0.1"
eth2_network_config = { path = "../eth2_network_config" }
eth2_ssz = "0.4.0"
serde_yaml = "0.8.13"
toml = "0.5.6"
20 changes: 9 additions & 11 deletions common/clap_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! A helper library for parsing values from `clap::ArgMatches`.

use clap::ArgMatches;
use crate::matches::Matches;
use eth2_network_config::Eth2NetworkConfig;
use ssz::Decode;
use std::path::PathBuf;
use std::str::FromStr;

pub mod flags;
pub mod matches;

pub const BAD_TESTNET_DIR_MESSAGE: &str = "The hard-coded testnet directory was invalid. \
This happens when Lighthouse is migrating between spec versions \
Expand All @@ -16,7 +17,7 @@ pub const BAD_TESTNET_DIR_MESSAGE: &str = "The hard-coded testnet directory was
/// Attempts to load the testnet dir at the path if `name` is in `matches`, returning an error if
/// the path cannot be found or the testnet dir is invalid.
pub fn parse_testnet_dir(
matches: &ArgMatches,
matches: &Matches,
name: &'static str,
) -> Result<Option<Eth2NetworkConfig>, String> {
let path = parse_required::<PathBuf>(matches, name)?;
Expand All @@ -28,7 +29,7 @@ pub fn parse_testnet_dir(
/// Attempts to load a hardcoded network config if `name` is in `matches`, returning an error if
/// the name is not a valid network name.
pub fn parse_hardcoded_network(
matches: &ArgMatches,
matches: &Matches,
name: &str,
) -> Result<Option<Eth2NetworkConfig>, String> {
let network_name = parse_required::<String>(matches, name)?;
Expand All @@ -38,7 +39,7 @@ pub fn parse_hardcoded_network(
/// If `name` is in `matches`, parses the value as a path. Otherwise, attempts to find the user's
/// home directory and appends `default` to it.
pub fn parse_path_with_default_in_home_dir(
matches: &ArgMatches,
matches: &Matches,
name: &'static str,
default: PathBuf,
) -> Result<PathBuf, String> {
Expand All @@ -57,7 +58,7 @@ pub fn parse_path_with_default_in_home_dir(

/// Returns the value of `name` or an error if it is not in `matches` or does not parse
/// successfully using `std::string::FromStr`.
pub fn parse_required<T>(matches: &ArgMatches, name: &str) -> Result<T, String>
pub fn parse_required<T>(matches: &Matches, name: &str) -> Result<T, String>
where
T: FromStr,
<T as FromStr>::Err: std::fmt::Display,
Expand All @@ -67,7 +68,7 @@ where

/// Returns the value of `name` (if present) or an error if it does not parse successfully using
/// `std::string::FromStr`.
pub fn parse_optional<T>(matches: &ArgMatches, name: &str) -> Result<Option<T>, String>
pub fn parse_optional<T>(matches: &Matches, name: &str) -> Result<Option<T>, String>
where
T: FromStr,
<T as FromStr>::Err: std::fmt::Display,
Expand All @@ -85,10 +86,7 @@ where
/// successfully using `ssz::Decode`.
///
/// Expects the value of `name` to be 0x-prefixed ASCII-hex.
pub fn parse_ssz_required<T: Decode>(
matches: &ArgMatches,
name: &'static str,
) -> Result<T, String> {
pub fn parse_ssz_required<T: Decode>(matches: &Matches, name: &'static str) -> Result<T, String> {
parse_ssz_optional(matches, name)?.ok_or_else(|| format!("{} not specified", name))
}

Expand All @@ -97,7 +95,7 @@ pub fn parse_ssz_required<T: Decode>(
///
/// Expects the value of `name` (if any) to be 0x-prefixed ASCII-hex.
pub fn parse_ssz_optional<T: Decode>(
matches: &ArgMatches,
matches: &Matches,
name: &'static str,
) -> Result<Option<T>, String> {
matches
Expand Down
Loading