gpl_token/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use gemachain_program::{decode_error::DecodeError, program_error::ProgramError};
5use thiserror::Error;
6
7/// Errors that may be returned by the Token program.
8#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
9pub enum TokenError {
10    // 0
11    /// Carat balance below rent-exempt threshold.
12    #[error("Carat balance below rent-exempt threshold")]
13    NotRentExempt,
14    /// Insufficient funds for the operation requested.
15    #[error("Insufficient funds")]
16    InsufficientFunds,
17    /// Invalid Mint.
18    #[error("Invalid Mint")]
19    InvalidMint,
20    /// Account not associated with this Mint.
21    #[error("Account not associated with this Mint")]
22    MintMismatch,
23    /// Owner does not match.
24    #[error("Owner does not match")]
25    OwnerMismatch,
26
27    // 5
28    /// This token's supply is fixed and new tokens cannot be minted.
29    #[error("Fixed supply")]
30    FixedSupply,
31    /// The account cannot be initialized because it is already being used.
32    #[error("Already in use")]
33    AlreadyInUse,
34    /// Invalid number of provided signers.
35    #[error("Invalid number of provided signers")]
36    InvalidNumberOfProvidedSigners,
37    /// Invalid number of required signers.
38    #[error("Invalid number of required signers")]
39    InvalidNumberOfRequiredSigners,
40    /// State is uninitialized.
41    #[error("State is unititialized")]
42    UninitializedState,
43
44    // 10
45    /// Instruction does not support native tokens
46    #[error("Instruction does not support native tokens")]
47    NativeNotSupported,
48    /// Non-native account can only be closed if its balance is zero
49    #[error("Non-native account can only be closed if its balance is zero")]
50    NonNativeHasBalance,
51    /// Invalid instruction
52    #[error("Invalid instruction")]
53    InvalidInstruction,
54    /// State is invalid for requested operation.
55    #[error("State is invalid for requested operation")]
56    InvalidState,
57    /// Operation overflowed
58    #[error("Operation overflowed")]
59    Overflow,
60
61    // 15
62    /// Account does not support specified authority type.
63    #[error("Account does not support specified authority type")]
64    AuthorityTypeNotSupported,
65    /// This token mint cannot freeze accounts.
66    #[error("This token mint cannot freeze accounts")]
67    MintCannotFreeze,
68    /// Account is frozen; all account operations will fail
69    #[error("Account is frozen")]
70    AccountFrozen,
71    /// Mint decimals mismatch between the client and mint
72    #[error("The provided decimals value different from the Mint decimals")]
73    MintDecimalsMismatch,
74    /// Instruction does not support non-native tokens
75    #[error("Instruction does not support non-native tokens")]
76    NonNativeNotSupported,
77}
78impl From<TokenError> for ProgramError {
79    fn from(e: TokenError) -> Self {
80        ProgramError::Custom(e as u32)
81    }
82}
83impl<T> DecodeError<T> for TokenError {
84    fn type_of() -> &'static str {
85        "TokenError"
86    }
87}