1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use webb::{
    evm::ethers,
    substrate::{dkg_runtime, protocol_substrate_runtime, subxt},
};

/// An enum of all possible errors that could be encountered during the execution of the Webb
/// Relayer.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// An Io error occurred.
    #[error(transparent)]
    Io(#[from] std::io::Error),
    /// JSON Error occurred.
    #[error(transparent)]
    Json(#[from] serde_json::Error),
    /// Config loading error.
    #[error(transparent)]
    Config(#[from] config::ConfigError),
    /// Error while iterating over a glob pattern.
    #[error(transparent)]
    GlobPattern(#[from] glob::PatternError),
    /// Error from Glob Iterator.
    #[error(transparent)]
    Glob(#[from] glob::GlobError),
    /// Error while parsing a URL.
    #[error(transparent)]
    Url(#[from] url::ParseError),
    /// Error in the underlying Http/Ws server.
    #[error(transparent)]
    Warp(#[from] warp::Error),
    /// Elliptic Curve error.
    #[error(transparent)]
    EllipticCurve(#[from] ethers::core::k256::elliptic_curve::Error),
    /// Secp256k1 error occurred.
    #[error(transparent)]
    Secp256k1(#[from] libsecp256k1::Error),
    /// Basic error for the substrate runtime.
    #[error(transparent)]
    SubxtBasicError(#[from] subxt::BasicError),
    /// DKG Runtime error.
    #[error(transparent)]
    DKGError(
        #[from]
        subxt::GenericError<
            subxt::RuntimeError<dkg_runtime::api::DispatchError>,
        >,
    ),
    /// Protocol Substrate Runtime error.
    #[error(transparent)]
    ProtocolSubstrateError(
        #[from]
        subxt::GenericError<
            subxt::RuntimeError<protocol_substrate_runtime::api::DispatchError>,
        >,
    ),
    /// Runtime metadata error.
    #[error(transparent)]
    Metadata(#[from] subxt::MetadataError),
    /// Error in Http Provider (ethers client).
    #[error(transparent)]
    EthersProvider(#[from] ethers::providers::ProviderError),
    /// Smart contract error.
    #[error(transparent)]
    EthersContract(
        #[from]
        ethers::contract::ContractError<
            ethers::providers::Provider<ethers::providers::Http>,
        >,
    ),
    /// SCALE Codec error.
    #[error(transparent)]
    ScaleCodec(#[from] webb::substrate::scale::Error),
    /// Sled database error.
    #[error(transparent)]
    Sled(#[from] sled::Error),
    /// Sled transaction error.
    #[error(transparent)]
    SledTransaction(
        #[from] sled::transaction::TransactionError<std::io::Error>,
    ),
    /// Generic error.
    #[error("{}", _0)]
    Generic(&'static str),
    /// Bridge not configured or not enabled.
    #[error("Bridge not found for: {:?}", typed_chain_id)]
    BridgeNotFound {
        /// The chain id of the bridge.
        typed_chain_id: webb_proposals::TypedChainId,
    },
    /// Error while parsing the config files.
    #[error("Config parse error: {}", _0)]
    ParseConfig(#[from] serde_path_to_error::Error<config::ConfigError>),
    /// EVM Chain not found.
    #[error("Chain Not Found: {}", chain_id)]
    ChainNotFound {
        /// The chain id of the chain.
        chain_id: String,
    },
    /// Substrate node not found.
    #[error("Node Not Found: {}", chain_id)]
    NodeNotFound {
        /// The chain id of the node.
        chain_id: String,
    },
    /// Missing Secrets in the config, either Private key, SURI, ...etc.
    #[error("Missing required private-key or SURI in the config")]
    MissingSecrets,
    /// Failed to send the response to the client.
    #[error("Failed to send response to the client")]
    FailedToSendResponse,
    /// a backgorund task failed and force restarted.
    #[error("Task Force Restarted from an error")]
    ForceRestart,
    /// a backgorund task failed and stopped Apnormally.
    #[error("Task Stopped Apnormally")]
    TaskStoppedApnormally,
}

/// A type alias for the result for webb relayer, that uses the `Error` enum.
pub type Result<T> = std::result::Result<T, Error>;