example_my_evm/
handler.rs

1use revm::{
2    context::{
3        result::{EVMError, HaltReason, InvalidTransaction},
4        JournalOutput,
5    },
6    context_interface::{ContextTr, JournalTr},
7    handler::{
8        instructions::InstructionProvider, EthFrame, EvmTr, FrameResult, Handler,
9        PrecompileProvider,
10    },
11    inspector::{Inspector, InspectorEvmTr, InspectorHandler},
12    interpreter::{interpreter::EthInterpreter, InterpreterResult},
13    Database,
14};
15
16pub struct MyHandler<EVM> {
17    pub _phantom: core::marker::PhantomData<EVM>,
18}
19
20impl<EVM> Default for MyHandler<EVM> {
21    fn default() -> Self {
22        Self {
23            _phantom: core::marker::PhantomData,
24        }
25    }
26}
27
28impl<EVM> Handler for MyHandler<EVM>
29where
30    EVM: EvmTr<
31        Context: ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>>,
32        Precompiles: PrecompileProvider<EVM::Context, Output = InterpreterResult>,
33        Instructions: InstructionProvider<
34            Context = EVM::Context,
35            InterpreterTypes = EthInterpreter,
36        >,
37    >,
38{
39    type Evm = EVM;
40    type Error = EVMError<<<EVM::Context as ContextTr>::Db as Database>::Error, InvalidTransaction>;
41    type Frame = EthFrame<
42        EVM,
43        EVMError<<<EVM::Context as ContextTr>::Db as Database>::Error, InvalidTransaction>,
44        <EVM::Instructions as InstructionProvider>::InterpreterTypes,
45    >;
46    type HaltReason = HaltReason;
47
48    fn reward_beneficiary(
49        &self,
50        _evm: &mut Self::Evm,
51        _exec_result: &mut FrameResult,
52    ) -> Result<(), Self::Error> {
53        // Skip beneficiary reward
54        Ok(())
55    }
56}
57
58impl<EVM> InspectorHandler for MyHandler<EVM>
59where
60    EVM: InspectorEvmTr<
61        Inspector: Inspector<<<Self as Handler>::Evm as EvmTr>::Context, EthInterpreter>,
62        Context: ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>>,
63        Precompiles: PrecompileProvider<EVM::Context, Output = InterpreterResult>,
64        Instructions: InstructionProvider<
65            Context = EVM::Context,
66            InterpreterTypes = EthInterpreter,
67        >,
68    >,
69{
70    type IT = EthInterpreter;
71}