use pendzl::math::errors::MathError;
use pendzl::traits::String;
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum PSP22Error {
Custom(String),
InsufficientBalance,
InsufficientAllowance,
ZeroRecipientAddress,
ZeroSenderAddress,
SafeTransferCheckFailed(String),
PermitInvalidSignature,
PermitExpired,
}
impl From<MathError> for PSP22Error {
fn from(err: MathError) -> Self {
match err {
MathError::Overflow => {
PSP22Error::Custom(String::from("M::Overflow"))
}
MathError::Underflow => {
PSP22Error::Custom(String::from("M::Underflow"))
}
MathError::DivByZero => {
PSP22Error::Custom(String::from("M::DivByZero"))
}
}
}
}
#[cfg(feature = "ownable")]
use crate::access::ownable::OwnableError;
#[cfg(feature = "ownable")]
impl From<OwnableError> for PSP22Error {
fn from(ownable: OwnableError) -> Self {
match ownable {
OwnableError::CallerIsNotOwner => {
PSP22Error::Custom(String::from("O::CallerIsNotOwner"))
}
}
}
}
#[cfg(feature = "access_control")]
use crate::access::access_control::AccessControlError;
#[cfg(feature = "access_control")]
impl From<AccessControlError> for PSP22Error {
fn from(access: AccessControlError) -> Self {
match access {
AccessControlError::MissingRole => {
PSP22Error::Custom(String::from("AC::MissingRole"))
}
AccessControlError::RoleRedundant => {
PSP22Error::Custom(String::from("AC::RoleRedundant"))
}
AccessControlError::InvalidCaller => {
PSP22Error::Custom(String::from("AC::InvalidCaller"))
}
}
}
}
#[cfg(feature = "pausable")]
use crate::security::pausable::PausableError;
#[cfg(feature = "pausable")]
impl From<PausableError> for PSP22Error {
fn from(pausable: PausableError) -> Self {
match pausable {
PausableError::Paused => {
PSP22Error::Custom(String::from("P::Paused"))
}
PausableError::NotPaused => {
PSP22Error::Custom(String::from("P::NotPaused"))
}
}
}
}