blueprint_client_tangle/
error.rs

1use blueprint_std::io;
2use blueprint_std::string::{String, ToString};
3use tangle_subxt::subxt;
4use tangle_subxt::subxt_core::utils::AccountId32;
5use thiserror::Error;
6
7#[derive(Debug, Error)]
8pub enum Error {
9    #[error("Tangle error: {0}")]
10    Tangle(TangleDispatchError),
11    #[error("Not a Tangle instance")]
12    NotTangle,
13
14    #[error("Missing ECDSA key for operator: {0}")]
15    MissingEcdsa(AccountId32),
16    #[error("Party not found in operator list")]
17    PartyNotFound,
18
19    #[error("{0}")]
20    Other(String),
21
22    #[error(transparent)]
23    Keystore(#[from] blueprint_keystore::Error),
24    #[error(transparent)]
25    Core(#[from] blueprint_client_core::error::Error),
26    #[error("IO error: {0}")]
27    Io(#[from] io::Error),
28    #[error("Subxt error: {0}")]
29    Subxt(#[from] subxt::Error),
30}
31
32impl From<Error> for blueprint_client_core::error::Error {
33    fn from(value: Error) -> Self {
34        blueprint_client_core::error::Error::Tangle(value.to_string())
35    }
36}
37
38pub type Result<T> = blueprint_std::result::Result<T, Error>;
39
40#[derive(Debug)]
41pub struct TangleDispatchError(
42    pub tangle_subxt::tangle_testnet_runtime::api::runtime_types::sp_runtime::DispatchError,
43);
44
45impl From<tangle_subxt::tangle_testnet_runtime::api::runtime_types::sp_runtime::DispatchError>
46    for TangleDispatchError
47{
48    fn from(
49        error: tangle_subxt::tangle_testnet_runtime::api::runtime_types::sp_runtime::DispatchError,
50    ) -> Self {
51        TangleDispatchError(error)
52    }
53}
54
55impl From<TangleDispatchError> for Error {
56    fn from(error: TangleDispatchError) -> Self {
57        Error::Tangle(error)
58    }
59}
60
61impl blueprint_std::fmt::Display for TangleDispatchError {
62    fn fmt(&self, f: &mut blueprint_std::fmt::Formatter<'_>) -> blueprint_std::fmt::Result {
63        write!(f, "{:?}", self.0)
64    }
65}