ic_web3_rs/contract/
error.rs1use crate::error::Error as ApiError;
4use derive_more::{Display, From};
5use ethabi::Error as EthError;
6
7#[derive(Debug, Display, From)]
9pub enum Error {
10 #[display(fmt = "Invalid output type: {}", _0)]
12 InvalidOutputType(String),
13 #[display(fmt = "Abi error: {}", _0)]
15 Abi(EthError),
16 #[display(fmt = "Api error: {}", _0)]
18 Api(ApiError),
19 InterfaceUnsupported,
24}
25
26impl std::error::Error for Error {
27 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28 match *self {
29 Error::InvalidOutputType(_) => None,
30 Error::Abi(ref e) => Some(e),
31 Error::Api(ref e) => Some(e),
32 Error::InterfaceUnsupported => None,
34 }
35 }
36}
37
38impl From<Error> for crate::error::Error {
39 fn from(e: Error) -> Self {
40 match e {
41 Error::InvalidOutputType(s) => crate::error::Error::InvalidResponse(s),
42 Error::Abi(eth_error) => crate::error::Error::Decoder(format!("{}", eth_error)),
43 Error::Api(api_error) => api_error,
44 Error::InterfaceUnsupported => crate::error::Error::Internal,
45 }
46 }
47}
48
49pub mod deploy {
50 use crate::{error::Error as ApiError, types::H256};
51 use derive_more::{Display, From};
52
53 #[derive(Debug, Display, From)]
55 pub enum Error {
56 #[display(fmt = "Abi error: {}", _0)]
58 Abi(ethabi::Error),
59 #[display(fmt = "Api error: {}", _0)]
61 Api(ApiError),
62 #[display(fmt = "Failure during deployment.Tx hash: {:?}", _0)]
64 ContractDeploymentFailure(H256),
65 }
66
67 impl std::error::Error for Error {
68 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
69 match *self {
70 Error::Abi(ref e) => Some(e),
71 Error::Api(ref e) => Some(e),
72 Error::ContractDeploymentFailure(_) => None,
73 }
74 }
75 }
76}