-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(rpc):
EthApiTypes
trait for network specific error AT (#9523)
Co-authored-by: Matthias Seitz <[email protected]>
- Loading branch information
Showing
39 changed files
with
879 additions
and
479 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,85 @@ | ||
//! RPC errors specific to OP. | ||
|
||
use jsonrpsee::types::ErrorObject; | ||
use reth_primitives::revm_primitives::{InvalidTransaction, OptimismInvalidTransaction}; | ||
use reth_rpc_eth_api::AsEthApiError; | ||
use reth_rpc_eth_types::EthApiError; | ||
use reth_rpc_server_types::result::internal_rpc_err; | ||
use reth_rpc_types::ToRpcError; | ||
use reth_rpc_server_types::result::{internal_rpc_err, rpc_err}; | ||
use reth_rpc_types::error::EthRpcErrorCode; | ||
|
||
/// Optimism specific errors, that extend [`EthApiError`]. | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum OpEthApiError { | ||
/// L1 ethereum error. | ||
#[error(transparent)] | ||
Eth(#[from] EthApiError), | ||
/// Thrown when calculating L1 gas fee. | ||
#[error("failed to calculate l1 gas fee")] | ||
L1BlockFeeError, | ||
/// Thrown when calculating L1 gas used | ||
#[error("failed to calculate l1 gas used")] | ||
L1BlockGasError, | ||
/// Wrapper for [`revm_primitives::InvalidTransaction`](InvalidTransaction). | ||
#[error(transparent)] | ||
InvalidTransaction(OptimismInvalidTransactionError), | ||
} | ||
|
||
impl ToRpcError for OpEthApiError { | ||
fn to_rpc_error(&self) -> ErrorObject<'static> { | ||
impl AsEthApiError for OpEthApiError { | ||
fn as_err(&self) -> Option<&EthApiError> { | ||
match self { | ||
Self::L1BlockFeeError | Self::L1BlockGasError => internal_rpc_err(self.to_string()), | ||
Self::Eth(err) => Some(err), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl From<OpEthApiError> for EthApiError { | ||
impl From<OpEthApiError> for jsonrpsee_types::error::ErrorObject<'static> { | ||
fn from(err: OpEthApiError) -> Self { | ||
Self::other(err) | ||
match err { | ||
OpEthApiError::Eth(err) => err.into(), | ||
OpEthApiError::L1BlockFeeError | OpEthApiError::L1BlockGasError => { | ||
internal_rpc_err(err.to_string()) | ||
} | ||
OpEthApiError::InvalidTransaction(err) => err.into(), | ||
} | ||
} | ||
} | ||
|
||
/// Optimism specific invalid transaction errors | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum OptimismInvalidTransactionError { | ||
/// A deposit transaction was submitted as a system transaction post-regolith. | ||
#[error("no system transactions allowed after regolith")] | ||
DepositSystemTxPostRegolith, | ||
/// A deposit transaction halted post-regolith | ||
#[error("deposit transaction halted after regolith")] | ||
HaltedDepositPostRegolith, | ||
} | ||
|
||
impl From<OptimismInvalidTransactionError> for jsonrpsee_types::error::ErrorObject<'static> { | ||
fn from(err: OptimismInvalidTransactionError) -> Self { | ||
match err { | ||
OptimismInvalidTransactionError::DepositSystemTxPostRegolith | | ||
OptimismInvalidTransactionError::HaltedDepositPostRegolith => { | ||
rpc_err(EthRpcErrorCode::TransactionRejected.code(), err.to_string(), None) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<InvalidTransaction> for OptimismInvalidTransactionError { | ||
type Error = InvalidTransaction; | ||
|
||
fn try_from(err: InvalidTransaction) -> Result<Self, Self::Error> { | ||
match err { | ||
InvalidTransaction::OptimismError(err) => match err { | ||
OptimismInvalidTransaction::DepositSystemTxPostRegolith => { | ||
Ok(Self::DepositSystemTxPostRegolith) | ||
} | ||
OptimismInvalidTransaction::HaltedDepositPostRegolith => { | ||
Ok(Self::HaltedDepositPostRegolith) | ||
} | ||
}, | ||
_ => Err(err), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.