Macro solana_sdk::declare_builtin[][src]

macro_rules! declare_builtin {
    ($bs58_string : expr, $name : ident, $entrypoint : expr) => { ... };
    ($bs58_string : expr, $name : ident, $entrypoint : expr, $id : path) => { ... };
}
Expand description

Convenience macro to declare a builtin

bs58_string: bs58 string representation the program’s id name: Name of the program entrypoint: Program’s entrypoint, must be of type Entrypoint id: Path to the program id access function, used if this macro is not called in src/lib

Examples

use std::str::FromStr;
// wrapper is used so that the macro invocation occurs in the item position
// rather than in the statement position which isn't allowed.
mod item_wrapper {
use solana_sdk::keyed_account::KeyedAccount;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::declare_builtin;

fn my_process_instruction(
    first_instruction_account: usize,
    keyed_accounts: &[KeyedAccount],
    instruction_data: &[u8],
) -> Result<(), InstructionError> {
  // Process an instruction
  Ok(())
}

declare_builtin!(
    "My11111111111111111111111111111111111111111",
    solana_my_program,
    my_process_instruction
);

let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
assert_eq!(id(), my_id);
use std::str::FromStr;
use solana_sdk::keyed_account::KeyedAccount;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::declare_builtin;

fn my_process_instruction(
    first_instruction_account: usize,
    keyed_accounts: &[KeyedAccount],
    instruction_data: &[u8],
) -> Result<(), InstructionError> {
  // Process an instruction
  Ok(())
}

declare_builtin!(
    solana_sdk::system_program::ID,
    solana_my_program,
    my_process_instruction
);
}

assert_eq!(id(), solana_sdk::system_program::ID);