revm_interpreter/interpreter_action/create_outcome.rs
1use crate::{Gas, InstructionResult, InterpreterResult};
2use revm_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/// It provides methods to determine the next action based on the result of the operation.
8#[derive(Debug, Clone, PartialEq, Eq)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct CreateOutcome {
11 // The result of the interpreter operation.
12 pub result: InterpreterResult,
13 // An optional address associated with the create operation.
14 pub address: Option<Address>,
15}
16
17impl CreateOutcome {
18 /// Constructs a new `CreateOutcome`.
19 ///
20 /// # Arguments
21 ///
22 /// * `result` - An `InterpreterResult` representing the result of the interpreter operation.
23 /// * `address` - An optional `Address` associated with the create operation.
24 ///
25 /// # Returns
26 ///
27 /// A new `CreateOutcome` instance.
28 pub fn new(result: InterpreterResult, address: Option<Address>) -> Self {
29 Self { result, address }
30 }
31
32 /// Retrieves a reference to the `InstructionResult` from the `InterpreterResult`.
33 ///
34 /// This method provides access to the `InstructionResult` which represents the
35 /// outcome of the instruction execution. It encapsulates the result information
36 /// such as whether the instruction was executed successfully, resulted in a revert,
37 /// or encountered a fatal error.
38 ///
39 /// # Returns
40 ///
41 /// A reference to the `InstructionResult`.
42 pub fn instruction_result(&self) -> &InstructionResult {
43 &self.result.result
44 }
45
46 /// Retrieves a reference to the output bytes from the `InterpreterResult`.
47 ///
48 /// This method returns the output of the interpreted operation. The output is
49 /// typically used when the operation successfully completes and returns data.
50 ///
51 /// # Returns
52 ///
53 /// A reference to the output `Bytes`.
54 pub fn output(&self) -> &Bytes {
55 &self.result.output
56 }
57
58 /// Retrieves a reference to the `Gas` details from the `InterpreterResult`.
59 ///
60 /// This method provides access to the gas details of the operation, which includes
61 /// information about gas used, remaining, and refunded. It is essential for
62 /// understanding the gas consumption of the operation.
63 ///
64 /// # Returns
65 ///
66 /// A reference to the `Gas` details.
67 pub fn gas(&self) -> &Gas {
68 &self.result.gas
69 }
70}