rtvm_interpreter/interpreter_action/
eof_create_outcome.rs

1use core::ops::Range;
2
3use crate::{Gas, InstructionResult, InterpreterResult};
4use rtvm_primitives::{Address, Bytes};
5
6/// Represents the outcome of a create operation in an interpreter.
7///
8/// This struct holds the result of the operation along with an optional address.
9/// It provides methods to determine the next action based on the result of the operation.
10#[derive(Debug, Clone, PartialEq, Eq)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub struct EOFCreateOutcome {
13    /// The result of the interpreter operation.
14    pub result: InterpreterResult,
15    /// An optional address associated with the create operation.
16    pub address: Address,
17    /// Return memory range. If EOF creation Reverts it can return bytes from the memory.
18    pub return_memory_range: Range<usize>,
19}
20
21impl EOFCreateOutcome {
22    /// Constructs a new [`EOFCreateOutcome`].
23    ///
24    /// # Arguments
25    ///
26    /// * `result` - An `InterpreterResult` representing the result of the interpreter operation.
27    /// * `address` - An optional `Address` associated with the create operation.
28    /// * `return_memory_range` - The memory range that Revert bytes are going to be written.
29    ///
30    /// # Returns
31    ///
32    /// A new [`EOFCreateOutcome`] instance.
33    pub fn new(
34        result: InterpreterResult,
35        address: Address,
36        return_memory_range: Range<usize>,
37    ) -> Self {
38        Self {
39            result,
40            address,
41            return_memory_range,
42        }
43    }
44
45    /// Retrieves a reference to the [`InstructionResult`] from the [`InterpreterResult`].
46    ///
47    /// This method provides access to the `InstructionResult` which represents the
48    /// outcome of the instruction execution. It encapsulates the result information
49    /// such as whether the instruction was executed successfully, resulted in a revert,
50    /// or encountered a fatal error.
51    ///
52    /// # Returns
53    ///
54    /// A reference to the `InstructionResult`.
55    pub fn instruction_result(&self) -> &InstructionResult {
56        &self.result.result
57    }
58
59    /// Retrieves a reference to the output bytes from the `InterpreterResult`.
60    ///
61    /// This method returns the output of the interpreted operation. The output is
62    /// typically used when the operation successfully completes and returns data.
63    ///
64    /// # Returns
65    ///
66    /// A reference to the output `Bytes`.
67    pub fn output(&self) -> &Bytes {
68        &self.result.output
69    }
70
71    /// Retrieves a reference to the `Gas` details from the `InterpreterResult`.
72    ///
73    /// This method provides access to the gas details of the operation, which includes
74    /// information about gas used, remaining, and refunded. It is essential for
75    /// understanding the gas consumption of the operation.
76    ///
77    /// # Returns
78    ///
79    /// A reference to the `Gas` details.
80    pub fn gas(&self) -> &Gas {
81        &self.result.gas
82    }
83
84    /// Returns the memory range that Revert bytes are going to be written.
85    pub fn return_range(&self) -> Range<usize> {
86        self.return_memory_range.clone()
87    }
88}