op_revm/api/
builder.rs

1//! Optimism builder trait [`OpBuilder`] used to build [`OpEvm`].
2use crate::{evm::OpEvm, precompiles::OpPrecompiles, 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/// Type alias for default OpEvm
13pub type DefaultOpEvm<CTX, INSP = ()> =
14    OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, OpPrecompiles>;
15
16/// Trait that allows for optimism OpEvm to be built.
17pub trait OpBuilder: Sized {
18    /// Type of the context.
19    type Context;
20
21    /// Build the op.
22    fn build_op(self) -> DefaultOpEvm<Self::Context>;
23
24    /// Build the op with an inspector.
25    fn build_op_with_inspector<INSP>(self, inspector: INSP) -> DefaultOpEvm<Self::Context, INSP>;
26}
27
28impl<BLOCK, TX, CFG, DB, JOURNAL> OpBuilder for Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>
29where
30    BLOCK: Block,
31    TX: OpTxTr,
32    CFG: Cfg<Spec = OpSpecId>,
33    DB: Database,
34    JOURNAL: JournalTr<Database = DB, State = EvmState>,
35{
36    type Context = Self;
37
38    fn build_op(self) -> DefaultOpEvm<Self::Context> {
39        OpEvm::new(self, ())
40    }
41
42    fn build_op_with_inspector<INSP>(self, inspector: INSP) -> DefaultOpEvm<Self::Context, INSP> {
43        OpEvm::new(self, inspector)
44    }
45}