Add persistent network identification

This commit is contained in:
Age Manning
2019-07-01 16:38:42 +10:00
parent 7dc5e2f959
commit af28d5e20c
12 changed files with 220 additions and 71 deletions

View File

@@ -13,3 +13,4 @@ slog-async = "^2.3.0"
validator_client = { path = "../validator_client" }
types = { path = "../eth2/types" }
eth2_config = { path = "../eth2/utils/eth2_config" }
dirs = "2.0.1"

View File

@@ -1,7 +1,7 @@
use bls::Keypair;
use clap::{App, Arg, SubCommand};
use eth2_config::get_data_dir;
use slog::{crit, debug, info, o, Drain};
use std::fs;
use std::path::PathBuf;
use types::test_utils::generate_deterministic_keypair;
use validator_client::Config as ValidatorClientConfig;
@@ -61,13 +61,22 @@ fn main() {
)
.get_matches();
let data_dir = match get_data_dir(&matches, PathBuf::from(DEFAULT_DATA_DIR)) {
Ok(dir) => dir,
let mut default_dir = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
default_dir.push(DEFAULT_DATA_DIR);
let data_dir = &matches
.value_of("datadir")
.and_then(|v| Some(PathBuf::from(v)))
.unwrap_or_else(|| PathBuf::from(default_dir));
// create the directory if needed
match fs::create_dir_all(&data_dir) {
Ok(_) => {}
Err(e) => {
crit!(log, "Failed to initialize data dir"; "error" => format!("{:?}", e));
crit!(log, "Failed to initialize data dir"; "error" => format!("{}", e));
return;
}
};
}
let mut client_config = ValidatorClientConfig::default();