111 lines
3.1 KiB
Rust
111 lines
3.1 KiB
Rust
/// ACC-1644 错误类型定义
|
|
|
|
use std::fmt;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Acc1644Error {
|
|
/// 未授权操作
|
|
Unauthorized {
|
|
operator: String,
|
|
required_role: String,
|
|
},
|
|
|
|
/// 无效的控制器角色
|
|
InvalidControllerRole {
|
|
role: u8,
|
|
},
|
|
|
|
/// 资产已冻结
|
|
AssetFrozen {
|
|
partition_id: String,
|
|
},
|
|
|
|
/// 资产未冻结
|
|
AssetNotFrozen {
|
|
partition_id: String,
|
|
},
|
|
|
|
/// 无效的法律依据
|
|
InvalidLegalBasis {
|
|
legal_basis: String,
|
|
},
|
|
|
|
/// 控制器不存在
|
|
NoController,
|
|
|
|
/// 接管已过期
|
|
TakeoverExpired {
|
|
controller: String,
|
|
},
|
|
|
|
/// 接管未过期
|
|
TakeoverNotExpired {
|
|
remaining_seconds: u64,
|
|
},
|
|
|
|
/// 宪法收据无效
|
|
InvalidConstitutionalReceipt {
|
|
receipt_hash: String,
|
|
},
|
|
|
|
/// 余额不足
|
|
InsufficientBalance {
|
|
account: String,
|
|
available: u128,
|
|
required: u128,
|
|
},
|
|
|
|
/// 分区不存在
|
|
PartitionNotFound {
|
|
partition_id: String,
|
|
},
|
|
}
|
|
|
|
impl fmt::Display for Acc1644Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Acc1644Error::Unauthorized { operator, required_role } => {
|
|
write!(f, "Unauthorized: {} requires role {}", operator, required_role)
|
|
}
|
|
Acc1644Error::InvalidControllerRole { role } => {
|
|
write!(f, "Invalid controller role: {}", role)
|
|
}
|
|
Acc1644Error::AssetFrozen { partition_id } => {
|
|
write!(f, "Asset is frozen: {}", partition_id)
|
|
}
|
|
Acc1644Error::AssetNotFrozen { partition_id } => {
|
|
write!(f, "Asset is not frozen: {}", partition_id)
|
|
}
|
|
Acc1644Error::InvalidLegalBasis { legal_basis } => {
|
|
write!(f, "Invalid legal basis: {}", legal_basis)
|
|
}
|
|
Acc1644Error::NoController => {
|
|
write!(f, "No controller assigned")
|
|
}
|
|
Acc1644Error::TakeoverExpired { controller } => {
|
|
write!(f, "Takeover expired for controller: {}", controller)
|
|
}
|
|
Acc1644Error::TakeoverNotExpired { remaining_seconds } => {
|
|
write!(f, "Takeover not expired, {} seconds remaining", remaining_seconds)
|
|
}
|
|
Acc1644Error::InvalidConstitutionalReceipt { receipt_hash } => {
|
|
write!(f, "Invalid constitutional receipt: {}", receipt_hash)
|
|
}
|
|
Acc1644Error::InsufficientBalance { account, available, required } => {
|
|
write!(
|
|
f,
|
|
"Insufficient balance for {}: available {}, required {}",
|
|
account, available, required
|
|
)
|
|
}
|
|
Acc1644Error::PartitionNotFound { partition_id } => {
|
|
write!(f, "Partition not found: {}", partition_id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for Acc1644Error {}
|
|
|
|
pub type Result<T> = std::result::Result<T, Acc1644Error>;
|