Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CLI --debug-level argument #14

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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