[][src]Macro solana_sdk::declare_program

macro_rules! declare_program {
    ($bs58_string:expr, $name:ident, $entrypoint:expr) => { ... };
}

Convenience macro to declare a native program

bs58_string: bs58 string representation the program's id name: Name of the program, must match the library name in Cargo.toml entrypoint: Program's entrypoint, must be of type Entrypoint

Examples

use std::str::FromStr;
use solana_sdk::account::KeyedAccount;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::declare_program;

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

declare_program!(
    "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::account::KeyedAccount;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::declare_program;

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

declare_program!(
    solana_sdk::system_program::ID,
    solana_my_program,
    my_process_instruction
);

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