//! Helper traits to wrap generic l1 errors, in network specific error type configured in //! [`EthApiTypes`](crate::EthApiTypes). use reth_rpc_eth_types::EthApiError; use revm_primitives::EVMError; /// Helper trait to wrap core [`EthApiError`]. pub trait FromEthApiError: From { /// Converts from error via [`EthApiError`]. fn from_eth_err(err: E) -> Self where EthApiError: From; } impl FromEthApiError for T where T: From, { fn from_eth_err(err: E) -> Self where EthApiError: From, { T::from(EthApiError::from(err)) } } /// Helper trait to wrap core [`EthApiError`]. pub trait IntoEthApiError: Into { /// Converts into error via [`EthApiError`]. fn into_eth_err(self) -> E where E: FromEthApiError; } impl IntoEthApiError for T where EthApiError: From, { fn into_eth_err(self) -> E where E: FromEthApiError, { E::from_eth_err(self) } } /// Helper trait to access wrapped core error. pub trait AsEthApiError { /// Returns reference to [`EthApiError`], if this an error variant inherited from core /// functionality. fn as_err(&self) -> Option<&EthApiError>; /// Returns `true` if error is /// [`RpcInvalidTransactionError::GasTooHigh`](reth_rpc_eth_types::RpcInvalidTransactionError::GasTooHigh). fn is_gas_too_high(&self) -> bool { if let Some(err) = self.as_err() { return err.is_gas_too_high() } false } } impl AsEthApiError for EthApiError { fn as_err(&self) -> Option<&EthApiError> { Some(self) } } /// Helper trait to convert from revm errors. pub trait FromEvmError: From { /// Converts from a revm error. fn from_evm_err(err: EVMError) -> Self where EthApiError: From; } impl FromEvmError for T where T: From, { fn from_evm_err(err: EVMError) -> Self where EthApiError: From, { err.into_eth_err() } }