use alloc::string::String;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum AddTransactionError {
#[error("internal server error")]
Internal,
#[error("transaction expired")]
Expired,
#[error("transaction conflicts with current state: {message}")]
StateConflict { message: String },
#[error("the mempool is at capacity")]
CapacityExceeded,
#[error("transaction does not contain a canonical fee output note")]
MissingFee,
#[error("transaction consumes in-flight fee notes")]
ConsumesInflightFeeNotes,
#[error("transaction fee output note must use only the native asset")]
InvalidFeeAsset,
#[error("batch proof ID does not match the batch ID")]
BatchIdMismatch,
#[error("failed to authenticate transaction: {message}")]
AuthenticationFailed { message: String },
#[error("unknown error code {code}: {message}")]
Unknown { code: u8, message: String },
}
impl AddTransactionError {
pub fn from_code(code: u8, message: &str) -> Self {
match code {
0 => Self::Internal,
1 => Self::Expired,
2 => Self::StateConflict { message: String::from(message) },
3 => Self::CapacityExceeded,
4 => Self::MissingFee,
5 => Self::ConsumesInflightFeeNotes,
6 => Self::InvalidFeeAsset,
7 => Self::BatchIdMismatch,
8 => Self::AuthenticationFailed { message: String::from(message) },
_ => Self::Unknown { code, message: String::from(message) },
}
}
}