Skip to content

Commit

Permalink
Restructure account_manager directory paths
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Aug 17, 2020
1 parent 53892af commit 54b4ae6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
16 changes: 15 additions & 1 deletion account_manager/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ pub fn base_wallet_dir(matches: &ArgMatches, arg: &'static str) -> Result<PathBu
clap_utils::parse_path_with_default_in_home_dir(
matches,
arg,
PathBuf::new().join(".lighthouse").join("wallets"),
PathBuf::new()
.join(".lighthouse")
.join(clap_utils::get_testnet_dir(matches))
.join("wallets"),
)
}

pub fn base_validator_dir(matches: &ArgMatches, arg: &'static str) -> Result<PathBuf, String> {
clap_utils::parse_path_with_default_in_home_dir(
matches,
arg,
PathBuf::new()
.join(".lighthouse")
.join(clap_utils::get_testnet_dir(matches))
.join("validators"),
)
}
11 changes: 5 additions & 6 deletions account_manager/src/validator/create.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{common::ensure_dir_exists, SECRETS_DIR_FLAG, VALIDATOR_DIR_FLAG};
use crate::{
common::{base_validator_dir, ensure_dir_exists},
SECRETS_DIR_FLAG, VALIDATOR_DIR_FLAG,
};
use account_utils::{random_password, strip_off_newlines, validator_definitions};
use clap::{App, Arg, ArgMatches};
use environment::Environment;
Expand Down Expand Up @@ -111,11 +114,7 @@ pub fn cli_run<T: EthSpec>(
let name: String = clap_utils::parse_required(matches, WALLET_NAME_FLAG)?;
let wallet_password_path: PathBuf =
clap_utils::parse_required(matches, WALLET_PASSPHRASE_FLAG)?;
let validator_dir = clap_utils::parse_path_with_default_in_home_dir(
matches,
VALIDATOR_DIR_FLAG,
PathBuf::new().join(".lighthouse").join("validators"),
)?;
let validator_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;
let secrets_dir = clap_utils::parse_path_with_default_in_home_dir(
matches,
SECRETS_DIR_FLAG,
Expand Down
8 changes: 2 additions & 6 deletions account_manager/src/validator/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::VALIDATOR_DIR_FLAG;
use crate::{common::base_validator_dir, VALIDATOR_DIR_FLAG};
use clap::{App, Arg, ArgMatches};
use deposit_contract::DEPOSIT_GAS;
use environment::Environment;
Expand Down Expand Up @@ -212,11 +212,7 @@ pub fn cli_run<T: EthSpec>(
) -> Result<(), String> {
let log = env.core_context().log().clone();

let data_dir = clap_utils::parse_path_with_default_in_home_dir(
matches,
VALIDATOR_DIR_FLAG,
PathBuf::new().join(".lighthouse").join("validators"),
)?;
let data_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;
let validator: String = clap_utils::parse_required(matches, VALIDATOR_FLAG)?;
let eth1_ipc_path: Option<PathBuf> = clap_utils::parse_optional(matches, ETH1_IPC_FLAG)?;
let eth1_http_url: Option<String> = clap_utils::parse_optional(matches, ETH1_HTTP_FLAG)?;
Expand Down
11 changes: 5 additions & 6 deletions account_manager/src/validator/import.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{common::ensure_dir_exists, VALIDATOR_DIR_FLAG};
use crate::{
common::{base_validator_dir, ensure_dir_exists},
VALIDATOR_DIR_FLAG,
};
use account_utils::{
eth2_keystore::Keystore,
read_password_from_user,
Expand Down Expand Up @@ -73,11 +76,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
pub fn cli_run(matches: &ArgMatches) -> 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 validator_dir = clap_utils::parse_path_with_default_in_home_dir(
matches,
VALIDATOR_DIR_FLAG,
PathBuf::new().join(".lighthouse").join("validators"),
)?;
let validator_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;
let stdin_password = matches.is_present(STDIN_PASSWORD_FLAG);

ensure_dir_exists(&validator_dir)?;
Expand Down
8 changes: 2 additions & 6 deletions account_manager/src/validator/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::base_validator_dir;
use crate::VALIDATOR_DIR_FLAG;
use clap::{App, Arg, ArgMatches};
use std::path::PathBuf;
use validator_dir::Manager as ValidatorManager;

pub const CMD: &str = "list";
Expand All @@ -21,11 +21,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
}

pub fn cli_run(matches: &ArgMatches<'_>) -> Result<(), String> {
let data_dir = clap_utils::parse_path_with_default_in_home_dir(
matches,
VALIDATOR_DIR_FLAG,
PathBuf::new().join(".lighthouse").join("validators"),
)?;
let data_dir = base_validator_dir(matches, VALIDATOR_DIR_FLAG)?;

let mgr = ValidatorManager::open(&data_dir)
.map_err(|e| format!("Unable to read --{}: {:?}", VALIDATOR_DIR_FLAG, e))?;
Expand Down
2 changes: 1 addition & 1 deletion account_manager/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
Arg::with_name(BASE_DIR_FLAG)
.long(BASE_DIR_FLAG)
.value_name("BASE_DIRECTORY")
.help("A path containing Eth2 EIP-2386 wallets. Defaults to ~/.lighthouse/wallets")
.help("A path containing Eth2 EIP-2386 wallets. Defaults to ~/.lighthouse/{testnet_name}/wallets")
.takes_value(true),
)
.subcommand(create::cli_app())
Expand Down

0 comments on commit 54b4ae6

Please sign in to comment.