example_my_evm/
handler.rs

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