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 into_interpreter_result(self) -> InterpreterResult {
48 match self {
49 FrameResult::Call(outcome) => outcome.result,
50 FrameResult::Create(outcome) => outcome.result,
51 }
52 }
53
54 #[inline]
56 pub fn output(&self) -> Output {
57 match self {
58 FrameResult::Call(outcome) => Output::Call(outcome.result.output.clone()),
59 FrameResult::Create(outcome) => {
60 Output::Create(outcome.result.output.clone(), outcome.address)
61 }
62 }
63 }
64
65 #[inline]
67 pub fn gas(&self) -> &Gas {
68 match self {
69 FrameResult::Call(outcome) => &outcome.result.gas,
70 FrameResult::Create(outcome) => &outcome.result.gas,
71 }
72 }
73
74 #[inline]
76 pub fn gas_mut(&mut self) -> &mut Gas {
77 match self {
78 FrameResult::Call(outcome) => &mut outcome.result.gas,
79 FrameResult::Create(outcome) => &mut outcome.result.gas,
80 }
81 }
82
83 #[inline]
85 pub fn interpreter_result(&self) -> &InterpreterResult {
86 match self {
87 FrameResult::Call(outcome) => &outcome.result,
88 FrameResult::Create(outcome) => &outcome.result,
89 }
90 }
91
92 #[inline]
94 pub fn interpreter_result_mut(&mut self) -> &InterpreterResult {
95 match self {
96 FrameResult::Call(outcome) => &mut outcome.result,
97 FrameResult::Create(outcome) => &mut outcome.result,
98 }
99 }
100
101 #[inline]
103 pub fn instruction_result(&self) -> InstructionResult {
104 self.interpreter_result().result
105 }
106}
107
108impl FrameData {
109 pub fn new_create(created_address: Address) -> Self {
111 Self::Create(CreateFrame { created_address })
112 }
113
114 pub fn new_call(return_memory_range: Range<usize>) -> Self {
116 Self::Call(CallFrame {
117 return_memory_range,
118 })
119 }
120
121 pub fn is_call(&self) -> bool {
123 matches!(self, Self::Call { .. })
124 }
125
126 pub fn is_create(&self) -> bool {
128 matches!(self, Self::Create { .. })
129 }
130
131 pub fn created_address(&self) -> Option<Address> {
133 match self {
134 Self::Create(create_frame) => Some(create_frame.created_address),
135 _ => None,
136 }
137 }
138}