miden_client/rpc/errors/node/
account.rs1use alloc::string::String;
2
3use thiserror::Error;
4
5use crate::rpc::errors::GrpcError;
6
7#[derive(Debug, Clone, PartialEq, Eq, Error)]
12pub enum GetAccountError {
13 #[error("internal server error")]
15 Internal,
16 #[error("deserialization failed")]
18 DeserializationFailed,
19 #[error("account not found")]
21 AccountNotFound,
22 #[error("account is not public")]
24 AccountNotPublic,
25 #[error("unknown block")]
27 UnknownBlock,
28 #[error("block pruned")]
30 BlockPruned,
31 #[error("storage slot not found")]
33 StorageSlotNotFound,
34 #[error("storage slot is not a map")]
36 StorageSlotNotMap,
37 #[error("unknown error code {code}: {message}")]
40 Unknown { code: u8, message: String },
41}
42
43impl GetAccountError {
44 pub fn from_code(code: u8, message: &str) -> Self {
45 match code {
46 0 => Self::Internal,
47 1 => Self::DeserializationFailed,
48 2 => Self::AccountNotFound,
49 3 => Self::AccountNotPublic,
50 4 => Self::UnknownBlock,
51 5 => Self::BlockPruned,
52 6 => Self::StorageSlotNotFound,
53 7 => Self::StorageSlotNotMap,
54 _ => Self::Unknown { code, message: String::from(message) },
55 }
56 }
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Error)]
64pub enum RegisterAccountError {
65 #[error("invitation code does not exist")]
66 InvitationNotFound,
67 #[error("the invitation code or the account is already registered")]
68 AlreadyRegistered,
69 #[error("invalid registration request: {0}")]
72 InvalidRequest(String),
73}
74
75impl RegisterAccountError {
76 pub fn from_grpc_error(error_kind: &GrpcError, message: &str) -> Option<Self> {
81 match error_kind {
82 GrpcError::NotFound => Some(Self::InvitationNotFound),
83 GrpcError::AlreadyExists => Some(Self::AlreadyRegistered),
84 GrpcError::InvalidArgument => Some(Self::InvalidRequest(String::from(message))),
85 _ => None,
86 }
87 }
88}