Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: expose InstructionResult getters in Interpreter result #1002

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Comment on lines +317 to +318
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems wrong no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

}

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