Skip to main content

miden_client/rpc/errors/node/
account.rs

1use alloc::string::String;
2
3use thiserror::Error;
4
5// GET ACCOUNT ERROR
6// ================================================================================================
7
8// Error codes match `miden-node/crates/store/src/errors.rs::GetAccountError`.
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10pub enum GetAccountError {
11    /// Internal server error (code 0)
12    #[error("internal server error")]
13    Internal,
14    /// Failed to deserialize data
15    #[error("deserialization failed")]
16    DeserializationFailed,
17    /// Account was not found at the requested block
18    #[error("account not found")]
19    AccountNotFound,
20    /// Account is not public
21    #[error("account is not public")]
22    AccountNotPublic,
23    /// Requested block number is unknown
24    #[error("unknown block")]
25    UnknownBlock,
26    /// Requested block has been pruned
27    #[error("block pruned")]
28    BlockPruned,
29    /// Error code not recognized by this client version. This can happen if the node
30    /// is newer than the client and has added new error variants.
31    #[error("unknown error code {code}: {message}")]
32    Unknown { code: u8, message: String },
33}
34
35impl GetAccountError {
36    pub fn from_code(code: u8, message: &str) -> Self {
37        match code {
38            0 => Self::Internal,
39            1 => Self::DeserializationFailed,
40            2 => Self::AccountNotFound,
41            3 => Self::AccountNotPublic,
42            4 => Self::UnknownBlock,
43            5 => Self::BlockPruned,
44            _ => Self::Unknown { code, message: String::from(message) },
45        }
46    }
47}