Skip to main content

miden_client/rpc/errors/node/
sync.rs

1use alloc::string::String;
2
3use thiserror::Error;
4
5// NOTE SYNC ERROR
6// ================================================================================================
7
8// Error codes match `miden-node/crates/store/src/errors.rs::NoteSyncError`.
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10pub enum NoteSyncError {
11    /// Internal server error (code 0)
12    #[error("internal server error")]
13    Internal,
14    /// Invalid block range specified
15    #[error("invalid block range")]
16    InvalidBlockRange,
17    /// Failed to deserialize data
18    #[error("deserialization failed")]
19    DeserializationFailed,
20    /// Error code not recognized by this client version. This can happen if the node
21    /// is newer than the client and has added new error variants.
22    #[error("unknown error code {code}: {message}")]
23    Unknown { code: u8, message: String },
24}
25
26impl NoteSyncError {
27    pub fn from_code(code: u8, message: &str) -> Self {
28        match code {
29            0 => Self::Internal,
30            1 => Self::InvalidBlockRange,
31            2 => Self::DeserializationFailed,
32            _ => Self::Unknown { code, message: String::from(message) },
33        }
34    }
35}
36
37// SYNC NULLIFIERS ERROR
38// ================================================================================================
39
40// Error codes match `miden-node/crates/store/src/errors.rs::SyncNullifiersError`.
41#[derive(Debug, Clone, PartialEq, Eq, Error)]
42pub enum SyncNullifiersError {
43    /// Internal server error (code 0)
44    #[error("internal server error")]
45    Internal,
46    /// Invalid block range specified
47    #[error("invalid block range")]
48    InvalidBlockRange,
49    /// Invalid prefix length
50    #[error("invalid prefix length")]
51    InvalidPrefixLength,
52    /// Failed to deserialize data
53    #[error("deserialization failed")]
54    DeserializationFailed,
55    /// Error code not recognized by this client version. This can happen if the node
56    /// is newer than the client and has added new error variants.
57    #[error("unknown error code {code}: {message}")]
58    Unknown { code: u8, message: String },
59}
60
61impl SyncNullifiersError {
62    pub fn from_code(code: u8, message: &str) -> Self {
63        match code {
64            0 => Self::Internal,
65            1 => Self::InvalidBlockRange,
66            2 => Self::InvalidPrefixLength,
67            3 => Self::DeserializationFailed,
68            _ => Self::Unknown { code, message: String::from(message) },
69        }
70    }
71}
72
73// SYNC ACCOUNT VAULT ERROR
74// ================================================================================================
75
76// Error codes match `miden-node/crates/store/src/errors.rs::SyncAccountVaultError`.
77#[derive(Debug, Clone, PartialEq, Eq, Error)]
78pub enum SyncAccountVaultError {
79    /// Internal server error (code 0)
80    #[error("internal server error")]
81    Internal,
82    /// Invalid block range specified
83    #[error("invalid block range")]
84    InvalidBlockRange,
85    /// Failed to deserialize data
86    #[error("deserialization failed")]
87    DeserializationFailed,
88    /// Account is not public
89    #[error("account is not public")]
90    AccountNotPublic,
91    /// Error code not recognized by this client version. This can happen if the node
92    /// is newer than the client and has added new error variants.
93    #[error("unknown error code {code}: {message}")]
94    Unknown { code: u8, message: String },
95}
96
97impl SyncAccountVaultError {
98    pub fn from_code(code: u8, message: &str) -> Self {
99        match code {
100            0 => Self::Internal,
101            1 => Self::InvalidBlockRange,
102            2 => Self::DeserializationFailed,
103            3 => Self::AccountNotPublic,
104            _ => Self::Unknown { code, message: String::from(message) },
105        }
106    }
107}
108
109// SYNC ACCOUNT STORAGE MAPS ERROR
110// ================================================================================================
111
112// Error codes match `miden-node/crates/store/src/errors.rs::SyncAccountStorageMapsError`.
113#[derive(Debug, Clone, PartialEq, Eq, Error)]
114pub enum SyncAccountStorageMapsError {
115    /// Internal server error (code 0)
116    #[error("internal server error")]
117    Internal,
118    /// Invalid block range specified
119    #[error("invalid block range")]
120    InvalidBlockRange,
121    /// Failed to deserialize data
122    #[error("deserialization failed")]
123    DeserializationFailed,
124    /// Account was not found
125    #[error("account not found")]
126    AccountNotFound,
127    /// Account is not public
128    #[error("account is not public")]
129    AccountNotPublic,
130    /// Error code not recognized by this client version. This can happen if the node
131    /// is newer than the client and has added new error variants.
132    #[error("unknown error code {code}: {message}")]
133    Unknown { code: u8, message: String },
134}
135
136impl SyncAccountStorageMapsError {
137    pub fn from_code(code: u8, message: &str) -> Self {
138        match code {
139            0 => Self::Internal,
140            1 => Self::InvalidBlockRange,
141            2 => Self::DeserializationFailed,
142            3 => Self::AccountNotFound,
143            4 => Self::AccountNotPublic,
144            _ => Self::Unknown { code, message: String::from(message) },
145        }
146    }
147}
148
149// SYNC TRANSACTIONS ERROR
150// ================================================================================================
151
152// Error codes match `miden-node/crates/store/src/errors.rs::SyncTransactionsError`.
153#[derive(Debug, Clone, PartialEq, Eq, Error)]
154pub enum SyncTransactionsError {
155    /// Internal server error (code 0)
156    #[error("internal server error")]
157    Internal,
158    /// Invalid block range specified
159    #[error("invalid block range")]
160    InvalidBlockRange,
161    /// Failed to deserialize data
162    #[error("deserialization failed")]
163    DeserializationFailed,
164    /// Account was not found
165    #[error("account not found")]
166    AccountNotFound,
167    /// Witness error
168    #[error("witness error")]
169    WitnessError,
170    /// Error code not recognized by this client version. This can happen if the node
171    /// is newer than the client and has added new error variants.
172    #[error("unknown error code {code}: {message}")]
173    Unknown { code: u8, message: String },
174}
175
176impl SyncTransactionsError {
177    pub fn from_code(code: u8, message: &str) -> Self {
178        match code {
179            0 => Self::Internal,
180            1 => Self::InvalidBlockRange,
181            2 => Self::DeserializationFailed,
182            3 => Self::AccountNotFound,
183            4 => Self::WitnessError,
184            _ => Self::Unknown { code, message: String::from(message) },
185        }
186    }
187}