1use std::convert::Infallible;
2
3use alloy_primitives::Bytes;
4use reth_errors::ProviderError;
5use reth_evm::revm::context::result::EVMError;
6use reth_node_core::rpc::result::rpc_err;
7use reth_rpc_eth_api::AsEthApiError;
8use reth_rpc_eth_types::{
9 EthApiError,
10 error::api::{FromEvmHalt, FromRevert},
11};
12use tempo_evm::TempoHaltReason;
13
14#[derive(Debug, thiserror::Error)]
15pub enum TempoEthApiError {
16 #[error(transparent)]
17 EthApiError(EthApiError),
18}
19
20impl From<TempoEthApiError> for jsonrpsee::types::error::ErrorObject<'static> {
21 fn from(error: TempoEthApiError) -> Self {
22 match error {
23 TempoEthApiError::EthApiError(err) => err.into(),
24 }
25 }
26}
27impl From<Infallible> for TempoEthApiError {
28 fn from(_: Infallible) -> Self {
29 unreachable!()
30 }
31}
32
33impl AsEthApiError for TempoEthApiError {
34 fn as_err(&self) -> Option<&EthApiError> {
35 match self {
36 Self::EthApiError(err) => Some(err),
37 }
38 }
39}
40
41impl From<EthApiError> for TempoEthApiError {
42 fn from(error: EthApiError) -> Self {
43 Self::EthApiError(error)
44 }
45}
46
47impl From<ProviderError> for TempoEthApiError {
48 fn from(error: ProviderError) -> Self {
49 EthApiError::from(error).into()
50 }
51}
52impl<T, TxError> From<EVMError<T, TxError>> for TempoEthApiError
53where
54 T: Into<EthApiError>,
55 TxError: reth_evm::InvalidTxError,
56{
57 fn from(error: EVMError<T, TxError>) -> Self {
58 EthApiError::from(error).into()
59 }
60}
61
62impl FromEvmHalt<TempoHaltReason> for TempoEthApiError {
63 fn from_evm_halt(halt: TempoHaltReason, gas_limit: u64) -> Self {
64 EthApiError::from_evm_halt(halt, gas_limit).into()
65 }
66}
67
68impl FromRevert for TempoEthApiError {
69 fn from_revert(revert: Bytes) -> Self {
70 match tempo_precompiles::error::decode_error(&revert.0) {
71 Some(error) => Self::EthApiError(EthApiError::Other(Box::new(rpc_err(
72 3,
73 format!("execution reverted: {}", error.error),
74 Some(error.revert_bytes),
75 )))),
76 None => Self::EthApiError(EthApiError::from_revert(revert)),
77 }
78 }
79}