1use revm::{
2 context::{ContextSetters, ContextTr, Evm, EvmData},
3 handler::{
4 instructions::{EthInstructions, InstructionProvider},
5 EthPrecompiles, EvmTr,
6 },
7 inspector::{inspect_instructions, InspectorEvmTr, JournalExt},
8 interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterTypes},
9 Inspector,
10};
11
12pub struct MyEvm<CTX, INSP>(
14 pub Evm<CTX, INSP, EthInstructions<EthInterpreter, CTX>, EthPrecompiles>,
15);
16
17impl<CTX: ContextTr, INSP> MyEvm<CTX, INSP> {
18 pub fn new(ctx: CTX, inspector: INSP) -> Self {
19 Self(Evm {
20 data: EvmData { ctx, inspector },
21 instruction: EthInstructions::new_mainnet(),
22 precompiles: EthPrecompiles::default(),
23 })
24 }
25}
26
27impl<CTX: ContextTr, INSP> EvmTr for MyEvm<CTX, INSP>
28where
29 CTX: ContextTr,
30{
31 type Context = CTX;
32 type Instructions = EthInstructions<EthInterpreter, CTX>;
33 type Precompiles = EthPrecompiles;
34
35 fn ctx(&mut self) -> &mut Self::Context {
36 &mut self.0.data.ctx
37 }
38
39 fn ctx_ref(&self) -> &Self::Context {
40 self.0.ctx_ref()
41 }
42
43 fn ctx_instructions(&mut self) -> (&mut Self::Context, &mut Self::Instructions) {
44 self.0.ctx_instructions()
45 }
46
47 fn run_interpreter(
48 &mut self,
49 interpreter: &mut Interpreter<
50 <Self::Instructions as InstructionProvider>::InterpreterTypes,
51 >,
52 ) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
53 {
54 self.0.run_interpreter(interpreter)
55 }
56
57 fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) {
58 self.0.ctx_precompiles()
59 }
60}
61
62impl<CTX: ContextTr, INSP> InspectorEvmTr for MyEvm<CTX, INSP>
63where
64 CTX: ContextSetters<Journal: JournalExt>,
65 INSP: Inspector<CTX, EthInterpreter>,
66{
67 type Inspector = INSP;
68
69 fn inspector(&mut self) -> &mut Self::Inspector {
70 self.0.inspector()
71 }
72
73 fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) {
74 self.0.ctx_inspector()
75 }
76
77 fn run_inspect_interpreter(
78 &mut self,
79 interpreter: &mut Interpreter<
80 <Self::Instructions as InstructionProvider>::InterpreterTypes,
81 >,
82 ) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
83 {
84 let context = &mut self.0.data.ctx;
85 let instructions = &mut self.0.instruction;
86 let inspector = &mut self.0.data.inspector;
87
88 inspect_instructions(
89 context,
90 interpreter,
91 inspector,
92 instructions.instruction_table(),
93 )
94 }
95}