solana/sdk/src/native_program.rs

52 lines
1.5 KiB
Rust
Raw Normal View History

use account::KeyedAccount;
2018-11-17 17:02:14 -08:00
use pubkey::Pubkey;
// 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,
) -> bool;
// 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
) -> bool {
return $entrypoint(program_id, keyed_accounts, data, tick_height);
}
)
);
2018-12-03 12:26:23 -08:00
/// Reasons a program might have rejected an instruction.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ProgramError {
/// Contract's transactions resulted in an account with a negative balance
/// The difference from InsufficientFundsForFee is that the transaction was executed by the
/// contract
ResultWithNegativeTokens,
/// The program returned an error
GenericError,
/// Program's instruction token balance does not equal the balance after the instruction
UnbalancedInstruction,
/// Program modified an account's program id
ModifiedProgramId,
/// Program spent the tokens of an account that doesn't belong to it
ExternalAccountTokenSpend,
}