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
use crate::error::DexError;
use crate::processor::Processor;
use num_traits::FromPrimitive;
use solana_program::{
account_info::AccountInfo, decode_error::DecodeError, entrypoint::ProgramResult, msg,
program_error::PrintProgramError, pubkey::Pubkey,
};
#[cfg(not(feature = "no-entrypoint"))]
use solana_program::entrypoint;
#[cfg(not(feature = "no-entrypoint"))]
entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
msg!("Entrypoint");
if let Err(error) = Processor::process_instruction(program_id, accounts, instruction_data) {
error.print::<DexError>();
return Err(error);
}
Ok(())
}
impl PrintProgramError for DexError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
{
match self {
DexError::InvalidOrderIndex => msg!("Error: The given order index is invalid."),
DexError::UserAccountFull => {
msg!("Error: The user account has reached its maximum capacity for open orders.")
}
DexError::TransactionAborted => msg!("Error: The transaction has been aborted."),
DexError::MissingUserAccount => msg!("Error: A required user account is missing."),
DexError::OrderNotFound => msg!("Error: The specified order has not been found."),
DexError::NoOp => msg!("Error: The operation is a no-op"),
DexError::OutofFunds => msg!("Error: The user does not own enough lamports"),
DexError::UserAccountStillActive => msg!("Error: The user account is still active"),
DexError::MarketStillActive => msg!("Error: Market is still active"),
}
}
}