use super::{
AccessControlError,
OwnableError,
PausableError,
ReentrancyGuardError,
};
use openbrush::traits::String;
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum PSP37Error {
Custom(String),
InsufficientBalance,
TransferToZeroAddress,
TokenNotExists,
NotAllowed,
SelfApprove,
SafeTransferCheckFailed(String),
}
impl From<OwnableError> for PSP37Error {
fn from(ownable: OwnableError) -> Self {
match ownable {
OwnableError::CallerIsNotOwner => PSP37Error::Custom(String::from("O::CallerIsNotOwner")),
OwnableError::NewOwnerIsZero => PSP37Error::Custom(String::from("O::NewOwnerIsZero")),
}
}
}
impl From<AccessControlError> for PSP37Error {
fn from(access: AccessControlError) -> Self {
match access {
AccessControlError::MissingRole => PSP37Error::Custom(String::from("AC::MissingRole")),
AccessControlError::RoleRedundant => PSP37Error::Custom(String::from("AC::RoleRedundant")),
AccessControlError::InvalidCaller => PSP37Error::Custom(String::from("AC::InvalidCaller")),
}
}
}
impl From<PausableError> for PSP37Error {
fn from(pausable: PausableError) -> Self {
match pausable {
PausableError::Paused => PSP37Error::Custom(String::from("P::Paused")),
PausableError::NotPaused => PSP37Error::Custom(String::from("P::NotPaused")),
}
}
}
impl From<ReentrancyGuardError> for PSP37Error {
fn from(guard: ReentrancyGuardError) -> Self {
match guard {
ReentrancyGuardError::ReentrantCall => PSP37Error::Custom(String::from("RG::ReentrantCall")),
}
}
}
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum PSP37ReceiverError {
TransferRejected(String),
}
impl From<PSP37ReceiverError> for PSP37Error {
fn from(error: PSP37ReceiverError) -> Self {
match error {
PSP37ReceiverError::TransferRejected(message) => PSP37Error::SafeTransferCheckFailed(message),
}
}
}