reth_rpc_eth_types/error/
api.rs1use crate::EthApiError;
5use reth_errors::ProviderError;
6use reth_evm::{ConfigureEvm, EvmErrorFor, HaltReasonFor};
7use revm::context_interface::result::HaltReason;
8
9use super::RpcInvalidTransactionError;
10
11pub trait FromEthApiError: From<EthApiError> {
13 fn from_eth_err<E>(err: E) -> Self
15 where
16 EthApiError: From<E>;
17}
18
19impl<T> FromEthApiError for T
20where
21 T: From<EthApiError>,
22{
23 fn from_eth_err<E>(err: E) -> Self
24 where
25 EthApiError: From<E>,
26 {
27 T::from(EthApiError::from(err))
28 }
29}
30
31pub trait IntoEthApiError: Into<EthApiError> {
33 fn into_eth_err<E>(self) -> E
35 where
36 E: FromEthApiError;
37}
38
39impl<T> IntoEthApiError for T
40where
41 EthApiError: From<T>,
42{
43 fn into_eth_err<E>(self) -> E
44 where
45 E: FromEthApiError,
46 {
47 E::from_eth_err(self)
48 }
49}
50
51pub trait AsEthApiError {
53 fn as_err(&self) -> Option<&EthApiError>;
56
57 fn is_gas_too_high(&self) -> bool {
60 if let Some(err) = self.as_err() {
61 return err.is_gas_too_high()
62 }
63
64 false
65 }
66
67 fn is_gas_too_low(&self) -> bool {
70 if let Some(err) = self.as_err() {
71 return err.is_gas_too_low()
72 }
73
74 false
75 }
76}
77
78impl AsEthApiError for EthApiError {
79 fn as_err(&self) -> Option<&EthApiError> {
80 Some(self)
81 }
82}
83
84pub trait FromEvmError<Evm: ConfigureEvm>:
86 From<EvmErrorFor<Evm, ProviderError>> + FromEvmHalt<HaltReasonFor<Evm>>
87{
88 fn from_evm_err(err: EvmErrorFor<Evm, ProviderError>) -> Self {
90 err.into()
91 }
92}
93
94impl<T, Evm> FromEvmError<Evm> for T
95where
96 T: From<EvmErrorFor<Evm, ProviderError>> + FromEvmHalt<HaltReasonFor<Evm>>,
97 Evm: ConfigureEvm,
98{
99}
100
101pub trait FromEvmHalt<Halt> {
103 fn from_evm_halt(halt: Halt, gas_limit: u64) -> Self;
105}
106
107impl FromEvmHalt<HaltReason> for EthApiError {
108 fn from_evm_halt(halt: HaltReason, gas_limit: u64) -> Self {
109 RpcInvalidTransactionError::halt(halt, gas_limit).into()
110 }
111}