Skip to content

Commit

Permalink
feat: add CLI --debug-level argument (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashiru authored Oct 16, 2023
1 parent 609c904 commit cdea2b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
23 changes: 21 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn main() -> Result<(), ExecutionError> {
let mut data: Option<Vec<u8>> = None;
let mut bytecode: String;
let state: EvmState;
let mut debug_level: Option<u8> = Some(255);

/* -------------------------------------------------------------------------- */
/* Fetch arguments */
Expand Down Expand Up @@ -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::<u8>() {
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));
Expand All @@ -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(());
}

Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit cdea2b7

Please sign in to comment.