Use tempdir for account manager

This commit is contained in:
Paul Hauner
2019-12-02 10:31:52 +11:00
parent 6583191905
commit 300fe0bf47
3 changed files with 29 additions and 19 deletions

View File

@@ -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<T: EthSpec>(
"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<T> = if let Some(testnet_dir_str) =
matches.value_of("testnet-dir")
{
let testnet_dir = testnet_dir_str
.parse::<PathBuf>()
.map_err(|e| format!("Unable to parse testnet-dir: {}", e))?;
@@ -192,23 +194,31 @@ fn run_new_validator_subcommand<T: EthSpec>(
"testnet_dir" => format!("{:?}", &testnet_dir)
);
let eth2_testnet_dir: Eth2TestnetDir<T> = 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::<Address>()
.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(),

View File

@@ -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"

View File

@@ -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";