Fix minor bugs whilst testing

This commit is contained in:
Paul Hauner
2019-11-25 14:52:09 +11:00
parent 73572c32d4
commit 713c0a8c10
6 changed files with 59 additions and 32 deletions

View File

@@ -3,6 +3,7 @@ use serde_derive::{Deserialize, Serialize};
use std::path::PathBuf;
pub const DEFAULT_HTTP_SERVER: &str = "http://localhost:5052/";
pub const DEFAULT_DATA_DIR: &str = ".lighthouse/validators";
/// Specifies a method for obtaining validator keypairs.
#[derive(Clone)]
@@ -37,7 +38,7 @@ impl Default for Config {
/// Build a new configuration from defaults.
fn default() -> Self {
Self {
data_dir: PathBuf::from(".lighthouse/validators"),
data_dir: PathBuf::from(DEFAULT_DATA_DIR),
key_source: <_>::default(),
http_server: DEFAULT_HTTP_SERVER.to_string(),
}
@@ -50,6 +51,21 @@ impl Config {
pub fn from_cli(cli_args: &ArgMatches) -> Result<Config, String> {
let mut config = Config::default();
// Read the `--datadir` flag.
//
// If it's not present, try and find the home directory (`~`) and push the default data
// directory onto it.
config.data_dir = cli_args
.value_of("datadir")
.map(PathBuf::from)
.or_else(|| {
dirs::home_dir().map(|mut home| {
home.push(DEFAULT_DATA_DIR);
home
})
})
.ok_or_else(|| "Unable to find a home directory for the datadir".to_string())?;
if let Some(server) = cli_args.value_of("server") {
config.http_server = server.to_string();
}

View File

@@ -34,7 +34,7 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
log: Logger,
) -> Result<Self, String> {
let validator_iter = read_dir(&base_dir)
.map_err(|e| format!("Failed to read base directory: {:?}", e))?
.map_err(|e| format!("Failed to read base directory {:?}: {:?}", base_dir, e))?
.filter_map(|validator_dir| {
let path = validator_dir.ok()?.path();