diff --git a/src/stack/mod.rs b/src/stack.rs similarity index 98% rename from src/stack/mod.rs rename to src/stack.rs index 9bb868a2..e6af1de6 100644 --- a/src/stack/mod.rs +++ b/src/stack.rs @@ -7,10 +7,6 @@ use revm::{ }; use std::fmt::Debug; -/// A wrapped [Inspector] that can be reused in the stack -mod maybe_owned; -pub use maybe_owned::MaybeOwnedInspector; - /// One can hook on inspector execution in 3 ways: /// - Block: Hook on block execution /// - BlockWithIndex: Hook on block execution transaction index diff --git a/src/stack/maybe_owned.rs b/src/stack/maybe_owned.rs deleted file mode 100644 index 5640dcd7..00000000 --- a/src/stack/maybe_owned.rs +++ /dev/null @@ -1,150 +0,0 @@ -use alloy_primitives::{Log, U256}; -use revm::{ - interpreter::{CallInputs, CallOutcome, CreateInputs, CreateOutcome, Interpreter}, - primitives::{db::Database, Address}, - EvmContext, Inspector, -}; -use std::{ - cell::{Ref, RefCell}, - rc::Rc, -}; - -/// An [Inspector] that is either owned by an individual [Inspector] or is shared as part of a -/// series of inspectors in a [InspectorStack](crate::stack::InspectorStack). -/// -/// Caution: if the [Inspector] is _stacked_ then it _must_ be called first. -#[derive(Debug)] -pub enum MaybeOwnedInspector { - /// Inspector is owned. - Owned(Rc>), - /// Inspector is shared and part of a stack - Stacked(Rc>), -} - -impl MaybeOwnedInspector { - /// Create a new _owned_ instance - pub fn new_owned(inspector: I) -> Self { - Self::Owned(Rc::new(RefCell::new(inspector))) - } - - /// Creates a [MaybeOwnedInspector::Stacked] clone of this type. - pub fn clone_stacked(&self) -> Self { - match self { - Self::Owned(gas) | Self::Stacked(gas) => Self::Stacked(Rc::clone(gas)), - } - } - - /// Returns a reference to the inspector. - pub fn as_ref(&self) -> Ref<'_, I> { - match self { - Self::Owned(insp) => insp.borrow(), - Self::Stacked(insp) => insp.borrow(), - } - } -} - -impl MaybeOwnedInspector { - /// Create a new _owned_ instance - pub fn owned() -> Self { - Self::new_owned(Default::default()) - } -} - -impl Default for MaybeOwnedInspector { - fn default() -> Self { - Self::owned() - } -} - -impl Clone for MaybeOwnedInspector { - fn clone(&self) -> Self { - self.clone_stacked() - } -} - -impl Inspector for MaybeOwnedInspector -where - DB: Database, - I: Inspector, -{ - fn initialize_interp(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { - match self { - Self::Owned(insp) => insp.borrow_mut().initialize_interp(interp, context), - Self::Stacked(_) => {} - } - } - - fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { - match self { - Self::Owned(insp) => insp.borrow_mut().step(interp, context), - Self::Stacked(_) => {} - } - } - - fn step_end(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { - match self { - Self::Owned(insp) => insp.borrow_mut().step_end(interp, context), - Self::Stacked(_) => {} - } - } - - fn log(&mut self, context: &mut EvmContext, log: &Log) { - match self { - Self::Owned(insp) => insp.borrow_mut().log(context, log), - Self::Stacked(_) => {} - } - } - - fn call( - &mut self, - context: &mut EvmContext, - inputs: &mut CallInputs, - ) -> Option { - match self { - Self::Owned(insp) => insp.borrow_mut().call(context, inputs), - Self::Stacked(_) => None, - } - } - - fn call_end( - &mut self, - context: &mut EvmContext, - inputs: &CallInputs, - outcome: CallOutcome, - ) -> CallOutcome { - match self { - Self::Owned(insp) => insp.borrow_mut().call_end(context, inputs, outcome), - Self::Stacked(_) => outcome, - } - } - - fn create( - &mut self, - context: &mut EvmContext, - inputs: &mut CreateInputs, - ) -> Option { - match self { - Self::Owned(insp) => insp.borrow_mut().create(context, inputs), - Self::Stacked(_) => None, - } - } - - fn create_end( - &mut self, - context: &mut EvmContext, - inputs: &CreateInputs, - outcome: CreateOutcome, - ) -> CreateOutcome { - match self { - Self::Owned(insp) => insp.borrow_mut().create_end(context, inputs, outcome), - Self::Stacked(_) => outcome, - } - } - - fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) { - match self { - Self::Owned(insp) => insp.borrow_mut().selfdestruct(contract, target, value), - Self::Stacked(_) => {} - } - } -}