Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
fix(primitives): Error Primitive Display + Error Implementations (blu…
Browse files Browse the repository at this point in the history
…ealloy#770)

* Error and display impls for error primitives

* Fix std lib use

* Fix std lib use
  • Loading branch information
refcell authored Oct 6, 2023
1 parent 8bb9ab1 commit fb1e364
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,73 @@ pub enum InvalidTransaction {
DepositSystemTxPostRegolith,
}

#[cfg(feature = "std")]
impl std::error::Error for InvalidTransaction {}

impl fmt::Display for InvalidTransaction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InvalidTransaction::PriorityFeeGreaterThanMaxFee => {
write!(f, "Priority fee is greater than max fee")
}
InvalidTransaction::GasPriceLessThanBasefee => {
write!(f, "Gas price is less than basefee")
}
InvalidTransaction::CallerGasLimitMoreThanBlock => {
write!(f, "Caller gas limit exceeds the block gas limit")
}
InvalidTransaction::CallGasCostMoreThanGasLimit => {
write!(f, "Call gas cost exceeds the gas limit")
}
InvalidTransaction::RejectCallerWithCode => {
write!(f, "Reject transactions from senders with deployed code")
}
InvalidTransaction::LackOfFundForMaxFee { fee, balance } => {
write!(f, "Lack of funds {} for max fee {}", balance, fee)
}
InvalidTransaction::OverflowPaymentInTransaction => {
write!(f, "Overflow payment in transaction")
}
InvalidTransaction::NonceOverflowInTransaction => {
write!(f, "Nonce overflow in transaction")
}
InvalidTransaction::NonceTooHigh { tx, state } => {
write!(f, "Nonce too high {}, expected {}", tx, state)
}
InvalidTransaction::NonceTooLow { tx, state } => {
write!(f, "Nonce {} too low, expected {}", tx, state)
}
InvalidTransaction::CreateInitcodeSizeLimit => {
write!(f, "Create initcode size limit")
}
InvalidTransaction::InvalidChainId => write!(f, "Invalid chain id"),
InvalidTransaction::AccessListNotSupported => {
write!(f, "Access list not supported")
}
InvalidTransaction::MaxFeePerBlobGasNotSupported => {
write!(f, "Max fee per blob gas not supported")
}
InvalidTransaction::BlobVersionedHashesNotSupported => {
write!(f, "Blob versioned hashes not supported")
}
InvalidTransaction::BlobGasPriceGreaterThanMax => {
write!(f, "Blob gas price is greater than max fee per blob gas")
}
InvalidTransaction::EmptyBlobs => write!(f, "Empty blobs"),
InvalidTransaction::BlobCreateTransaction => write!(f, "Blob create transaction"),
InvalidTransaction::TooManyBlobs => write!(f, "Too many blobs"),
InvalidTransaction::BlobVersionNotSupported => write!(f, "Blob version not supported"),
#[cfg(feature = "optimism")]
InvalidTransaction::DepositSystemTxPostRegolith => {
write!(
f,
"Deposit system transactions post regolith hardfork are not supported"
)
}
}
}
}

impl<DBError> From<InvalidHeader> for EVMError<DBError> {
fn from(invalid: InvalidHeader) -> Self {
EVMError::Header(invalid)
Expand All @@ -233,6 +300,18 @@ pub enum InvalidHeader {
ExcessBlobGasNotSet,
}

#[cfg(feature = "std")]
impl std::error::Error for InvalidHeader {}

impl fmt::Display for InvalidHeader {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
InvalidHeader::PrevrandaoNotSet => write!(f, "Prevrandao not set"),
InvalidHeader::ExcessBlobGasNotSet => write!(f, "Excess blob gas not set"),
}
}
}

/// Reason a transaction successfully completed.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down

0 comments on commit fb1e364

Please sign in to comment.