Skip to main content

example_my_evm/
frame.rs

1//! Custom frame that wraps [`EthFrame`](revm::handler::EthFrame).
2//!
3//! Useful when a custom EVM variant needs to carry additional per-call-frame
4//! state or intercept frame creation, execution, or return.
5use revm::{
6    handler::{evm::FrameTr, EthFrame, FrameResult},
7    inspector::InspectorFrame,
8    interpreter::{interpreter::EthInterpreter, interpreter_action::FrameInit},
9};
10
11/// A custom frame that wraps [`EthFrame`] and delegates execution to it.
12#[derive(Debug)]
13pub struct MyFrame {
14    /// The wrapped Ethereum frame that performs the actual execution.
15    pub eth_frame: EthFrame<EthInterpreter>,
16}
17
18impl MyFrame {
19    /// Creates a new invalid [`MyFrame`].
20    pub fn invalid() -> Self {
21        Self {
22            eth_frame: EthFrame::invalid(),
23        }
24    }
25
26    /// Returns true if the frame has finished execution.
27    pub const fn is_finished(&self) -> bool {
28        self.eth_frame.is_finished()
29    }
30}
31
32impl FrameTr for MyFrame {
33    type FrameResult = FrameResult;
34    type FrameInit = FrameInit;
35}
36
37/// Exposes the inner [`EthFrame`] so inspectors can trace through the custom frame.
38impl InspectorFrame for MyFrame {
39    type IT = EthInterpreter;
40
41    fn eth_frame(&mut self) -> Option<&mut EthFrame<EthInterpreter>> {
42        Some(&mut self.eth_frame)
43    }
44}