-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.rs
64 lines (57 loc) · 2 KB
/
error.rs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Error types
//! A multisig wallet program for the Solana blockchain Designed by Mohammadreza Ashouri / [email protected]
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use solana_program::{
decode_error::DecodeError,
info,
program_error::{PrintProgramError, ProgramError},
};
use thiserror::Error;
/// Errors that may be returned by the Token program.
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum WalletError {
/// Lamport balance below rent-exempt threshold.
#[error("Lamport balance below rent-exempt threshold")]
NotRentExempt,
/// Insufficient funds for the operation requested.
#[error("Insufficient funds")]
InsufficientFunds,
/// Invalid Owner.
#[error("Invalid owner")]
InvalidOwner,
/// Insufficient signature weight.
#[error("Insufficient weight")]
InsufficientWeight,
/// Invalid instruction
#[error("Invalid instruction")]
InvalidInstruction,
/// State is invalid for requested operation.
#[error("State is invalid for requested operation")]
InvalidState,
}
impl From<WalletError> for ProgramError {
fn from(e: WalletError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for WalletError {
fn type_of() -> &'static str {
"WalletError"
}
}
impl PrintProgramError for WalletError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
{
match self {
WalletError::NotRentExempt => info!("WalletError: NotRentExempt"),
WalletError::InsufficientFunds => info!("WalletError: InsufficientFunds"),
WalletError::InvalidOwner => info!("WalletError: InvalidOwner"),
WalletError::InsufficientWeight => info!("WalletError: InsufficientWeight"),
WalletError::InvalidInstruction => info!("WalletError: InvalidInstruction"),
WalletError::InvalidState => info!("WalletError: InvalidState"),
}
}
}