Skip to main content

miden_client/rpc/errors/node/
transaction.rs

1use alloc::string::String;
2
3use thiserror::Error;
4
5// Error codes match `miden-node/crates/block-producer/src/errors.rs::AddTransactionError`.
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
7pub enum AddTransactionError {
8    /// Internal server error (code 0)
9    #[error("internal server error")]
10    Internal,
11    /// One or more input notes have already been consumed
12    #[error("input notes already consumed")]
13    InputNotesAlreadyConsumed,
14    /// Unauthenticated notes were not found in the store
15    #[error("unauthenticated notes not found")]
16    UnauthenticatedNotesNotFound,
17    /// One or more output notes already exist in the store
18    #[error("output notes already exist")]
19    OutputNotesAlreadyExist,
20    /// Account's initial commitment doesn't match the current state
21    #[error("incorrect account initial commitment")]
22    IncorrectAccountInitialCommitment,
23    /// Transaction proof verification failed
24    #[error("invalid transaction proof")]
25    InvalidTransactionProof,
26    /// Failed to deserialize the transaction
27    #[error("failed to deserialize transaction")]
28    TransactionDeserializationFailed,
29    /// Transaction has expired
30    #[error("transaction expired")]
31    Expired,
32    /// Block producer capacity exceeded
33    #[error("block producer capacity exceeded")]
34    CapacityExceeded,
35    /// Error code not recognized by this client version. This can happen if the node
36    /// is newer than the client and has added new error variants.
37    #[error("unknown error code {code}: {message}")]
38    Unknown { code: u8, message: String },
39}
40
41impl AddTransactionError {
42    pub fn from_code(code: u8, message: &str) -> Self {
43        match code {
44            0 => Self::Internal,
45            1 => Self::InputNotesAlreadyConsumed,
46            2 => Self::UnauthenticatedNotesNotFound,
47            3 => Self::OutputNotesAlreadyExist,
48            4 => Self::IncorrectAccountInitialCommitment,
49            5 => Self::InvalidTransactionProof,
50            6 => Self::TransactionDeserializationFailed,
51            7 => Self::Expired,
52            8 => Self::CapacityExceeded,
53            _ => Self::Unknown { code, message: String::from(message) },
54        }
55    }
56}