* Add solana-program-sdk boilerplate (cherry picked from commit3718771ffb
) # Conflicts: # sdk/Cargo.toml * Initial population of solana-program-sdk (cherry picked from commit63db324204
) # Conflicts: # Cargo.lock * Port programs to solana-program-sdk (cherry picked from commitfe68f7f786
) # Conflicts: # programs/bpf/Cargo.lock # programs/bpf/rust/128bit/Cargo.toml # programs/bpf/rust/128bit_dep/Cargo.toml # programs/bpf/rust/alloc/Cargo.toml # programs/bpf/rust/call_depth/Cargo.toml # programs/bpf/rust/custom_heap/Cargo.toml # programs/bpf/rust/dep_crate/Cargo.toml # programs/bpf/rust/deprecated_loader/Cargo.toml # programs/bpf/rust/dup_accounts/Cargo.toml # programs/bpf/rust/error_handling/Cargo.toml # programs/bpf/rust/external_spend/Cargo.toml # programs/bpf/rust/instruction_introspection/Cargo.toml # programs/bpf/rust/invoke/Cargo.toml # programs/bpf/rust/invoked/Cargo.toml # programs/bpf/rust/iter/Cargo.toml # programs/bpf/rust/many_args/Cargo.toml # programs/bpf/rust/many_args_dep/Cargo.toml # programs/bpf/rust/noop/Cargo.toml # programs/bpf/rust/panic/Cargo.toml # programs/bpf/rust/param_passing/Cargo.toml # programs/bpf/rust/param_passing_dep/Cargo.toml # programs/bpf/rust/rand/Cargo.toml # programs/bpf/rust/ristretto/Cargo.toml # programs/bpf/rust/sanity/Cargo.toml # programs/bpf/rust/sha256/Cargo.toml # programs/bpf/rust/sysval/Cargo.toml * Only activate legacy program feature for the solana-sdk crate (cherry picked from commit85c51f5787
) * Run serum-dex unit tests (cherry picked from commit92ce381d60
) * Rename solana-program-sdk to solana-program (cherry picked from commitdd711ab5fb
) # Conflicts: # programs/bpf/rust/128bit/Cargo.toml # programs/bpf/rust/128bit_dep/Cargo.toml # programs/bpf/rust/alloc/Cargo.toml # programs/bpf/rust/call_depth/Cargo.toml # programs/bpf/rust/custom_heap/Cargo.toml # programs/bpf/rust/dep_crate/Cargo.toml # programs/bpf/rust/deprecated_loader/Cargo.toml # programs/bpf/rust/dup_accounts/Cargo.toml # programs/bpf/rust/error_handling/Cargo.toml # programs/bpf/rust/external_spend/Cargo.toml # programs/bpf/rust/instruction_introspection/Cargo.toml # programs/bpf/rust/invoke/Cargo.toml # programs/bpf/rust/invoked/Cargo.toml # programs/bpf/rust/iter/Cargo.toml # programs/bpf/rust/many_args/Cargo.toml # programs/bpf/rust/many_args_dep/Cargo.toml # programs/bpf/rust/noop/Cargo.toml # programs/bpf/rust/panic/Cargo.toml # programs/bpf/rust/param_passing/Cargo.toml # programs/bpf/rust/param_passing_dep/Cargo.toml # programs/bpf/rust/rand/Cargo.toml # programs/bpf/rust/ristretto/Cargo.toml # programs/bpf/rust/sanity/Cargo.toml # programs/bpf/rust/sha256/Cargo.toml # programs/bpf/rust/sysval/Cargo.toml * Update frozen_abi hashes The movement of files in sdk/ caused ABI hashes to change (cherry picked from commita4956844bd
) * Resolve merge conflicts Co-authored-by: Michael Vines <mvines@gmail.com>
46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
//! @brief Example Rust-based BPF program that exercises instruction introspection
|
|
|
|
extern crate solana_program;
|
|
use solana_program::{
|
|
account_info::next_account_info, account_info::AccountInfo, entrypoint,
|
|
entrypoint::ProgramResult, info, program_error::ProgramError, pubkey::Pubkey,
|
|
sysvar::instructions,
|
|
};
|
|
|
|
entrypoint!(process_instruction);
|
|
fn process_instruction(
|
|
_program_id: &Pubkey,
|
|
accounts: &[AccountInfo],
|
|
instruction_data: &[u8],
|
|
) -> ProgramResult {
|
|
if instruction_data.is_empty() {
|
|
return Err(ProgramError::InvalidAccountData);
|
|
}
|
|
|
|
let secp_instruction_index = instruction_data[0];
|
|
let account_info_iter = &mut accounts.iter();
|
|
let instruction_accounts = next_account_info(account_info_iter)?;
|
|
assert_eq!(*instruction_accounts.key, instructions::id());
|
|
let data_len = instruction_accounts.try_borrow_data()?.len();
|
|
if data_len < 2 {
|
|
return Err(ProgramError::InvalidAccountData);
|
|
}
|
|
|
|
let instruction = instructions::load_instruction_at(
|
|
secp_instruction_index as usize,
|
|
&instruction_accounts.try_borrow_data()?,
|
|
)
|
|
.map_err(|_| ProgramError::InvalidAccountData)?;
|
|
|
|
let current_instruction =
|
|
instructions::load_current_index(&instruction_accounts.try_borrow_data()?);
|
|
let my_index = instruction_data[1] as u16;
|
|
assert_eq!(current_instruction, my_index);
|
|
|
|
info!(&format!("id: {}", instruction.program_id));
|
|
|
|
info!(&format!("data[0]: {}", instruction.data[0]));
|
|
info!(&format!("index: {}", current_instruction));
|
|
Ok(())
|
|
}
|