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

@@ -9,9 +9,10 @@ mod signer;
use crate::config::Config as ValidatorClientConfig;
use crate::service::Service as ValidatorService;
use clap::{App, Arg};
use eth2_config::{get_data_dir, read_from_file, write_to_file, Eth2Config};
use eth2_config::{read_from_file, write_to_file, Eth2Config};
use protos::services_grpc::ValidatorServiceClient;
use slog::{crit, error, info, o, Drain};
use std::fs;
use std::path::PathBuf;
use types::{Keypair, MainnetEthSpec, MinimalEthSpec};
@@ -66,13 +67,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 client_config_path = data_dir.join(CLIENT_CONFIG_FILENAME);