1use revm::{
2 context::{setters::ContextSetters, Evm, EvmData},
3 context_interface::ContextTr,
4 handler::{
5 handler::EvmTr,
6 instructions::{EthInstructions, InstructionProvider},
7 },
8 interpreter::{interpreter::EthInterpreter, Host, Interpreter, InterpreterAction},
9};
10
11use crate::handler::precompiles::OpPrecompileProvider;
12
13pub struct OpEvm<CTX, INSP, I = EthInstructions<EthInterpreter, CTX>, P = OpPrecompileProvider<CTX>>(
14 pub Evm<CTX, INSP, I, P>,
15);
16
17impl<CTX: Host, INSP>
18 OpEvm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, OpPrecompileProvider<CTX>>
19{
20 pub fn new(ctx: CTX, inspector: INSP) -> Self {
21 Self(Evm {
22 data: EvmData { ctx, inspector },
23 instruction: EthInstructions::new_mainnet(),
24 precompiles: OpPrecompileProvider::default(),
25 })
26 }
27}
28
29impl<CTX: ContextSetters, INSP, I> ContextSetters for OpEvm<CTX, INSP, I> {
30 type Tx = <CTX as ContextSetters>::Tx;
31 type Block = <CTX as ContextSetters>::Block;
32
33 fn set_tx(&mut self, tx: Self::Tx) {
34 self.0.data.ctx.set_tx(tx);
35 }
36
37 fn set_block(&mut self, block: Self::Block) {
38 self.0.data.ctx.set_block(block);
39 }
40}
41
42impl<CTX, INSP, I, P> EvmTr for OpEvm<CTX, INSP, I, P>
43where
44 CTX: ContextTr,
45 I: InstructionProvider<Context = CTX, Output = InterpreterAction>,
46{
47 type Context = CTX;
48 type Instructions = I;
49 type Precompiles = P;
50
51 fn run_interpreter(
52 &mut self,
53 interpreter: &mut Interpreter<
54 <Self::Instructions as InstructionProvider>::InterpreterTypes,
55 >,
56 ) -> <Self::Instructions as InstructionProvider>::Output {
57 let context = &mut self.0.data.ctx;
58 let instructions = &mut self.0.instruction;
59 interpreter.run_plain(instructions.instruction_table(), context)
60 }
61
62 fn ctx(&mut self) -> &mut Self::Context {
63 &mut self.0.data.ctx
64 }
65
66 fn ctx_ref(&self) -> &Self::Context {
67 &self.0.data.ctx
68 }
69
70 fn ctx_instructions(&mut self) -> (&mut Self::Context, &mut Self::Instructions) {
71 (&mut self.0.data.ctx, &mut self.0.instruction)
72 }
73
74 fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) {
75 (&mut self.0.data.ctx, &mut self.0.precompiles)
76 }
77}