revm_interpreter/interpreter_action/
call_outcome.rs

1use crate::{Gas, InstructionResult, InterpreterResult};
2use core::ops::Range;
3use primitives::Bytes;
4
5/// Represents the outcome of a call operation in a virtual machine.
6///
7/// This struct encapsulates the result of executing an instruction by an interpreter, including
8/// the result itself, gas usage information, and the memory offset where output data is stored.
9///
10/// # Fields
11///
12/// * `result` - The result of the interpreter's execution, including output data and gas usage.
13/// * `memory_offset` - The range in memory where the output data is located.
14#[derive(Clone, Debug, PartialEq, Eq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct CallOutcome {
17    pub result: InterpreterResult,
18    pub memory_offset: Range<usize>,
19}
20
21impl CallOutcome {
22    /// Constructs a new [`CallOutcome`].
23    ///
24    /// Creates an instance of [`CallOutcome`] with the given interpreter result and memory offset.
25    ///
26    /// # Arguments
27    ///
28    /// * `result` - The result of the interpreter's execution.
29    /// * `memory_offset` - The range in memory indicating where the output data is stored.
30    pub fn new(result: InterpreterResult, memory_offset: Range<usize>) -> Self {
31        Self {
32            result,
33            memory_offset,
34        }
35    }
36
37    /// Returns a reference to the instruction result.
38    ///
39    /// Provides access to the result of the executed instruction.
40    ///
41    /// # Returns
42    ///
43    /// A reference to the [`InstructionResult`].
44    pub fn instruction_result(&self) -> &InstructionResult {
45        &self.result.result
46    }
47
48    /// Returns the gas usage information.
49    ///
50    /// Provides access to the gas usage details of the executed instruction.
51    ///
52    /// # Returns
53    ///
54    /// An instance of [`Gas`] representing the gas usage.
55    pub fn gas(&self) -> Gas {
56        self.result.gas
57    }
58
59    /// Returns a reference to the output data.
60    ///
61    /// Provides access to the output data generated by the executed instruction.
62    ///
63    /// # Returns
64    ///
65    /// A reference to the output data as [`Bytes`].
66    pub fn output(&self) -> &Bytes {
67        &self.result.output
68    }
69
70    /// Returns the start position of the memory offset.
71    ///
72    /// Provides the starting index of the memory range where the output data is stored.
73    ///
74    /// # Returns
75    ///
76    /// The starting index of the memory offset as [`usize`].
77    pub fn memory_start(&self) -> usize {
78        self.memory_offset.start
79    }
80
81    /// Returns the length of the memory range.
82    ///
83    /// Provides the length of the memory range where the output data is stored.
84    ///
85    /// # Returns
86    ///
87    /// The length of the memory range as [`usize`].
88    pub fn memory_length(&self) -> usize {
89        self.memory_offset.len()
90    }
91}