Skip to content

Commit

Permalink
feat: Implement Error for EVMError
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique committed Jul 24, 2023
1 parent 36de35b commit 8d1ca6b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{Log, State, B160};
use alloc::vec::Vec;
use bytes::Bytes;
use core::fmt;
use ruint::aliases::U256;

pub type EVMResult<DBError> = core::result::Result<ResultAndState, EVMError<DBError>>;
Expand Down Expand Up @@ -128,6 +129,22 @@ pub enum EVMError<DBError> {
Database(DBError),
}

#[cfg(feature = "std")]
impl<DBError: core::error::Error> core::error::Error for EVMError<DBError> {}

impl<DBError> fmt::Display for EVMError<DBError>
where
DBError: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EVMError::Transaction(v) => write!(f, "Transaction error: {:?}", v),
EVMError::PrevrandaoNotSet => f.write_str("pre-randao not set"),
EVMError::Database(v) => write!(f, "Database error: {}", v),
}
}
}

impl<DBError> From<InvalidTransaction> for EVMError<DBError> {
fn from(invalid: InvalidTransaction) -> Self {
EVMError::Transaction(invalid)
Expand Down

0 comments on commit 8d1ca6b

Please sign in to comment.