Add native loader entry points (#9486)
This commit is contained in:
@ -7,7 +7,19 @@ use crate::{account::KeyedAccount, instruction::InstructionError, pubkey::Pubkey
|
||||
/// program_id: Program ID of the currently executing program
|
||||
/// keyed_accounts: Accounts passed as part of the instruction
|
||||
/// instruction_data: Instruction data
|
||||
pub type Entrypoint = unsafe extern "C" fn(
|
||||
pub type ProgramEntrypoint = unsafe extern "C" fn(
|
||||
program_id: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
instruction_data: &[u8],
|
||||
) -> Result<(), InstructionError>;
|
||||
|
||||
// Prototype of a native loader entry point
|
||||
///
|
||||
/// program_id: Program ID of the currently executing program
|
||||
/// keyed_accounts: Accounts passed as part of the instruction
|
||||
/// instruction_data: Instruction data
|
||||
/// invoke_context: Invocation context
|
||||
pub type LoaderEntrypoint = unsafe extern "C" fn(
|
||||
program_id: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
instruction_data: &[u8],
|
||||
@ -103,3 +115,27 @@ macro_rules! declare_program(
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
/// Same as declare_program but for native loaders
|
||||
#[macro_export]
|
||||
macro_rules! declare_loader(
|
||||
($bs58_string:expr, $name:ident, $entrypoint:expr) => (
|
||||
$crate::declare_id!($bs58_string);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! $name {
|
||||
() => {
|
||||
(stringify!($name).to_string(), $crate::id())
|
||||
};
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn $name(
|
||||
program_id: &$crate::pubkey::Pubkey,
|
||||
keyed_accounts: &[$crate::account::KeyedAccount],
|
||||
instruction_data: &[u8],
|
||||
) -> Result<(), $crate::instruction::InstructionError> {
|
||||
$entrypoint(program_id, keyed_accounts, instruction_data)
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -134,6 +134,10 @@ pub enum InstructionError {
|
||||
/// Executable accounts must be rent exempt
|
||||
#[error("executable accounts must be rent exempt")]
|
||||
ExecutableAccountNotRentExempt,
|
||||
|
||||
/// Unsupported program id
|
||||
#[error("Unsupported program id")]
|
||||
UnsupportedProgramId,
|
||||
}
|
||||
|
||||
impl InstructionError {
|
||||
|
Reference in New Issue
Block a user