revm_handler/
frame_data.rs1use context_interface::result::Output;
2use core::ops::Range;
3use interpreter::{CallOutcome, CreateOutcome, Gas, InstructionResult, InterpreterResult};
4use primitives::Address;
5
6#[derive(Debug, Clone)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct CallFrame {
10 pub return_memory_range: Range<usize>,
12}
13
14#[derive(Debug, Clone)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17pub struct CreateFrame {
18 pub created_address: Address,
20}
21
22#[derive(Debug, Clone)]
26#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
27pub enum FrameData {
28 Call(CallFrame),
30 Create(CreateFrame),
32}
33
34#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36#[derive(Debug, Clone)]
37pub enum FrameResult {
38 Call(CallOutcome),
40 Create(CreateOutcome),
42}
43
44impl FrameResult {
45 #[inline]
47 pub fn new_call_oog(gas_limit: u64, memory_offset: core::ops::Range<usize>) -> Self {
48 Self::Call(CallOutcome::new_oog(gas_limit, memory_offset))
49 }
50
51 #[inline]
53 pub fn new_create_oog(gas_limit: u64) -> Self {
54 Self::Create(CreateOutcome::new_oog(gas_limit))
55 }
56
57 #[inline]
59 pub fn into_interpreter_result(self) -> InterpreterResult {
60 match self {
61 FrameResult::Call(outcome) => outcome.result,
62 FrameResult::Create(outcome) => outcome.result,
63 }
64 }
65
66 #[inline]
68 pub fn output(&self) -> Output {
69 match self {
70 FrameResult::Call(outcome) => Output::Call(outcome.result.output.clone()),
71 FrameResult::Create(outcome) => {
72 Output::Create(outcome.result.output.clone(), outcome.address)
73 }
74 }
75 }
76
77 #[inline]
79 pub fn gas(&self) -> &Gas {
80 match self {
81 FrameResult::Call(outcome) => &outcome.result.gas,
82 FrameResult::Create(outcome) => &outcome.result.gas,
83 }
84 }
85
86 #[inline]
88 pub fn gas_mut(&mut self) -> &mut Gas {
89 match self {
90 FrameResult::Call(outcome) => &mut outcome.result.gas,
91 FrameResult::Create(outcome) => &mut outcome.result.gas,
92 }
93 }
94
95 #[inline]
97 pub fn interpreter_result(&self) -> &InterpreterResult {
98 match self {
99 FrameResult::Call(outcome) => &outcome.result,
100 FrameResult::Create(outcome) => &outcome.result,
101 }
102 }
103
104 #[inline]
106 pub fn interpreter_result_mut(&mut self) -> &mut InterpreterResult {
107 match self {
108 FrameResult::Call(outcome) => &mut outcome.result,
109 FrameResult::Create(outcome) => &mut outcome.result,
110 }
111 }
112
113 #[inline]
115 pub fn instruction_result(&self) -> InstructionResult {
116 self.interpreter_result().result
117 }
118}
119
120impl FrameData {
121 pub fn new_create(created_address: Address) -> Self {
123 Self::Create(CreateFrame { created_address })
124 }
125
126 pub fn new_call(return_memory_range: Range<usize>) -> Self {
128 Self::Call(CallFrame {
129 return_memory_range,
130 })
131 }
132
133 pub fn is_call(&self) -> bool {
135 matches!(self, Self::Call { .. })
136 }
137
138 pub fn is_create(&self) -> bool {
140 matches!(self, Self::Create { .. })
141 }
142
143 pub fn created_address(&self) -> Option<Address> {
145 match self {
146 Self::Create(create_frame) => Some(create_frame.created_address),
147 _ => None,
148 }
149 }
150}