ic_web3/contract/
error.rs

1//! Contract call/query error.
2
3use crate::error::Error as ApiError;
4use derive_more::{Display, From};
5use ethabi::Error as EthError;
6
7/// Contract error.
8#[derive(Debug, Display, From)]
9pub enum Error {
10    /// invalid output type requested by the caller
11    #[display(fmt = "Invalid output type: {}", _0)]
12    InvalidOutputType(String),
13    /// eth abi error
14    #[display(fmt = "Abi error: {}", _0)]
15    Abi(EthError),
16    /// Rpc error
17    #[display(fmt = "Api error: {}", _0)]
18    Api(ApiError),
19    /// An error during deployment.
20    #[display(fmt = "Deployment error: {}", _0)]
21    Deployment(crate::contract::deploy::Error),
22    /// Contract does not support this interface.
23    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::Deployment(ref e) => Some(e),
33            Error::InterfaceUnsupported => None,
34        }
35    }
36}
37
38pub mod deploy {
39    use crate::{error::Error as ApiError, types::H256};
40    use derive_more::{Display, From};
41
42    /// Contract deployment error.
43    #[derive(Debug, Display, From)]
44    pub enum Error {
45        /// eth abi error
46        #[display(fmt = "Abi error: {}", _0)]
47        Abi(ethabi::Error),
48        /// Rpc error
49        #[display(fmt = "Api error: {}", _0)]
50        Api(ApiError),
51        /// Contract deployment failed
52        #[display(fmt = "Failure during deployment.Tx hash: {:?}", _0)]
53        ContractDeploymentFailure(H256),
54    }
55
56    impl std::error::Error for Error {
57        fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
58            match *self {
59                Error::Abi(ref e) => Some(e),
60                Error::Api(ref e) => Some(e),
61                Error::ContractDeploymentFailure(_) => None,
62            }
63        }
64    }
65}