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 /// The result of the interpreter's execution, including output data and gas usage
18 pub result: InterpreterResult,
19 /// The range in memory where the output data is located
20 pub memory_offset: Range<usize>,
21}
22
23impl CallOutcome {
24 /// Constructs a new [`CallOutcome`].
25 ///
26 /// Creates an instance of [`CallOutcome`] with the given interpreter result and memory offset.
27 ///
28 /// # Arguments
29 ///
30 /// * `result` - The result of the interpreter's execution.
31 /// * `memory_offset` - The range in memory indicating where the output data is stored.
32 pub fn new(result: InterpreterResult, memory_offset: Range<usize>) -> Self {
33 Self {
34 result,
35 memory_offset,
36 }
37 }
38
39 /// Returns a reference to the instruction result.
40 ///
41 /// Provides access to the result of the executed instruction.
42 ///
43 /// # Returns
44 ///
45 /// A reference to the [`InstructionResult`].
46 pub fn instruction_result(&self) -> &InstructionResult {
47 &self.result.result
48 }
49
50 /// Returns the gas usage information.
51 ///
52 /// Provides access to the gas usage details of the executed instruction.
53 ///
54 /// # Returns
55 ///
56 /// An instance of [`Gas`] representing the gas usage.
57 pub fn gas(&self) -> Gas {
58 self.result.gas
59 }
60
61 /// Returns a reference to the output data.
62 ///
63 /// Provides access to the output data generated by the executed instruction.
64 ///
65 /// # Returns
66 ///
67 /// A reference to the output data as [`Bytes`].
68 pub fn output(&self) -> &Bytes {
69 &self.result.output
70 }
71
72 /// Returns the start position of the memory offset.
73 ///
74 /// Provides the starting index of the memory range where the output data is stored.
75 ///
76 /// # Returns
77 ///
78 /// The starting index of the memory offset as [`usize`].
79 pub fn memory_start(&self) -> usize {
80 self.memory_offset.start
81 }
82
83 /// Returns the length of the memory range.
84 ///
85 /// Provides the length of the memory range where the output data is stored.
86 ///
87 /// # Returns
88 ///
89 /// The length of the memory range as [`usize`].
90 pub fn memory_length(&self) -> usize {
91 self.memory_offset.len()
92 }
93}