revm_interpreter/
interpreter_action.rs1mod call_inputs;
2mod call_outcome;
3mod create_inputs;
4mod create_outcome;
5
6pub use call_inputs::{CallInput, CallInputs, CallScheme, CallValue};
7pub use call_outcome::CallOutcome;
8pub use create_inputs::CreateInputs;
9pub use create_outcome::CreateOutcome;
10use primitives::Bytes;
11
12use crate::{Gas, InstructionResult, InterpreterResult, SharedMemory};
13use std::boxed::Box;
14
15#[derive(Clone, Debug, PartialEq, Eq)]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18pub enum FrameInput {
19 Empty,
21 Call(Box<CallInputs>),
23 Create(Box<CreateInputs>),
25}
26
27#[derive(Clone, Debug, PartialEq, Eq)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30pub struct FrameInit {
31 pub depth: usize,
33 pub memory: SharedMemory,
35 pub frame_input: FrameInput,
37}
38
39impl AsMut<Self> for FrameInput {
40 fn as_mut(&mut self) -> &mut Self {
41 self
42 }
43}
44
45#[derive(Clone, Debug, PartialEq, Eq)]
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48pub enum InterpreterAction {
49 NewFrame(FrameInput),
51 Return(InterpreterResult),
53}
54
55impl InterpreterAction {
56 pub fn is_call(&self) -> bool {
58 matches!(self, InterpreterAction::NewFrame(FrameInput::Call(..)))
59 }
60
61 pub fn is_create(&self) -> bool {
63 matches!(self, InterpreterAction::NewFrame(FrameInput::Create(..)))
64 }
65
66 pub fn is_return(&self) -> bool {
68 matches!(self, InterpreterAction::Return { .. })
69 }
70
71 pub fn into_result_return(self) -> Option<InterpreterResult> {
75 match self {
76 InterpreterAction::Return(result) => Some(result),
77 _ => None,
78 }
79 }
80
81 pub fn instruction_result(&self) -> Option<InstructionResult> {
85 match self {
86 InterpreterAction::Return(result) => Some(result.result),
87 _ => None,
88 }
89 }
90
91 pub fn new_frame(frame_input: FrameInput) -> Self {
93 Self::NewFrame(frame_input)
94 }
95
96 pub fn new_halt(result: InstructionResult, gas: Gas) -> Self {
98 Self::Return(InterpreterResult::new(result, Bytes::new(), gas))
99 }
100
101 pub fn new_return(result: InstructionResult, output: Bytes, gas: Gas) -> Self {
103 Self::Return(InterpreterResult::new(result, output, gas))
104 }
105
106 pub fn new_stop() -> Self {
108 Self::Return(InterpreterResult::new(
109 InstructionResult::Stop,
110 Bytes::new(),
111 Gas::new(0),
112 ))
113 }
114}