rtvm_interpreter/
interpreter_action.rs

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