mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
* Add progress on new deposits * Add deposited command to account manager * Remove old lcli::helpers mod * Clean clap_utils * Refactor lcli deposit contract commands to use IPC * Make testnet optional for environment * Use dbg formatting for deploy address * Add command to generate bootnode enr * Ensure lcli returns with 1 on error * Ensure account manager returns 1 on error * Disallow deposits to the zero address * Update web3 in eth1 crate * Ensure correct lighthouse dir is created * Reduce deposit gas requirement * Update cargo.lock * Add progress on new deposits * Add deposited command to account manager * Remove old lcli::helpers mod * Clean clap_utils * Refactor lcli deposit contract commands to use IPC * Add command to generate bootnode enr * Ensure lcli returns with 1 on error * Ensure account manager returns 1 on error * Update web3 in eth1 crate * Update Cargo.lock * Move lcli out of main install script * Change --limit to --at-least * Change --datadir to --validator-dir * Remove duplication in docs
67 lines
2.3 KiB
Rust
67 lines
2.3 KiB
Rust
use clap::ArgMatches;
|
|
use clap_utils;
|
|
use deposit_contract::{
|
|
testnet::{ABI, BYTECODE},
|
|
CONTRACT_DEPLOY_GAS,
|
|
};
|
|
use environment::Environment;
|
|
use futures::{Future, IntoFuture};
|
|
use std::path::PathBuf;
|
|
use types::EthSpec;
|
|
use web3::{
|
|
contract::{Contract, Options},
|
|
transports::Ipc,
|
|
types::{Address, U256},
|
|
Web3,
|
|
};
|
|
|
|
pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
|
let eth1_ipc_path: PathBuf = clap_utils::parse_required(matches, "eth1-ipc")?;
|
|
let from_address: Address = clap_utils::parse_required(matches, "from-address")?;
|
|
let confirmations: usize = clap_utils::parse_required(matches, "confirmations")?;
|
|
|
|
let (_event_loop_handle, transport) =
|
|
Ipc::new(eth1_ipc_path).map_err(|e| format!("Unable to connect to eth1 IPC: {:?}", e))?;
|
|
let web3 = Web3::new(transport);
|
|
|
|
let bytecode = String::from_utf8(BYTECODE.to_vec()).map_err(|e| {
|
|
format!(
|
|
"Unable to parse deposit contract bytecode as utf-8: {:?}",
|
|
e
|
|
)
|
|
})?;
|
|
|
|
// It's unlikely that this will be the _actual_ deployment block, however it'll be close
|
|
// enough to serve our purposes.
|
|
//
|
|
// We only need the deposit block to put a lower bound on the block number we need to search
|
|
// for deposit logs.
|
|
let deploy_block = env
|
|
.runtime()
|
|
.block_on(web3.eth().block_number())
|
|
.map_err(|e| format!("Failed to get block number: {}", e))?;
|
|
|
|
let address = env.runtime().block_on(
|
|
Contract::deploy(web3.eth(), &ABI)
|
|
.map_err(|e| format!("Unable to build contract deployer: {:?}", e))?
|
|
.confirmations(confirmations)
|
|
.options(Options {
|
|
gas: Some(U256::from(CONTRACT_DEPLOY_GAS)),
|
|
..Options::default()
|
|
})
|
|
.execute(bytecode, (), from_address)
|
|
.into_future()
|
|
.map_err(|e| format!("Unable to execute deployment: {:?}", e))
|
|
.and_then(|pending| {
|
|
pending.map_err(|e| format!("Unable to await pending contract: {:?}", e))
|
|
})
|
|
.map(|tx_receipt| tx_receipt.address())
|
|
.map_err(|e| format!("Failed to execute deployment: {:?}", e)),
|
|
)?;
|
|
|
|
println!("deposit_contract_address: {:?}", address);
|
|
println!("deposit_contract_deploy_block: {}", deploy_block);
|
|
|
|
Ok(())
|
|
}
|