mwc_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}
23
24impl std::error::Error for Error {
25    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26        match *self {
27            Error::InvalidOutputType(_) => None,
28            Error::Abi(ref e) => Some(e),
29            Error::Api(ref e) => Some(e),
30            Error::Deployment(ref e) => Some(e),
31        }
32    }
33}
34
35pub mod deploy {
36    use crate::{error::Error as ApiError, types::H256};
37    use derive_more::{Display, From};
38
39    /// Contract deployment error.
40    #[derive(Debug, Display, From)]
41    pub enum Error {
42        /// eth abi error
43        #[display(fmt = "Abi error: {}", _0)]
44        Abi(ethabi::Error),
45        /// Rpc error
46        #[display(fmt = "Api error: {}", _0)]
47        Api(ApiError),
48        /// Contract deployment failed
49        #[display(fmt = "Failure during deployment.Tx hash: {:?}", _0)]
50        ContractDeploymentFailure(H256),
51    }
52
53    impl std::error::Error for Error {
54        fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
55            match *self {
56                Error::Abi(ref e) => Some(e),
57                Error::Api(ref e) => Some(e),
58                Error::ContractDeploymentFailure(_) => None,
59            }
60        }
61    }
62}