From 7dba4841dcc50e87297bb3169f2078bfede050db Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 24 Nov 2019 19:20:09 +1100 Subject: [PATCH] Fix lcli testnet deployer --- lcli/Cargo.toml | 1 + lcli/src/main.rs | 3 +-- lcli/src/testnet.rs | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lcli/Cargo.toml b/lcli/Cargo.toml index 812b365832..48194497d4 100644 --- a/lcli/Cargo.toml +++ b/lcli/Cargo.toml @@ -23,3 +23,4 @@ futures = "0.1.25" environment = { path = "../lighthouse/environment" } web3 = "0.8.0" eth2_testnet = { path = "../eth2/utils/eth2_testnet" } +dirs = "2.0" diff --git a/lcli/src/main.rs b/lcli/src/main.rs index 9eb57d6e38..3379c82110 100644 --- a/lcli/src/main.rs +++ b/lcli/src/main.rs @@ -159,8 +159,7 @@ fn main() { .short("o") .value_name("PATH") .takes_value(true) - .default_value("~/.lighthouse/testnet") - .help("The output directory."), + .help("The output directory. Defaults to ~/.lighthouse/testnet"), ) .arg( Arg::with_name("min_genesis_time") diff --git a/lcli/src/testnet.rs b/lcli/src/testnet.rs index 4c10e9012b..bade73b4bd 100644 --- a/lcli/src/testnet.rs +++ b/lcli/src/testnet.rs @@ -6,6 +6,8 @@ use std::path::PathBuf; use types::EthSpec; use web3::{transports::Http, Web3}; +pub const DEFAULT_DATA_DIR: &str = ".lighthouse/testnet"; + pub fn new_testnet( mut env: Environment, matches: &ArgMatches, @@ -24,9 +26,16 @@ pub fn new_testnet( let output_dir = matches .value_of("output") - .ok_or_else(|| "Output directory not specified")? - .parse::() - .map_err(|e| format!("Failed to parse output directory: {}", e))?; + .ok_or_else(|| ()) + .and_then(|output| output.parse::().map_err(|_| ())) + .unwrap_or_else(|_| { + dirs::home_dir() + .map(|mut home| { + home.push(DEFAULT_DATA_DIR); + home + }) + .expect("should locate home directory") + }); let endpoint = matches .value_of("endpoint") @@ -73,6 +82,8 @@ pub fn new_testnet( deploy_block ); + info!("Writing config to {:?}", output_dir); + Eth2TestnetDir::new( output_dir, format!("0x{}", deposit_contract.address()),