mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Validator dir creation (#1746)
## Issue Addressed Resolves #1744 ## Proposed Changes - Add `directory::ensure_dir_exists` to the `ValidatorDefinition::open_or_create` method - As @pawanjay176 suggested, making the `--validator-dir` non-global so users are forced to include the flag after the `validator` subcommand. Current behavior seems to be ignoring the flag if it comes after something like `validator import` ## Additional Info N/A
This commit is contained in:
@@ -19,3 +19,4 @@ types = { path = "../../consensus/types" }
|
||||
validator_dir = { path = "../validator_dir" }
|
||||
regex = "1.3.9"
|
||||
rpassword = "5.0.0"
|
||||
directory = { path = "../directory" }
|
||||
|
||||
@@ -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<ValidatorDefinition>);
|
||||
impl ValidatorDefinitions {
|
||||
/// Open an existing file or create a new, empty one if it does not exist.
|
||||
pub fn open_or_create<P: AsRef<Path>>(validators_dir: P) -> Result<Self, Error> {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user