diff --git a/account_manager/src/lib.rs b/account_manager/src/lib.rs index 694cf80ef2..7070cc87ab 100644 --- a/account_manager/src/lib.rs +++ b/account_manager/src/lib.rs @@ -3,7 +3,7 @@ mod cli; use clap::ArgMatches; use deposit_contract::DEPOSIT_GAS; use environment::{Environment, RuntimeContext}; -use eth2_testnet::Eth2TestnetDir; +use eth2_testnet::{Eth2TestnetDir, TempDir}; use futures::{future, stream::unfold, Future, IntoFuture, Stream}; use rayon::prelude::*; use slog::{crit, error, info, Logger}; @@ -174,7 +174,9 @@ fn run_new_validator_subcommand( "eth1_node_http_endpoint" => eth1_endpoint ); - let deposit_contract = if let Some(testnet_dir_str) = matches.value_of("testnet-dir") { + let eth2_testnet_dir: Eth2TestnetDir = if let Some(testnet_dir_str) = + matches.value_of("testnet-dir") + { let testnet_dir = testnet_dir_str .parse::() .map_err(|e| format!("Unable to parse testnet-dir: {}", e))?; @@ -192,23 +194,31 @@ fn run_new_validator_subcommand( "testnet_dir" => format!("{:?}", &testnet_dir) ); - let eth2_testnet_dir: Eth2TestnetDir = Eth2TestnetDir::load(testnet_dir.clone()) - .map_err(|e| format!("Failed to load testnet dir at {:?}: {}", testnet_dir, e))?; - - // Convert from `types::Address` to `web3::types::Address`. - Address::from_slice( - eth2_testnet_dir - .deposit_contract_address()? - .as_fixed_bytes(), - ) + Eth2TestnetDir::load(testnet_dir.clone()) + .map_err(|e| format!("Failed to load testnet dir at {:?}: {}", testnet_dir, e))? } else { - matches - .value_of("deposit-contract") - .ok_or_else(|| "No --deposit-contract or --testnet-dir".to_string())? - .parse::
() - .map_err(|e| format!("Unable to parse deposit-contract: {}", e))? + let temp_dir = TempDir::new("lighthouse-account-manager") + .map_err(|e| format!("Unable to create temporary directory: {}", e))?; + + info!(log, "Using default deposit contract address"); + + let testnet_dir = PathBuf::from(temp_dir.path()); + + Eth2TestnetDir::load(testnet_dir.clone()).map_err(|e| { + format!( + "Failed to load default testnet dir at {:?}: {}", + testnet_dir, e + ) + })? }; + // Convert from `types::Address` to `web3::types::Address`. + let deposit_contract = Address::from_slice( + eth2_testnet_dir + .deposit_contract_address()? + .as_fixed_bytes(), + ); + if let Err(()) = env.runtime().block_on(deposit_validators( context.clone(), eth1_endpoint.to_string(), diff --git a/eth2/utils/eth2_testnet/Cargo.toml b/eth2/utils/eth2_testnet/Cargo.toml index cc04cb739d..213bbee5b6 100644 --- a/eth2/utils/eth2_testnet/Cargo.toml +++ b/eth2/utils/eth2_testnet/Cargo.toml @@ -6,12 +6,10 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dev-dependencies] -tempdir = "0.3" - [dependencies] serde = "1.0" serde_yaml = "0.8" types = { path = "../../types"} eth2-libp2p = { path = "../../../beacon_node/eth2-libp2p"} eth2_ssz = { path = "../ssz"} +tempdir = "0.3" diff --git a/eth2/utils/eth2_testnet/src/lib.rs b/eth2/utils/eth2_testnet/src/lib.rs index a92442606b..414857c448 100644 --- a/eth2/utils/eth2_testnet/src/lib.rs +++ b/eth2/utils/eth2_testnet/src/lib.rs @@ -14,6 +14,8 @@ use std::io::{Read, Write}; use std::path::PathBuf; use types::{Address, BeaconState, EthSpec, YamlConfig}; +pub use tempdir::TempDir; + pub const ADDRESS_FILE: &str = "deposit_contract.txt"; pub const DEPLOY_BLOCK_FILE: &str = "deploy_block.txt"; pub const BOOT_ENR_FILE: &str = "boot_enr.yaml";