1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use solana_program::program_error::ProgramError;
use thiserror::Error;

#[derive(Error, Debug)]
#[repr(u32)]
pub enum Error {
    #[error("operation would result in deposited balance less than required minimum")]
    LessThanDepositMinimum,
    #[error("this account is prohibited from enrolling in distribution")]
    BlackistedForEnroll,
    #[error("no other program calls can be present in enumerate transaction")]
    NoOtherProgramsAllowed,
    #[error("voucher is not eligible to receive this drop")]
    VoucherNotEligible,
    #[error("overflow occured")]
    Overflow,
    #[error("inconsistent voucher state (very bad)")]
    InvalidVoucher,
    #[error("not enough lamports on account to start distribution")]
    NotEnoughToStartDistribution,
    #[error("can't start distribution with 0 token balance")]
    ZeroTokenBalance,
    #[error("instruction unavailable while distribution is in progress")]
    TemporaryUnavailable,
    #[error("not enough balance to withdraw")]
    InsufficientBalance,
    #[error("can't withdraw while user's token owner record has unrelinquished votes")]
    UnrelinquishedVotes,
}

impl From<Error> for ProgramError {
    fn from(e: Error) -> Self {
        ProgramError::Custom(e as u32)
    }
}

impl<T> From<Error> for Result<T, ProgramError> {
    fn from(e: Error) -> Self {
        Err(ProgramError::Custom(e as u32))
    }
}