revm_interpreter/
interpreter_action.rs

1mod call_inputs;
2mod call_outcome;
3mod create_inputs;
4mod create_outcome;
5mod eof_create_inputs;
6
7pub use call_inputs::{CallInputs, CallScheme, CallValue};
8pub use call_outcome::CallOutcome;
9pub use create_inputs::CreateInputs;
10pub use create_outcome::CreateOutcome;
11pub use eof_create_inputs::{EOFCreateInputs, EOFCreateKind};
12
13use crate::InterpreterResult;
14use std::boxed::Box;
15
16#[derive(Clone, Debug, PartialEq, Eq)]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18pub enum FrameInput {
19    /// `CALL`, `CALLCODE`, `DELEGATECALL`, `STATICCALL`
20    /// or EOF `EXTCALL`, `EXTDELEGATECALL`, `EXTSTATICCALL` instruction called.
21    Call(Box<CallInputs>),
22    /// `CREATE` or `CREATE2` instruction called.
23    Create(Box<CreateInputs>),
24    /// EOF `CREATE` instruction called.
25    EOFCreate(Box<EOFCreateInputs>),
26}
27
28impl AsMut<Self> for FrameInput {
29    fn as_mut(&mut self) -> &mut Self {
30        self
31    }
32}
33
34#[derive(Clone, Debug, Default, PartialEq, Eq)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36pub enum InterpreterAction {
37    /// New frame
38    NewFrame(FrameInput),
39    /// Interpreter finished execution.
40    Return { result: InterpreterResult },
41    /// No action
42    #[default]
43    None,
44}
45
46impl InterpreterAction {
47    /// Returns `true` if action is call.
48    pub fn is_call(&self) -> bool {
49        matches!(self, InterpreterAction::NewFrame(FrameInput::Call(..)))
50    }
51
52    /// Returns `true` if action is create.
53    pub fn is_create(&self) -> bool {
54        matches!(self, InterpreterAction::NewFrame(FrameInput::Create(..)))
55    }
56
57    /// Returns `true` if action is return.
58    pub fn is_return(&self) -> bool {
59        matches!(self, InterpreterAction::Return { .. })
60    }
61
62    /// Returns `true` if action is none.
63    pub fn is_none(&self) -> bool {
64        matches!(self, InterpreterAction::None)
65    }
66
67    /// Returns `true` if action is some.
68    pub fn is_some(&self) -> bool {
69        !self.is_none()
70    }
71
72    /// Returns [`InterpreterResult`] if action is return.
73    ///
74    /// Else it returns [None].
75    pub fn into_result_return(self) -> Option<InterpreterResult> {
76        match self {
77            InterpreterAction::Return { result } => Some(result),
78            _ => None,
79        }
80    }
81}