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    /// Transaction does not contain a canonical fee output note
21    #[error("transaction does not contain a canonical fee output note")]
22    MissingFee,
23    /// Transaction consumes fee notes that are not committed yet
24    #[error("transaction consumes in-flight fee notes")]
25    ConsumesInflightFeeNotes,
26    /// Transaction fee output note contains an asset that is not the native asset
27    #[error("transaction fee output note must use only the native asset")]
28    InvalidFeeAsset,
29    /// Batch proof ID does not match the batch ID
30    #[error("batch proof ID does not match the batch ID")]
31    BatchIdMismatch,
32    /// Transaction authentication failed against the current state
33    #[error("failed to authenticate transaction: {message}")]
34    AuthenticationFailed { message: String },
35    /// Error code not recognized by this client version. This can happen if the node is newer than
36    /// 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::Expired,
46            2 => Self::StateConflict { message: String::from(message) },
47            3 => Self::CapacityExceeded,
48            4 => Self::MissingFee,
49            5 => Self::ConsumesInflightFeeNotes,
50            6 => Self::InvalidFeeAsset,
51            7 => Self::BatchIdMismatch,
52            8 => Self::AuthenticationFailed { message: String::from(message) },
53            _ => Self::Unknown { code, message: String::from(message) },
54        }
55    }
56}