op_revm/api/
builder.rs

1//! Optimism builder trait [`OpBuilder`] used to build [`OpEvm`].
2use crate::{evm::OpEvm, transaction::OpTxTr, L1BlockInfo, OpSpecId};
3use revm::{
4    context::Cfg,
5    context_interface::{Block, JournalTr},
6    handler::instructions::EthInstructions,
7    interpreter::interpreter::EthInterpreter,
8    state::EvmState,
9    Context, Database,
10};
11
12/// Trait that allows for optimism OpEvm to be built.
13pub trait OpBuilder: Sized {
14    /// Type of the context.
15    type Context;
16
17    /// Build the op.
18    fn build_op(self) -> OpEvm<Self::Context, (), EthInstructions<EthInterpreter, Self::Context>>;
19
20    /// Build the op with an inspector.
21    fn build_op_with_inspector<INSP>(
22        self,
23        inspector: INSP,
24    ) -> OpEvm<Self::Context, INSP, EthInstructions<EthInterpreter, Self::Context>>;
25}
26
27impl<BLOCK, TX, CFG, DB, JOURNAL> OpBuilder for Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>
28where
29    BLOCK: Block,
30    TX: OpTxTr,
31    CFG: Cfg<Spec = OpSpecId>,
32    DB: Database,
33    JOURNAL: JournalTr<Database = DB, State = EvmState>,
34{
35    type Context = Self;
36
37    fn build_op(self) -> OpEvm<Self::Context, (), EthInstructions<EthInterpreter, Self::Context>> {
38        OpEvm::new(self, ())
39    }
40
41    fn build_op_with_inspector<INSP>(
42        self,
43        inspector: INSP,
44    ) -> OpEvm<Self::Context, INSP, EthInstructions<EthInterpreter, Self::Context>> {
45        OpEvm::new(self, inspector)
46    }
47}