diff --git a/Cargo.lock b/Cargo.lock index 878ee69468..4a0679b29b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,7 @@ dependencies = [ name = "account_utils" version = "0.1.0" dependencies = [ + "directory", "eth2_keystore", "eth2_wallet", "rand 0.7.3", diff --git a/account_manager/src/validator/mod.rs b/account_manager/src/validator/mod.rs index 99d8da01b7..042a35ccdc 100644 --- a/account_manager/src/validator/mod.rs +++ b/account_manager/src/validator/mod.rs @@ -26,7 +26,6 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { Defaults to ~/.lighthouse/{testnet}/validators", ) .takes_value(true) - .global(true) .conflicts_with("datadir"), ) .subcommand(create::cli_app()) diff --git a/account_manager/src/wallet/mod.rs b/account_manager/src/wallet/mod.rs index d745cbcd2c..4ab957ecb9 100644 --- a/account_manager/src/wallet/mod.rs +++ b/account_manager/src/wallet/mod.rs @@ -18,7 +18,6 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .value_name("WALLETS_DIRECTORY") .help("A path containing Eth2 EIP-2386 wallets. Defaults to ~/.lighthouse/{testnet}/wallets") .takes_value(true) - .global(true) .conflicts_with("datadir"), ) .subcommand(create::cli_app()) diff --git a/common/account_utils/Cargo.toml b/common/account_utils/Cargo.toml index 7b8b2822e9..1b7580ded4 100644 --- a/common/account_utils/Cargo.toml +++ b/common/account_utils/Cargo.toml @@ -19,3 +19,4 @@ types = { path = "../../consensus/types" } validator_dir = { path = "../validator_dir" } regex = "1.3.9" rpassword = "5.0.0" +directory = { path = "../directory" } diff --git a/common/account_utils/src/validator_definitions.rs b/common/account_utils/src/validator_definitions.rs index b69678628c..11cfa1c142 100644 --- a/common/account_utils/src/validator_definitions.rs +++ b/common/account_utils/src/validator_definitions.rs @@ -4,6 +4,7 @@ //! attempt) to load into the `crate::intialized_validators::InitializedValidators` struct. use crate::{create_with_600_perms, default_keystore_password_path, ZeroizeString}; +use directory::ensure_dir_exists; use eth2_keystore::Keystore; use regex::Regex; use serde_derive::{Deserialize, Serialize}; @@ -35,6 +36,8 @@ pub enum Error { InvalidKeystorePubkey, /// The keystore was unable to be opened. UnableToOpenKeystore(eth2_keystore::Error), + /// The validator directory could not be created. + UnableToCreateValidatorDir(PathBuf), } /// Defines how the validator client should attempt to sign messages for this validator. @@ -108,6 +111,9 @@ pub struct ValidatorDefinitions(Vec); impl ValidatorDefinitions { /// Open an existing file or create a new, empty one if it does not exist. pub fn open_or_create>(validators_dir: P) -> Result { + ensure_dir_exists(validators_dir.as_ref()).map_err(|_| { + Error::UnableToCreateValidatorDir(PathBuf::from(validators_dir.as_ref())) + })?; let config_path = validators_dir.as_ref().join(CONFIG_FILENAME); if !config_path.exists() { let this = Self::default();