//! ACC-1594 Error Types use std::fmt; #[derive(Debug, Clone)] pub enum Acc1594Error { /// 资产不可发行 NotIssuable(String), /// 超过发行上限 ExceedsIssuanceLimit { current: u64, limit: u64 }, /// 赎回策略不允许 RedemptionNotAllowed(String), /// 未达到最低持有期 MinHoldingPeriodNotMet { required_months: u8, held_months: u8 }, /// 余额不足 InsufficientBalance { account: String, required: u64, available: u64 }, /// 无可领取分红 NoClaimableDividend { account: String, partition: String }, /// 分红周期无效 InvalidDividendPeriod(u64), /// 宪法收据无效 InvalidConstitutionalReceipt(String), /// 未授权操作 Unauthorized { operator: String, required_role: String }, /// 分区不存在 PartitionNotFound(String), /// GNACS解析错误 GNACSParseError(String), /// ACC-1410错误 Acc1410Error(String), } impl fmt::Display for Acc1594Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::NotIssuable(msg) => write!(f, "Asset not issuable: {}", msg), Self::ExceedsIssuanceLimit { current, limit } => { write!(f, "Exceeds issuance limit: current {}, limit {}", current, limit) } Self::RedemptionNotAllowed(msg) => write!(f, "Redemption not allowed: {}", msg), Self::MinHoldingPeriodNotMet { required_months, held_months } => { write!(f, "Min holding period not met: required {} months, held {} months", required_months, held_months) } Self::InsufficientBalance { account, required, available } => { write!(f, "Insufficient balance for {}: required {}, available {}", account, required, available) } Self::NoClaimableDividend { account, partition } => { write!(f, "No claimable dividend for {} in partition {}", account, partition) } Self::InvalidDividendPeriod(period) => { write!(f, "Invalid dividend period: {}", period) } Self::InvalidConstitutionalReceipt(msg) => { write!(f, "Invalid constitutional receipt: {}", msg) } Self::Unauthorized { operator, required_role } => { write!(f, "Unauthorized: {} requires role {}", operator, required_role) } Self::PartitionNotFound(id) => write!(f, "Partition not found: {}", id), Self::GNACSParseError(msg) => write!(f, "GNACS parse error: {}", msg), Self::Acc1410Error(msg) => write!(f, "ACC-1410 error: {}", msg), } } } impl std::error::Error for Acc1594Error {} impl From for Acc1594Error { fn from(err: nac_acc_1410::Acc1410Error) -> Self { Self::Acc1410Error(err.to_string()) } } pub type Result = std::result::Result;