Skip to content

Commit

Permalink
chore: expose InstructionResult getters in Interpreter result (#1002)
Browse files Browse the repository at this point in the history
* chore: expose InstructionResult getters in Interpreter result

* chore: reorder items
  • Loading branch information
mattsse committed Jan 22, 2024
1 parent c93be44 commit 7cf937a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/interpreter/src/instruction_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ macro_rules! return_error {
impl InstructionResult {
/// Returns whether the result is a success.
#[inline]
pub fn is_ok(self) -> bool {
pub const fn is_ok(self) -> bool {
matches!(self, crate::return_ok!())
}

/// Returns whether the result is a revert.
#[inline]
pub fn is_revert(self) -> bool {
pub const fn is_revert(self) -> bool {
matches!(self, crate::return_revert!())
}

/// Returns whether the result is an error.
#[inline]
pub fn is_error(self) -> bool {
pub const fn is_error(self) -> bool {
matches!(self, return_error!())
}
}
Expand Down
24 changes: 24 additions & 0 deletions crates/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ pub struct Interpreter {
pub next_action: Option<InterpreterAction>,
}

/// The result of an interpreter operation.
#[derive(Debug, Clone)]
pub struct InterpreterResult {
/// The result of the instruction execution.
pub result: InstructionResult,
/// The output of the instruction execution.
pub output: Bytes,
/// The gas usage information.
pub gas: Gas,
}

Expand Down Expand Up @@ -300,3 +304,23 @@ impl Interpreter {
}
}
}

impl InterpreterResult {
/// Returns whether the instruction result is a success.
#[inline]
pub const fn is_ok(&self) -> bool {
self.result.is_ok()
}

/// Returns whether the instruction result is a revert.
#[inline]
pub const fn is_revert(&self) -> bool {
self.result.is_ok()
}

/// Returns whether the instruction result is an error.
#[inline]
pub const fn is_error(&self) -> bool {
self.result.is_error()
}
}

0 comments on commit 7cf937a

Please sign in to comment.