Files
solana/sdk/src/native_program.rs

76 lines
2.3 KiB
Rust
Raw Normal View History

2018-12-14 20:39:10 -08:00
use crate::account::KeyedAccount;
use crate::pubkey::Pubkey;
2018-12-03 13:32:31 -08:00
use std;
/// Reasons a program might have rejected an instruction.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ProgramError {
/// The program instruction returned an error
GenericError,
/// The arguments provided to a program instruction where invalid
InvalidArgument,
/// An instruction's data contents was invalid
InvalidInstructionData,
2018-12-03 22:21:55 -08:00
/// An account's data contents was invalid
InvalidAccountData,
/// An account's data was too small
AccountDataTooSmall,
2018-12-03 22:21:55 -08:00
2019-03-13 12:48:11 -06:00
/// The account did not have the expected program id
IncorrectProgramId,
/// A signature was required but not found
MissingRequiredSignature,
/// An initialize instruction was sent to an account that has already been initialized.
AccountAlreadyInitialized,
/// An attempt to operate on an account that hasn't been initialized.
UninitializedAccount,
/// CustomError allows on-chain programs to implement program-specific error types and see
/// them returned by the Solana runtime. A CustomError may be any type that is serialized
/// to a Vec of bytes, max length 32 bytes. Any CustomError Vec greater than this length will
/// be truncated by the runtime.
CustomError(Vec<u8>),
2018-12-03 13:32:31 -08:00
}
impl std::fmt::Display for ProgramError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "error")
}
}
impl std::error::Error for ProgramError {}
// All native programs export a symbol named process()
pub const ENTRYPOINT: &str = "process";
// Native program ENTRYPOINT prototype
2018-11-17 17:02:14 -08:00
pub type Entrypoint = unsafe extern "C" fn(
program_id: &Pubkey,
keyed_accounts: &mut [KeyedAccount],
data: &[u8],
tick_height: u64,
2018-12-03 13:32:31 -08:00
) -> Result<(), ProgramError>;
// Convenience macro to define the native program entrypoint. Supply a fn to this macro that
// conforms to the `Entrypoint` type signature.
#[macro_export]
macro_rules! solana_entrypoint(
($entrypoint:ident) => (
#[no_mangle]
2018-11-17 17:02:14 -08:00
pub extern "C" fn process(
program_id: &Pubkey,
keyed_accounts: &mut [KeyedAccount],
data: &[u8],
tick_height: u64
2018-12-03 13:32:31 -08:00
) -> Result<(), ProgramError> {
$entrypoint(program_id, keyed_accounts, data, tick_height)
}
)
);