mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 22:04:44 +00:00
Make account manager submit deposits
This commit is contained in:
@@ -8,10 +8,7 @@ use web3::{transports::Http, Web3};
|
||||
|
||||
pub const DEFAULT_DATA_DIR: &str = ".lighthouse/testnet";
|
||||
|
||||
pub fn new_testnet<T: EthSpec>(
|
||||
mut env: Environment<T>,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
||||
let min_genesis_time = matches
|
||||
.value_of("min_genesis_time")
|
||||
.ok_or_else(|| "min_genesis_time not specified")?
|
||||
@@ -65,6 +62,8 @@ pub fn new_testnet<T: EthSpec>(
|
||||
|
||||
info!("Present eth1 block number is {}", deploy_block);
|
||||
|
||||
info!("Deploying the bytecode at https://github.com/sigp/unsafe-eth2-deposit-contract",);
|
||||
|
||||
info!(
|
||||
"Submitting deployment transaction, waiting for {} confirmations",
|
||||
confirmations
|
||||
@@ -1,78 +0,0 @@
|
||||
use clap::ArgMatches;
|
||||
use environment::Environment;
|
||||
use eth1_test_rig::{DelayThenDeposit, DepositContract};
|
||||
use futures::Future;
|
||||
use std::time::Duration;
|
||||
use types::{test_utils::generate_deterministic_keypair, EthSpec, Hash256};
|
||||
use web3::{transports::Http, Web3};
|
||||
|
||||
pub fn run_deposit_contract<T: EthSpec>(
|
||||
mut env: Environment<T>,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let count = matches
|
||||
.value_of("count")
|
||||
.ok_or_else(|| "Deposit count not specified")?
|
||||
.parse::<usize>()
|
||||
.map_err(|e| format!("Failed to parse deposit count: {}", e))?;
|
||||
|
||||
let delay = matches
|
||||
.value_of("delay")
|
||||
.ok_or_else(|| "Deposit count not specified")?
|
||||
.parse::<u64>()
|
||||
.map(Duration::from_millis)
|
||||
.map_err(|e| format!("Failed to parse deposit count: {}", e))?;
|
||||
|
||||
let confirmations = matches
|
||||
.value_of("confirmations")
|
||||
.ok_or_else(|| "Confirmations not specified")?
|
||||
.parse::<usize>()
|
||||
.map_err(|e| format!("Failed to parse confirmations: {}", e))?;
|
||||
|
||||
let endpoint = matches
|
||||
.value_of("endpoint")
|
||||
.ok_or_else(|| "Endpoint not specified")?;
|
||||
|
||||
let (_event_loop, transport) = Http::new(&endpoint).map_err(|e| {
|
||||
format!(
|
||||
"Failed to start HTTP transport connected to ganache: {:?}",
|
||||
e
|
||||
)
|
||||
})?;
|
||||
let web3 = Web3::new(transport);
|
||||
|
||||
let deposit_contract = env
|
||||
.runtime()
|
||||
.block_on(DepositContract::deploy(web3, confirmations))
|
||||
.map_err(|e| format!("Failed to deploy contract: {}", e))?;
|
||||
|
||||
info!(
|
||||
"Deposit contract deployed. Address: {}",
|
||||
deposit_contract.address()
|
||||
);
|
||||
|
||||
env.runtime()
|
||||
.block_on(do_deposits::<T>(deposit_contract, count, delay))
|
||||
.map_err(|e| format!("Failed to submit deposits: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn do_deposits<T: EthSpec>(
|
||||
deposit_contract: DepositContract,
|
||||
count: usize,
|
||||
delay: Duration,
|
||||
) -> impl Future<Item = (), Error = String> {
|
||||
let deposits = (0..count)
|
||||
.map(|i| DelayThenDeposit {
|
||||
deposit: deposit_contract.deposit_helper::<T>(
|
||||
generate_deterministic_keypair(i),
|
||||
Hash256::from_low_u64_le(i as u64),
|
||||
32_000_000_000,
|
||||
),
|
||||
delay,
|
||||
})
|
||||
.collect();
|
||||
|
||||
deposit_contract.deposit_multiple(deposits)
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
mod deposit_contract;
|
||||
mod deploy_deposit_contract;
|
||||
mod parse_hex;
|
||||
mod pycli;
|
||||
mod testnet;
|
||||
mod transition_blocks;
|
||||
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use deposit_contract::run_deposit_contract;
|
||||
use environment::EnvironmentBuilder;
|
||||
use log::Level;
|
||||
use parse_hex::run_parse_hex;
|
||||
@@ -113,46 +111,10 @@ fn main() {
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("deposit-contract")
|
||||
SubCommand::with_name("deploy-deposit-contract")
|
||||
.about(
|
||||
"Uses an eth1 test rpc (e.g., ganache-cli) to simulate the deposit contract.",
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("count")
|
||||
.short("c")
|
||||
.value_name("INTEGER")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.help("The number of deposits to be submitted."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("delay")
|
||||
.short("d")
|
||||
.value_name("MILLIS")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.help("The delay (in milliseconds) between each deposit"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("endpoint")
|
||||
.short("e")
|
||||
.value_name("HTTP_SERVER")
|
||||
.takes_value(true)
|
||||
.default_value("http://localhost:8545")
|
||||
.help("The URL to the eth1 JSON-RPC http API."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("confirmations")
|
||||
.value_name("INTEGER")
|
||||
.takes_value(true)
|
||||
.default_value("3")
|
||||
.help("The number of block confirmations before declaring the contract deployed."),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("testnet")
|
||||
.about(
|
||||
"Deploy an eth1 deposit contract and create files with testnet details.",
|
||||
"Deploy an eth1 deposit contract and create a ~/.lighthouse/testnet directory \
|
||||
(unless another directory is specified).",
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("output")
|
||||
@@ -254,10 +216,10 @@ fn main() {
|
||||
}
|
||||
("pycli", Some(matches)) => run_pycli::<LocalEthSpec>(matches)
|
||||
.unwrap_or_else(|e| error!("Failed to run pycli: {}", e)),
|
||||
("deposit-contract", Some(matches)) => run_deposit_contract::<LocalEthSpec>(env, matches)
|
||||
.unwrap_or_else(|e| error!("Failed to run deposit contract sim: {}", e)),
|
||||
("testnet", Some(matches)) => testnet::new_testnet::<LocalEthSpec>(env, matches)
|
||||
.unwrap_or_else(|e| error!("Failed to run testnet commmand: {}", e)),
|
||||
("deploy-deposit-contract", Some(matches)) => {
|
||||
deploy_deposit_contract::run::<LocalEthSpec>(env, matches)
|
||||
.unwrap_or_else(|e| error!("Failed to run deploy-deposit-contract commmand: {}", e))
|
||||
}
|
||||
(other, _) => error!("Unknown subcommand {}. See --help.", other),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user