Skip to main content

miden_client/rpc/errors/node/
note.rs

1use alloc::string::String;
2
3use thiserror::Error;
4
5// GET NOTES BY ID ERROR
6// ================================================================================================
7
8// Error codes match `miden-node/crates/store/src/errors.rs::GetNotesByIdError`.
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10pub enum GetNotesByIdError {
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    /// Note was not found
18    #[error("note not found")]
19    NoteNotFound,
20    /// Note is not public
21    #[error("note is not public")]
22    NoteNotPublic,
23    /// Error code not recognized by this client version. This can happen if the node
24    /// is newer than the client and has added new error variants.
25    #[error("unknown error code {code}: {message}")]
26    Unknown { code: u8, message: String },
27}
28
29impl GetNotesByIdError {
30    pub fn from_code(code: u8, message: &str) -> Self {
31        match code {
32            0 => Self::Internal,
33            1 => Self::DeserializationFailed,
34            2 => Self::NoteNotFound,
35            3 => Self::NoteNotPublic,
36            _ => Self::Unknown { code, message: String::from(message) },
37        }
38    }
39}
40
41// GET NOTE SCRIPT BY ROOT ERROR
42// ================================================================================================
43
44// Error codes match `miden-node/crates/store/src/errors.rs::GetNoteScriptByRootError`.
45#[derive(Debug, Clone, PartialEq, Eq, Error)]
46pub enum GetNoteScriptByRootError {
47    /// Internal server error (code 0)
48    #[error("internal server error")]
49    Internal,
50    /// Failed to deserialize data
51    #[error("deserialization failed")]
52    DeserializationFailed,
53    /// Script was not found
54    #[error("script not found")]
55    ScriptNotFound,
56    /// Error code not recognized by this client version. This can happen if the node
57    /// is newer than the client and has added new error variants.
58    #[error("unknown error code {code}: {message}")]
59    Unknown { code: u8, message: String },
60}
61
62impl GetNoteScriptByRootError {
63    pub fn from_code(code: u8, message: &str) -> Self {
64        match code {
65            0 => Self::Internal,
66            1 => Self::DeserializationFailed,
67            2 => Self::ScriptNotFound,
68            _ => Self::Unknown { code, message: String::from(message) },
69        }
70    }
71}
72
73// CHECK NULLIFIERS ERROR
74// ================================================================================================
75
76// Error codes match `miden-node/crates/store/src/errors.rs::CheckNullifiersError`.
77#[derive(Debug, Clone, PartialEq, Eq, Error)]
78pub enum CheckNullifiersError {
79    /// Internal server error (code 0)
80    #[error("internal server error")]
81    Internal,
82    /// Failed to deserialize data
83    #[error("deserialization failed")]
84    DeserializationFailed,
85    /// Error code not recognized by this client version. This can happen if the node
86    /// is newer than the client and has added new error variants.
87    #[error("unknown error code {code}: {message}")]
88    Unknown { code: u8, message: String },
89}
90
91impl CheckNullifiersError {
92    pub fn from_code(code: u8, message: &str) -> Self {
93        match code {
94            0 => Self::Internal,
95            1 => Self::DeserializationFailed,
96            _ => Self::Unknown { code, message: String::from(message) },
97        }
98    }
99}