1use crate::{
2 handler::inspect_instructions,
3 inspect::{InspectCommitEvm, InspectEvm},
4 Inspector, InspectorEvmTr, InspectorFrame, InspectorHandler, JournalExt,
5};
6use context::{ContextSetters, ContextTr, Evm, JournalOutput, JournalTr};
7use database_interface::DatabaseCommit;
8use handler::{
9 instructions::InstructionProvider, EthFrame, EvmTr, EvmTrError, Frame, FrameResult, Handler,
10 MainnetHandler, PrecompileProvider,
11};
12use interpreter::{
13 interpreter::EthInterpreter, FrameInput, Interpreter, InterpreterAction, InterpreterResult,
14 InterpreterTypes,
15};
16
17impl<EVM, ERROR, FRAME> InspectorHandler for MainnetHandler<EVM, ERROR, FRAME>
19where
20 EVM: InspectorEvmTr<
21 Context: ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>>,
22 Inspector: Inspector<<<Self as Handler>::Evm as EvmTr>::Context, EthInterpreter>,
23 >,
24 ERROR: EvmTrError<EVM>,
25 FRAME: Frame<Evm = EVM, Error = ERROR, FrameResult = FrameResult, FrameInit = FrameInput>
26 + InspectorFrame<IT = EthInterpreter>,
27{
28 type IT = EthInterpreter;
29}
30
31impl<CTX, INSP, INST, PRECOMPILES> InspectEvm for Evm<CTX, INSP, INST, PRECOMPILES>
33where
34 CTX: ContextSetters + ContextTr<Journal: JournalTr<FinalOutput = JournalOutput> + JournalExt>,
35 INSP: Inspector<CTX, EthInterpreter>,
36 INST: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
37 PRECOMPILES: PrecompileProvider<CTX, Output = InterpreterResult>,
38{
39 type Inspector = INSP;
40
41 fn set_inspector(&mut self, inspector: Self::Inspector) {
42 self.data.inspector = inspector;
43 }
44
45 fn inspect_replay(&mut self) -> Self::Output {
46 let mut t = MainnetHandler::<_, _, EthFrame<_, _, _>> {
47 _phantom: core::marker::PhantomData,
48 };
49
50 t.inspect_run(self)
51 }
52}
53
54impl<CTX, INSP, INST, PRECOMPILES> InspectCommitEvm for Evm<CTX, INSP, INST, PRECOMPILES>
56where
57 CTX: ContextSetters
58 + ContextTr<Journal: JournalTr<FinalOutput = JournalOutput> + JournalExt, Db: DatabaseCommit>,
59 INSP: Inspector<CTX, EthInterpreter>,
60 INST: InstructionProvider<Context = CTX, InterpreterTypes = EthInterpreter>,
61 PRECOMPILES: PrecompileProvider<CTX, Output = InterpreterResult>,
62{
63 fn inspect_replay_commit(&mut self) -> Self::CommitOutput {
64 self.inspect_replay().map(|r| {
65 self.ctx().db().commit(r.state);
66 r.result
67 })
68 }
69}
70
71impl<CTX, INSP, I, P> InspectorEvmTr for Evm<CTX, INSP, I, P>
73where
74 CTX: ContextTr<Journal: JournalExt> + ContextSetters,
75 I: InstructionProvider<
76 Context = CTX,
77 InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
78 >,
79 P: PrecompileProvider<CTX>,
80 INSP: Inspector<CTX, I::InterpreterTypes>,
81{
82 type Inspector = INSP;
83
84 fn inspector(&mut self) -> &mut Self::Inspector {
85 &mut self.data.inspector
86 }
87
88 fn ctx_inspector(&mut self) -> (&mut Self::Context, &mut Self::Inspector) {
89 (&mut self.data.ctx, &mut self.data.inspector)
90 }
91
92 fn run_inspect_interpreter(
93 &mut self,
94 interpreter: &mut Interpreter<
95 <Self::Instructions as InstructionProvider>::InterpreterTypes,
96 >,
97 ) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
98 {
99 let context = &mut self.data.ctx;
100 let instructions = &mut self.instruction;
101 let inspector = &mut self.data.inspector;
102
103 inspect_instructions(
104 context,
105 interpreter,
106 inspector,
107 instructions.instruction_table(),
108 )
109 }
110}