mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Use tempdir for account manager
This commit is contained in:
@@ -3,7 +3,7 @@ mod cli;
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use deposit_contract::DEPOSIT_GAS;
|
use deposit_contract::DEPOSIT_GAS;
|
||||||
use environment::{Environment, RuntimeContext};
|
use environment::{Environment, RuntimeContext};
|
||||||
use eth2_testnet::Eth2TestnetDir;
|
use eth2_testnet::{Eth2TestnetDir, TempDir};
|
||||||
use futures::{future, stream::unfold, Future, IntoFuture, Stream};
|
use futures::{future, stream::unfold, Future, IntoFuture, Stream};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use slog::{crit, error, info, Logger};
|
use slog::{crit, error, info, Logger};
|
||||||
@@ -174,7 +174,9 @@ fn run_new_validator_subcommand<T: EthSpec>(
|
|||||||
"eth1_node_http_endpoint" => eth1_endpoint
|
"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
|
let testnet_dir = testnet_dir_str
|
||||||
.parse::<PathBuf>()
|
.parse::<PathBuf>()
|
||||||
.map_err(|e| format!("Unable to parse testnet-dir: {}", e))?;
|
.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)
|
"testnet_dir" => format!("{:?}", &testnet_dir)
|
||||||
);
|
);
|
||||||
|
|
||||||
let eth2_testnet_dir: Eth2TestnetDir<T> = Eth2TestnetDir::load(testnet_dir.clone())
|
Eth2TestnetDir::load(testnet_dir.clone())
|
||||||
.map_err(|e| format!("Failed to load testnet dir at {:?}: {}", testnet_dir, e))?;
|
.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(),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
matches
|
let temp_dir = TempDir::new("lighthouse-account-manager")
|
||||||
.value_of("deposit-contract")
|
.map_err(|e| format!("Unable to create temporary directory: {}", e))?;
|
||||||
.ok_or_else(|| "No --deposit-contract or --testnet-dir".to_string())?
|
|
||||||
.parse::<Address>()
|
info!(log, "Using default deposit contract address");
|
||||||
.map_err(|e| format!("Unable to parse deposit-contract: {}", e))?
|
|
||||||
|
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(
|
if let Err(()) = env.runtime().block_on(deposit_validators(
|
||||||
context.clone(),
|
context.clone(),
|
||||||
eth1_endpoint.to_string(),
|
eth1_endpoint.to_string(),
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ edition = "2018"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
tempdir = "0.3"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_yaml = "0.8"
|
serde_yaml = "0.8"
|
||||||
types = { path = "../../types"}
|
types = { path = "../../types"}
|
||||||
eth2-libp2p = { path = "../../../beacon_node/eth2-libp2p"}
|
eth2-libp2p = { path = "../../../beacon_node/eth2-libp2p"}
|
||||||
eth2_ssz = { path = "../ssz"}
|
eth2_ssz = { path = "../ssz"}
|
||||||
|
tempdir = "0.3"
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ use std::io::{Read, Write};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use types::{Address, BeaconState, EthSpec, YamlConfig};
|
use types::{Address, BeaconState, EthSpec, YamlConfig};
|
||||||
|
|
||||||
|
pub use tempdir::TempDir;
|
||||||
|
|
||||||
pub const ADDRESS_FILE: &str = "deposit_contract.txt";
|
pub const ADDRESS_FILE: &str = "deposit_contract.txt";
|
||||||
pub const DEPLOY_BLOCK_FILE: &str = "deploy_block.txt";
|
pub const DEPLOY_BLOCK_FILE: &str = "deploy_block.txt";
|
||||||
pub const BOOT_ENR_FILE: &str = "boot_enr.yaml";
|
pub const BOOT_ENR_FILE: &str = "boot_enr.yaml";
|
||||||
|
|||||||
Reference in New Issue
Block a user