Skip to content

Commit

Permalink
feat: add trace option in revme evm (bluealloy#1376)
Browse files Browse the repository at this point in the history
* feat: add trace option

* fix: use evm.modify

* fix

* refactor

* Update bins/revme/src/cmd/evmrunner.rs

* Update bins/revme/src/cmd/evmrunner.rs
  • Loading branch information
qiweiii authored May 8, 2024
1 parent c1109bd commit 5404a6a
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use revm::{
db::BenchmarkDB,
inspector_handle_register,
inspectors::TracerEip3155,
primitives::{Address, Bytecode, TransactTo},
Evm,
};
Expand Down Expand Up @@ -51,6 +53,9 @@ pub struct Cmd {
/// Print the state.
#[structopt(long)]
state: bool,
/// Print the trace.
#[structopt(long)]
trace: bool,
}

impl Cmd {
Expand Down Expand Up @@ -93,13 +98,30 @@ impl Cmd {
microbench::bench(&bench_options, "Run bytecode", || {
let _ = evm.transact().unwrap();
});

return Ok(());
}

let out = if self.trace {
let mut evm = evm
.modify()
.reset_handler_with_external_context(TracerEip3155::new(
Box::new(std::io::stdout()),
))
.append_handler_register(inspector_handle_register)
.build();

evm.transact().map_err(|_| Errors::EVMError)?
} else {
let out = evm.transact().map_err(|_| Errors::EVMError)?;
println!("Result: {:#?}", out.result);
if self.state {
println!("State: {:#?}", out.state);
}
out
};

if self.state {
println!("State: {:#?}", out.state);
}

Ok(())
}
}

0 comments on commit 5404a6a

Please sign in to comment.