use alloc::string::String;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum AddTransactionError {
#[error("internal server error")]
Internal,
#[error("input notes already consumed")]
InputNotesAlreadyConsumed,
#[error("unauthenticated notes not found")]
UnauthenticatedNotesNotFound,
#[error("output notes already exist")]
OutputNotesAlreadyExist,
#[error("incorrect account initial commitment")]
IncorrectAccountInitialCommitment,
#[error("invalid transaction proof")]
InvalidTransactionProof,
#[error("failed to deserialize transaction")]
TransactionDeserializationFailed,
#[error("transaction expired")]
Expired,
#[error("block producer capacity exceeded")]
CapacityExceeded,
#[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::InputNotesAlreadyConsumed,
2 => Self::UnauthenticatedNotesNotFound,
3 => Self::OutputNotesAlreadyExist,
4 => Self::IncorrectAccountInitialCommitment,
5 => Self::InvalidTransactionProof,
6 => Self::TransactionDeserializationFailed,
7 => Self::Expired,
8 => Self::CapacityExceeded,
_ => Self::Unknown { code, message: String::from(message) },
}
}
}