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 /// Retrieves a reference to the [`InstructionResult`] from the [`InterpreterResult`].
34 ///
35 /// This method provides access to the [`InstructionResult`] which represents the
36 /// outcome of the instruction execution.
37 ///
38 /// It encapsulates the result information such as whether the instruction was
39 /// executed successfully, resulted in a revert, or encountered a fatal error.
40 ///
41 /// # Returns
42 ///
43 /// A reference to the [`InstructionResult`].
44 pub fn instruction_result(&self) -> &InstructionResult {
45 &self.result.result
46 }
47
48 /// Retrieves a reference to the output bytes from the [`InterpreterResult`].
49 ///
50 /// This method returns the output of the interpreted operation.
51 ///
52 /// The output is typically used when the operation successfully completes and
53 /// returns data.
54 ///
55 /// # Returns
56 ///
57 /// A reference to the output [`Bytes`].
58 pub fn output(&self) -> &Bytes {
59 &self.result.output
60 }
61
62 /// Retrieves a reference to the [`Gas`] details from the [`InterpreterResult`].
63 ///
64 /// This method provides access to the gas details of the operation, which includes
65 /// information about gas used, remaining, and refunded.
66 ///
67 /// It is essential for understanding the gas consumption of the operation.
68 ///
69 /// # Returns
70 ///
71 /// A reference to the [`Gas`] details.
72 pub fn gas(&self) -> &Gas {
73 &self.result.gas
74 }
75}