Skip to content

Commit

Permalink
chore: Add helpers with_inspector with_precompile (#2063)
Browse files Browse the repository at this point in the history
* chore: Add helpers with_inspector with_precompile

* chore: fn inspector()

* chore: consumes evm into inspector

* inspect previous with tx
  • Loading branch information
rakita authored Feb 10, 2025
1 parent ee8e319 commit 26d16a1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/context/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ impl<CTX> Evm<CTX, (), (), ()> {
}
}

impl<CTX: ContextSetters, INSP, I, P> Evm<CTX, INSP, I, P> {
/// Consumed self and returns new Evm type with given Inspector.
pub fn with_inspector<OINSP>(self, inspector: OINSP) -> Evm<CTX, OINSP, I, P> {
Evm {
data: EvmData {
ctx: self.data.ctx,
inspector,
},
enabled_inspection: self.enabled_inspection,
instruction: self.instruction,
precompiles: self.precompiles,
}
}

/// Consumes self and returns new Evm type with given Precompiles.
pub fn with_precompiles<OP>(self, precompiles: OP) -> Evm<CTX, INSP, I, OP> {
Evm {
data: self.data,
enabled_inspection: self.enabled_inspection,
instruction: self.instruction,
precompiles,
}
}

/// Consumes self and returns inner Inspector.
pub fn into_inspector(self) -> INSP {
self.data.inspector
}
}

impl<CTX: ContextSetters, INSP, I, P> ContextSetters for Evm<CTX, INSP, I, P> {
type Tx = <CTX as ContextSetters>::Tx;
type Block = <CTX as ContextSetters>::Block;
Expand Down
7 changes: 7 additions & 0 deletions crates/handler/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ where
&self.data.ctx
}

#[inline]
fn inspector(&mut self) -> &mut Self::Inspector {
&mut self.data.inspector
}

#[inline]
fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) {
(&mut self.data.ctx, &mut self.data.inspector)
Expand Down Expand Up @@ -194,6 +199,8 @@ pub trait EvmTrait {

fn ctx(&mut self) -> &mut Self::Context;

fn inspector(&mut self) -> &mut Self::Inspector;

fn ctx_ref(&self) -> &Self::Context;

fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector);
Expand Down
4 changes: 4 additions & 0 deletions crates/optimism/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ where
&self.data.ctx
}

fn inspector(&mut self) -> &mut Self::Inspector {
&mut self.data.inspector
}

fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) {
(&mut self.data.ctx, &mut self.data.inspector)
}
Expand Down
5 changes: 5 additions & 0 deletions crates/revm/src/exec_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub trait InspectEvm: ExecuteEvm {
self.inspect_previous()
}

fn inspect_previous_with_tx(&mut self, tx: <Self as ContextSetters>::Tx) -> Self::Output {
self.set_tx(tx);
self.inspect_previous()
}

fn inspect(
&mut self,
tx: <Self as ContextSetters>::Tx,
Expand Down

0 comments on commit 26d16a1

Please sign in to comment.