revm_handler/
frame_data.rsuse context_interface::result::Output;
use core::ops::Range;
use interpreter::{CallOutcome, CreateOutcome, Gas, InstructionResult, InterpreterResult};
use primitives::Address;
pub struct CallFrame {
pub return_memory_range: Range<usize>,
}
pub struct CreateFrame {
pub created_address: Address,
}
pub struct EOFCreateFrame {
pub created_address: Address,
}
pub enum FrameData {
Call(CallFrame),
Create(CreateFrame),
EOFCreate(EOFCreateFrame),
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug)]
pub enum FrameResult {
Call(CallOutcome),
Create(CreateOutcome),
EOFCreate(CreateOutcome),
}
impl FrameResult {
#[inline]
pub fn into_interpreter_result(self) -> InterpreterResult {
match self {
FrameResult::Call(outcome) => outcome.result,
FrameResult::Create(outcome) => outcome.result,
FrameResult::EOFCreate(outcome) => outcome.result,
}
}
#[inline]
pub fn output(&self) -> Output {
match self {
FrameResult::Call(outcome) => Output::Call(outcome.result.output.clone()),
FrameResult::Create(outcome) => {
Output::Create(outcome.result.output.clone(), outcome.address)
}
FrameResult::EOFCreate(outcome) => {
Output::Create(outcome.result.output.clone(), outcome.address)
}
}
}
#[inline]
pub fn gas(&self) -> &Gas {
match self {
FrameResult::Call(outcome) => &outcome.result.gas,
FrameResult::Create(outcome) => &outcome.result.gas,
FrameResult::EOFCreate(outcome) => &outcome.result.gas,
}
}
#[inline]
pub fn gas_mut(&mut self) -> &mut Gas {
match self {
FrameResult::Call(outcome) => &mut outcome.result.gas,
FrameResult::Create(outcome) => &mut outcome.result.gas,
FrameResult::EOFCreate(outcome) => &mut outcome.result.gas,
}
}
#[inline]
pub fn interpreter_result(&self) -> &InterpreterResult {
match self {
FrameResult::Call(outcome) => &outcome.result,
FrameResult::Create(outcome) => &outcome.result,
FrameResult::EOFCreate(outcome) => &outcome.result,
}
}
#[inline]
pub fn interpreter_result_mut(&mut self) -> &InterpreterResult {
match self {
FrameResult::Call(outcome) => &mut outcome.result,
FrameResult::Create(outcome) => &mut outcome.result,
FrameResult::EOFCreate(outcome) => &mut outcome.result,
}
}
#[inline]
pub fn instruction_result(&self) -> InstructionResult {
self.interpreter_result().result
}
}
impl FrameData {
pub fn new_create(created_address: Address) -> Self {
Self::Create(CreateFrame { created_address })
}
pub fn new_call(return_memory_range: Range<usize>) -> Self {
Self::Call(CallFrame {
return_memory_range,
})
}
pub fn is_call(&self) -> bool {
matches!(self, Self::Call { .. })
}
pub fn is_create(&self) -> bool {
matches!(self, Self::Create { .. })
}
pub fn created_address(&self) -> Option<Address> {
match self {
Self::Create(create_frame) => Some(create_frame.created_address),
_ => None,
}
}
}