use solana_program_error::{ProgramError, ToStr};
#[repr(u32)]
#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
pub enum TransferHookError {
#[error("Incorrect account provided")]
IncorrectAccount = 2_110_272_652,
#[error("Mint has no mint authority")]
MintHasNoMintAuthority,
#[error("Incorrect mint authority has signed the instruction")]
IncorrectMintAuthority,
#[error("Program called outside of a token transfer")]
ProgramCalledOutsideOfTransfer,
}
impl From<TransferHookError> for ProgramError {
fn from(e: TransferHookError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl ToStr for TransferHookError {
fn to_str(&self) -> &'static str {
match self {
TransferHookError::IncorrectAccount => "Incorrect account provided",
TransferHookError::MintHasNoMintAuthority => "Mint has no mint authority",
TransferHookError::IncorrectMintAuthority => {
"Incorrect mint authority has signed the instruction"
}
TransferHookError::ProgramCalledOutsideOfTransfer => {
"Program called outside of a token transfer"
}
}
}
}
impl TryFrom<u32> for TransferHookError {
type Error = ProgramError;
fn try_from(code: u32) -> Result<Self, Self::Error> {
num_traits::FromPrimitive::from_u32(code).ok_or(ProgramError::InvalidArgument)
}
}