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::MempoolSubmissionError`.
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
7pub enum AddTransactionError {
8    /// Internal server error (code 0)
9    #[error("internal server error")]
10    Internal,
11    /// Transaction has expired
12    #[error("transaction expired")]
13    Expired,
14    /// Transaction conflicts with the current state
15    #[error("transaction conflicts with current state: {message}")]
16    StateConflict { message: String },
17    /// Mempool is at capacity
18    #[error("the mempool is at capacity")]
19    CapacityExceeded,
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 AddTransactionError {
27    pub fn from_code(code: u8, message: &str) -> Self {
28        match code {
29            0 => Self::Internal,
30            1 => Self::Expired,
31            2 => Self::StateConflict { message: String::from(message) },
32            3 => Self::CapacityExceeded,
33            _ => Self::Unknown { code, message: String::from(message) },
34        }
35    }
36}