2018-12-14 20:39:10 -08:00
|
|
|
use crate::account::KeyedAccount;
|
|
|
|
use crate::pubkey::Pubkey;
|
2019-03-18 09:05:03 -07:00
|
|
|
use crate::transaction::InstructionError;
|
2018-11-13 18:17:32 -08:00
|
|
|
|
|
|
|
// 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,
|
2019-03-18 09:05:03 -07:00
|
|
|
) -> Result<(), InstructionError>;
|
2018-11-13 18:38:51 -08:00
|
|
|
|
|
|
|
// 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(
|
2019-03-21 13:36:25 -07:00
|
|
|
program_id: &solana_sdk::pubkey::Pubkey,
|
|
|
|
keyed_accounts: &mut [solana_sdk::account::KeyedAccount],
|
2018-11-17 17:02:14 -08:00
|
|
|
data: &[u8],
|
|
|
|
tick_height: u64
|
2019-03-21 13:36:25 -07:00
|
|
|
) -> Result<(), solana_sdk::transaction::InstructionError> {
|
2018-12-03 13:32:31 -08:00
|
|
|
$entrypoint(program_id, keyed_accounts, data, tick_height)
|
2018-11-13 18:38:51 -08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2019-03-21 13:36:25 -07:00
|
|
|
|
|
|
|
// Macro to define an entrypoint from a native `process_instruction` function.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! process_instruction_entrypoint(
|
|
|
|
($process_instruction:ident) => (
|
|
|
|
solana_sdk::solana_entrypoint!(process_instruction_entrypoint);
|
|
|
|
fn process_instruction_entrypoint(
|
|
|
|
program_id: &solana_sdk::pubkey::Pubkey,
|
|
|
|
keyed_accounts: &mut [solana_sdk::account::KeyedAccount],
|
|
|
|
data: &[u8],
|
|
|
|
tick_height: u64,
|
|
|
|
) -> Result<(), solana_sdk::transaction::InstructionError> {
|
|
|
|
solana_logger::setup();
|
|
|
|
|
|
|
|
log::trace!("process_instruction: {:?}", data);
|
|
|
|
log::trace!("keyed_accounts: {:?}", keyed_accounts);
|
|
|
|
$process_instruction(program_id, keyed_accounts, data, tick_height)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|