Skip to content

Commit

Permalink
Move clap arg to a seperate file and clean up main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
makemake-kbo committed Aug 3, 2023
1 parent 390e968 commit 67b94c2
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 105 deletions.
111 changes: 111 additions & 0 deletions src/cli_arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use clap::{Command, Arg};


// This is not the recommended way to set clap args but it works and its too late to change it now
pub fn create_match() -> clap::Command {
let matches = Command::new("sothis")
.version("0.5.0")
.author("makemake <[email protected]>")
.about("Tool for replaying historical transactions. Designed to be used with anvil or hardhat.")
.arg(Arg::new("source_rpc")
.long("source_rpc")
.short('s')
.num_args(1..)
.required(true)
.help("HTTP JSON-RPC of the node we're querying data from"))
.arg(Arg::new("replay_rpc")
.long("replay_rpc")
.short('r')
.num_args(1..)
.help("HTTP JSON-RPC of the node we're replaying data to"))
.arg(Arg::new("mode")
.long("mode")
.short('m')
.num_args(1..)
.default_value("historic")
.help("Choose between live, historic, track, fast_track, or call_track"))
.arg(Arg::new("terminal_block")
.long("terminal_block")
.short('b')
.num_args(1..)
.required_if_eq("mode", "historic")
.help("Block we're replaying until"))
.arg(Arg::new("exit_on_tx_fail")
.long("exit_on_tx_fail")
.num_args(0..)
.help("Exit the program if a transaction fails"))
.arg(Arg::new("block_listen_time")
.long("block_listen_time")
.short('t')
.num_args(1..)
.default_value("500")
.help("Time in ms to check for new blocks."))
.arg(Arg::new("entropy_threshold")
.long("entropy_threshold")
.num_args(1..)
.default_value("0.07")
.help("Set the percentage of failed transactions to trigger a warning"))
.arg(Arg::new("replay_delay")
.long("replay_delay")
.short('d')
.num_args(1..)
.default_value("0")
.help("Default delay for block replay in ms"))
.arg(Arg::new("send_as_unsigned")
.long("send_as_unsigned")
.num_args(0..)
.help("Exit the program if a transaction fails"))
.arg(Arg::new("no_setup")
.long("no_setup")
.num_args(0..)
.help("Start replaying immediately."))
.arg(Arg::new("decimal")
.long("decimal")
.num_args(0..)
.help("Start replaying immediately."))
.arg(Arg::new("contract_address")
.long("contract_address")
.short('c')
.num_args(1..)
.required_if_eq("mode", "track")
.required_if_eq("mode", "fast_track")
.help("Address of the contract we're tracking storage."))
.arg(Arg::new("storage_slot")
.long("storage_slot")
.short('l')
.num_args(1..)
.required_if_eq("mode", "track")
.required_if_eq("mode", "fast_track")
.help("Storage slot for the variable we're tracking"))
.arg(Arg::new("calldata")
.long("calldata")
.short('a')
.num_args(1..)
.required_if_eq("mode", "call_track")
.help("Storage slot for the variable we're tracking"))
.arg(Arg::new("origin_block")
.long("origin_block")
.short('o')
.num_args(1..)
.required_if_eq("mode", "fast_track")
.help("First block sothis will look at."))
.arg(Arg::new("query_interval")
.long("query_interval")
.short('q')
.num_args(1..)
.help("First block sothis will look at."))
.arg(Arg::new("path")
.long("path")
.short('p')
.num_args(1..)
.default_value(".")
.help("Path to file we're writing to"))
.arg(Arg::new("filename")
.long("filename")
.short('f')
.num_args(1..)
.default_value("")
.help("Name of the file."));

return matches;
}
107 changes: 2 additions & 105 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod rpc;
mod replay;
mod tracker;
mod cli_arg;

use clap::{Command, Arg};
use ethers::types::U256;

use crate::replay::replay::replay_historic_blocks;
Expand All @@ -19,110 +19,7 @@ use rpc::rpc::RpcConnection;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let matches = Command::new("sothis")
.version("0.5.0")
.author("makemake <[email protected]>")
.about("Tool for replaying historical transactions. Designed to be used with anvil or hardhat.")
.arg(Arg::new("source_rpc")
.long("source_rpc")
.short('s')
.num_args(1..)
.required(true)
.help("HTTP JSON-RPC of the node we're querying data from"))
.arg(Arg::new("replay_rpc")
.long("replay_rpc")
.short('r')
.num_args(1..)
.help("HTTP JSON-RPC of the node we're replaying data to"))
.arg(Arg::new("mode")
.long("mode")
.short('m')
.num_args(1..)
.default_value("historic")
.help("Choose between live, historic, track, fast_track, or call_track"))
.arg(Arg::new("terminal_block")
.long("terminal_block")
.short('b')
.num_args(1..)
.required_if_eq("mode", "historic")
.help("Block we're replaying until"))
.arg(Arg::new("exit_on_tx_fail")
.long("exit_on_tx_fail")
.num_args(0..)
.help("Exit the program if a transaction fails"))
.arg(Arg::new("block_listen_time")
.long("block_listen_time")
.short('t')
.num_args(1..)
.default_value("500")
.help("Time in ms to check for new blocks."))
.arg(Arg::new("entropy_threshold")
.long("entropy_threshold")
.num_args(1..)
.default_value("0.07")
.help("Set the percentage of failed transactions to trigger a warning"))
.arg(Arg::new("replay_delay")
.long("replay_delay")
.short('d')
.num_args(1..)
.default_value("0")
.help("Default delay for block replay in ms"))
.arg(Arg::new("send_as_unsigned")
.long("send_as_unsigned")
.num_args(0..)
.help("Exit the program if a transaction fails"))
.arg(Arg::new("no_setup")
.long("no_setup")
.num_args(0..)
.help("Start replaying immediately."))
.arg(Arg::new("decimal")
.long("decimal")
.num_args(0..)
.help("Start replaying immediately."))
.arg(Arg::new("contract_address")
.long("contract_address")
.short('c')
.num_args(1..)
.required_if_eq("mode", "track")
.required_if_eq("mode", "fast_track")
.help("Address of the contract we're tracking storage."))
.arg(Arg::new("storage_slot")
.long("storage_slot")
.short('l')
.num_args(1..)
.required_if_eq("mode", "track")
.required_if_eq("mode", "fast_track")
.help("Storage slot for the variable we're tracking"))
.arg(Arg::new("calldata")
.long("calldata")
.short('a')
.num_args(1..)
.required_if_eq("mode", "call_track")
.help("Storage slot for the variable we're tracking"))
.arg(Arg::new("origin_block")
.long("origin_block")
.short('o')
.num_args(1..)
.required_if_eq("mode", "fast_track")
.help("First block sothis will look at."))
.arg(Arg::new("query_interval")
.long("query_interval")
.short('q')
.num_args(1..)
.help("First block sothis will look at."))
.arg(Arg::new("path")
.long("path")
.short('p')
.num_args(1..)
.default_value(".")
.help("Path to file we're writing to"))
.arg(Arg::new("filename")
.long("filename")
.short('f')
.num_args(1..)
.default_value("")
.help("Name of the file."))
.get_matches();
let matches = cli_arg::create_match().get_matches();

let source_rpc = matches.get_one::<String>("source_rpc").expect("Invalid source_rpc").to_string();
let source_rpc = RpcConnection::new(source_rpc);
Expand Down

0 comments on commit 67b94c2

Please sign in to comment.