diff --git a/Cargo.toml b/Cargo.toml index fc2a701..4331cde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.4.0", features = ["string"] } ethers = "2.0.10" eyre = "0.6.8" serde_json = "1.0.107" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..3fca38c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,58 @@ +use clap::{arg, value_parser, Command}; + +fn cli() -> Command { + Command::new("state-reconstruct") + .about("zkSync state reconstruction tool") + .subcommand_required(true) + .arg_required_else_help(false) + .subcommand( + Command::new("reconstruct") + .about("Reconstruct L2 state") + .subcommand_required(true) + .subcommand( + Command::new("l1") + .about("Read state from Ethereum L1") + .arg( + arg!(--"start-block" ) + .help("Ethereum block number to start state import from") + .default_value(state_reconstruct::GENESIS_BLOCK.to_string()) + .value_parser(value_parser!(u64)), + ) + .arg( + arg!(--"block-step" ) + .help("Number of blocks to filter & process in one step") + .default_value(state_reconstruct::BLOCK_STEP.to_string()) + .value_parser(value_parser!(u64)), + ), + ) + .subcommand( + Command::new("file") + .about("Read state from file") + .arg(arg!( "File to import state from")) + .arg_required_else_help(true), + ), + ) +} + +fn main() { + let matches = cli().get_matches(); + + match matches.subcommand() { + Some(("reconstruct", sub_matches)) => { + match sub_matches.subcommand() { + Some(("l1", args)) => { + let start_block = args.get_one::("start-block").expect("required"); + let block_step = args.get_one::("block-step").expect("required"); + println!("reconstruct from L1, starting from block number {}, processing {} blocks at a time", start_block, block_step); + // TODO(tuommaki): Implement block fetch logic. + } + Some(("file", args)) => { + let input_file = args.get_one::("FILE").expect("required"); + println!("reconstruct from file (path: \"{}\")", input_file); + } + _ => unreachable!(), + } + } + _ => unreachable!(), + } +}