From 54b8c71a27bd415371e88d81272995660cd73b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20FASANO?= Date: Mon, 16 Oct 2023 16:16:32 +0200 Subject: [PATCH] feat: add CLI --debug-level argument --- Cargo.toml | 2 +- src/main.rs | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 53d49b4..aab8b40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "evm-rs-emulator" -version = "0.1.3" +version = "0.1.4" edition = "2021" license-file = "LICENSE" description = "A blazingly fast in-memory Ethereum Virtual Machine (EVM) emulator written in Rust" diff --git a/src/main.rs b/src/main.rs index 66031cd..6365a9c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ fn main() -> Result<(), ExecutionError> { let mut data: Option> = None; let mut bytecode: String; let state: EvmState; + let mut debug_level: Option = Some(255); /* -------------------------------------------------------------------------- */ /* Fetch arguments */ @@ -183,6 +184,19 @@ fn main() -> Result<(), ExecutionError> { return Ok(()); } + /* -------------------------- Fetch the debug level ------------------------- */ + let debug_level_arg = args + .iter() + .position(|r| r == "--debug-level") + .map(|p| &args[p + 1]); + + if let Some(debug_level_arg) = debug_level_arg { + match debug_level_arg.parse::() { + Ok(level) => debug_level = Some(level), + Err(_) => unexpected_arg_value("Debug level", "a 8 bytes usigned integer"), + } + } + // Create a new interpreter let mut interpreter = core_module::runner::Runner::new(caller, origin, address, value, data, Some(state)); @@ -192,7 +206,7 @@ fn main() -> Result<(), ExecutionError> { let bytecode = hex::decode(&bytecode[2..]).expect("Invalid bytecode"); // Interpret the bytecode - let _ = interpreter.interpret(bytecode, Some(255), true); + let _ = interpreter.interpret(bytecode, debug_level, true); return Ok(()); } @@ -203,7 +217,7 @@ fn main() -> Result<(), ExecutionError> { let bytecode = hex::decode(file_content.trim()).expect("Decoding failed"); // Interpret the bytecode - let _ = interpreter.interpret(bytecode, Some(255), true); + let _ = interpreter.interpret(bytecode, debug_level, true); } Err(_) => { // Print the error @@ -269,6 +283,11 @@ fn print_help() { "value".magenta(), "HEX_VALUE".blue() ); + println!( + " --{} <{}> Override the default debug level (0 to 255)", + "debug-level".magenta(), + "LEVEL".blue() + ); println!( " --{} <{}> Set the fork url", "fork".magenta(),