Skip to content

Commit

Permalink
Add private key to struct opt
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Mar 31, 2021
1 parent 51afc28 commit 3e1fe34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions core/bin/block_revert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ ethabi = "12.0.0"
anyhow = "1.0"
web3 = "0.13.0"
structopt = "0.3.20"
envy = "0.4"
serde = { version = "1.0", features = ["derive"] }
39 changes: 15 additions & 24 deletions core/bin/block_revert/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
//! This is a CLI tool for reverting blocks on contract or in storage.
//!
//! There are 1 parameter:
//! `number` - number of blocks to revert
//!
//! There are 3 subcommands:
//! `all' - if you want to revert blocks on contract and in storage
//! `contract` - if you want to revert blocks on contract
//! `storage` - if you want to revert blocks in storage
//!
//! Pass private key of account from which you want to send ethereum transaction
//! in `REVERT_TOOL_OPERATOR_PRIVATE_KEY` env variable.
use anyhow::{bail, ensure, format_err};
use ethabi::Token;
use serde::Deserialize;
use std::str::FromStr;
use structopt::StructOpt;
use tokio::time::Duration;
use web3::{
Expand Down Expand Up @@ -206,24 +193,28 @@ struct Opt {
number: u32,
#[structopt(subcommand)]
command: Command,
}

#[derive(Debug, Deserialize)]
struct OperatorPrivateKey {
pub operator_private_key: H256,
#[structopt(
long = "key",
env = "REVERT_TOOL_OPERATOR_PRIVATE_KEY",
hide_env_values = true
)]
operator_private_key: String,
}

// TODO: don't use anyhow (ZKS-588)
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let opt = Opt::from_args();
let blocks_to_revert = opt.number;

let operator_private_key: OperatorPrivateKey = envy::prefixed("REVERT_TOOL_")
.from_env()
.expect("Cannot load operator private key");
let mut config = ZkSyncConfig::from_env();
config.eth_sender.sender.operator_private_key = operator_private_key.operator_private_key;

let key_without_prefix = opt
.operator_private_key
.strip_prefix("0x")
.unwrap_or(opt.operator_private_key.as_str());

config.eth_sender.sender.operator_private_key =
H256::from_str(key_without_prefix).expect("Cannot deserialize private key");

let mut storage = StorageProcessor::establish_connection().await?;
let client = EthereumGateway::from_config(&config);
Expand Down

0 comments on commit 3e1fe34

Please sign in to comment.