Skip to main content

revm_interpreter/interpreter_action/
create_outcome.rs

1use crate::{Gas, InstructionResult, InterpreterResult};
2use primitives::{Address, Bytes};
3
4/// Represents the outcome of a create operation in an interpreter.
5///
6/// This struct holds the result of the operation along with an optional address.
7///
8/// It provides methods to determine the next action based on the result of the operation.
9#[derive(Debug, Clone, PartialEq, Eq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct CreateOutcome {
12    /// The result of the interpreter operation
13    pub result: InterpreterResult,
14    /// An optional address associated with the create operation
15    pub address: Option<Address>,
16    /// EIP-8037: whether the CREATE opcode charged the conditional
17    /// `create_state_gas` on the parent's tracker (the destination did not
18    /// exist at access time). When the create fails the parent refunds it.
19    pub charged_create_state_gas: bool,
20}
21
22impl CreateOutcome {
23    /// Constructs a new [`CreateOutcome`].
24    ///
25    /// # Arguments
26    ///
27    /// * `result` - An [`InterpreterResult`] representing the result of the interpreter operation.
28    /// * `address` - An optional [`Address`] associated with the create operation.
29    ///
30    /// # Returns
31    ///
32    /// A new [`CreateOutcome`] instance.
33    pub const fn new(result: InterpreterResult, address: Option<Address>) -> Self {
34        Self {
35            result,
36            address,
37            charged_create_state_gas: false,
38        }
39    }
40
41    /// Constructs a new [`CreateOutcome`] for an out-of-gas error.
42    ///
43    /// # Arguments
44    ///
45    /// * `gas_limit` - The gas limit that was exceeded.
46    ///
47    /// # Returns
48    ///
49    /// A new [`CreateOutcome`] instance with no address.
50    pub fn new_oog(gas_limit: u64, reservoir: u64) -> Self {
51        Self::new(InterpreterResult::new_oog(gas_limit, reservoir), None)
52    }
53
54    /// Retrieves a reference to the [`InstructionResult`] from the [`InterpreterResult`].
55    ///
56    /// This method provides access to the [`InstructionResult`] which represents the
57    /// outcome of the instruction execution.
58    ///
59    /// It encapsulates the result information such as whether the instruction was
60    /// executed successfully, resulted in a revert, or encountered a fatal error.
61    ///
62    /// # Returns
63    ///
64    /// A reference to the [`InstructionResult`].
65    pub const fn instruction_result(&self) -> &InstructionResult {
66        &self.result.result
67    }
68
69    /// Retrieves a reference to the output bytes from the [`InterpreterResult`].
70    ///
71    /// This method returns the output of the interpreted operation.
72    ///
73    /// The output is typically used when the operation successfully completes and
74    /// returns data.
75    ///
76    /// # Returns
77    ///
78    /// A reference to the output [`Bytes`].
79    pub const fn output(&self) -> &Bytes {
80        &self.result.output
81    }
82
83    /// Retrieves a reference to the [`Gas`] details from the [`InterpreterResult`].
84    ///
85    /// This method provides access to the gas details of the operation, which includes
86    /// information about gas used, remaining, and refunded.
87    ///
88    /// It is essential for understanding the gas consumption of the operation.
89    ///
90    /// # Returns
91    ///
92    /// A reference to the [`Gas`] details.
93    pub const fn gas(&self) -> &Gas {
94        &self.result.gas
95    }
96}