cfx_rpc_utils/error/
api.rs1use crate::error::EthApiError;
5
6pub trait FromEthApiError: From<EthApiError> {
8 fn from_eth_err<E>(err: E) -> Self
10 where EthApiError: From<E>;
11}
12
13impl<T> FromEthApiError for T
14where T: From<EthApiError>
15{
16 fn from_eth_err<E>(err: E) -> Self
17 where EthApiError: From<E> {
18 T::from(EthApiError::from(err))
19 }
20}
21
22pub trait IntoEthApiError: Into<EthApiError> {
24 fn into_eth_err<E>(self) -> E
26 where E: FromEthApiError;
27}
28
29impl<T> IntoEthApiError for T
30where EthApiError: From<T>
31{
32 fn into_eth_err<E>(self) -> E
33 where E: FromEthApiError {
34 E::from_eth_err(self)
35 }
36}
37
38pub trait AsEthApiError {
40 fn as_err(&self) -> Option<&EthApiError>;
43
44 fn is_gas_too_high(&self) -> bool {
47 if let Some(err) = self.as_err() {
48 return err.is_gas_too_high();
49 }
50
51 false
52 }
53
54 fn is_gas_too_low(&self) -> bool {
57 if let Some(err) = self.as_err() {
58 return err.is_gas_too_low();
59 }
60
61 false
62 }
63}
64
65impl AsEthApiError for EthApiError {
66 fn as_err(&self) -> Option<&EthApiError> { Some(self) }
67}