//! ACC-1410 Error Types use std::fmt; #[derive(Debug, Clone)] pub enum Acc1410Error { PartitionNotFound(String), InsufficientBalance { account: String, required: u64, available: u64 }, UnauthorizedOperator { operator: String, account: String }, PartitionClosed(String), FundsLocked { account: String, unlock_time: u64 }, InvalidReceiver(String), InvalidSender(String), InvalidTransfer(String), TransfersHalted, InvalidGNACS(String), PartitionAlreadyExists(String), NotFound(String), InvalidAmount(String), } impl fmt::Display for Acc1410Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::PartitionNotFound(id) => write!(f, "Partition not found: {}", id), Self::InsufficientBalance { account, required, available } => { write!(f, "Insufficient balance for {}: required {}, available {}", account, required, available) } Self::UnauthorizedOperator { operator, account } => { write!(f, "Operator {} is not authorized for account {}", operator, account) } Self::PartitionClosed(id) => write!(f, "Partition {} is closed", id), Self::FundsLocked { account, unlock_time } => { write!(f, "Funds locked for {} until {}", account, unlock_time) } Self::InvalidReceiver(addr) => write!(f, "Invalid receiver: {}", addr), Self::InvalidSender(addr) => write!(f, "Invalid sender: {}", addr), Self::InvalidTransfer(msg) => write!(f, "Invalid transfer: {}", msg), Self::TransfersHalted => write!(f, "Transfers are currently halted"), Self::InvalidGNACS(msg) => write!(f, "Invalid GNACS: {}", msg), Self::PartitionAlreadyExists(id) => write!(f, "Partition already exists: {}", id), Self::NotFound(msg) => write!(f, "Not found: {}", msg), Self::InvalidAmount(msg) => write!(f, "Invalid amount: {}", msg), } } } impl std::error::Error for Acc1410Error {} impl From for Acc1410Error { fn from(msg: String) -> Self { Self::InvalidGNACS(msg) } } impl From<&str> for Acc1410Error { fn from(msg: &str) -> Self { Self::InvalidGNACS(msg.to_string()) } } pub type Result = std::result::Result;