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}
17
18impl CreateOutcome {
19 /// Constructs a new [`CreateOutcome`].
20 ///
21 /// # Arguments
22 ///
23 /// * `result` - An [`InterpreterResult`] representing the result of the interpreter operation.
24 /// * `address` - An optional [`Address`] associated with the create operation.
25 ///
26 /// # Returns
27 ///
28 /// A new [`CreateOutcome`] instance.
29 pub fn new(result: InterpreterResult, address: Option<Address>) -> Self {
30 Self { result, address }
31 }
32
33 /// Constructs a new [`CreateOutcome`] for an out-of-gas error.
34 ///
35 /// # Arguments
36 ///
37 /// * `gas_limit` - The gas limit that was exceeded.
38 ///
39 /// # Returns
40 ///
41 /// A new [`CreateOutcome`] instance with no address.
42 pub fn new_oog(gas_limit: u64) -> Self {
43 Self::new(InterpreterResult::new_oog(gas_limit), None)
44 }
45
46 /// Retrieves a reference to the [`InstructionResult`] from the [`InterpreterResult`].
47 ///
48 /// This method provides access to the [`InstructionResult`] which represents the
49 /// outcome of the instruction execution.
50 ///
51 /// It encapsulates the result information such as whether the instruction was
52 /// executed successfully, resulted in a revert, or encountered a fatal error.
53 ///
54 /// # Returns
55 ///
56 /// A reference to the [`InstructionResult`].
57 pub fn instruction_result(&self) -> &InstructionResult {
58 &self.result.result
59 }
60
61 /// Retrieves a reference to the output bytes from the [`InterpreterResult`].
62 ///
63 /// This method returns the output of the interpreted operation.
64 ///
65 /// The output is typically used when the operation successfully completes and
66 /// returns data.
67 ///
68 /// # Returns
69 ///
70 /// A reference to the output [`Bytes`].
71 pub fn output(&self) -> &Bytes {
72 &self.result.output
73 }
74
75 /// Retrieves a reference to the [`Gas`] details from the [`InterpreterResult`].
76 ///
77 /// This method provides access to the gas details of the operation, which includes
78 /// information about gas used, remaining, and refunded.
79 ///
80 /// It is essential for understanding the gas consumption of the operation.
81 ///
82 /// # Returns
83 ///
84 /// A reference to the [`Gas`] details.
85 pub fn gas(&self) -> &Gas {
86 &self.result.gas
87 }
88}