Add get_processed_sibling_instruction syscall (#22859)
This commit is contained in:
23
programs/bpf/rust/sibling_inner_instruction/Cargo.toml
Normal file
23
programs/bpf/rust/sibling_inner_instruction/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "solana-bpf-rust-sibling_inner-instructions"
|
||||
version = "1.10.0"
|
||||
description = "Solana BPF test program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
documentation = "https://docs.rs/solana-bpf-rust-log-data"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "=1.10.0" }
|
||||
|
||||
[features]
|
||||
default = ["program"]
|
||||
program = []
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
69
programs/bpf/rust/sibling_inner_instruction/src/lib.rs
Normal file
69
programs/bpf/rust/sibling_inner_instruction/src/lib.rs
Normal file
@ -0,0 +1,69 @@
|
||||
//! Example Rust-based BPF program that queries sibling instructions
|
||||
|
||||
#![cfg(feature = "program")]
|
||||
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
entrypoint,
|
||||
entrypoint::ProgramResult,
|
||||
instruction::{
|
||||
get_processed_sibling_instruction, get_stack_height, AccountMeta, Instruction,
|
||||
TRANSACTION_LEVEL_STACK_HEIGHT,
|
||||
},
|
||||
msg,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
_instruction_data: &[u8],
|
||||
) -> ProgramResult {
|
||||
msg!("sibling inner");
|
||||
|
||||
// account 0 is mint
|
||||
// account 1 is noop
|
||||
// account 2 is invoke_and_return
|
||||
|
||||
// Check sibling instructions
|
||||
|
||||
let sibling_instruction2 = Instruction::new_with_bytes(
|
||||
*accounts[2].key,
|
||||
&[3],
|
||||
vec![AccountMeta::new_readonly(*accounts[1].key, false)],
|
||||
);
|
||||
let sibling_instruction1 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[2],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[0].key, true),
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
],
|
||||
);
|
||||
let sibling_instruction0 = Instruction::new_with_bytes(
|
||||
*accounts[1].key,
|
||||
&[1],
|
||||
vec![
|
||||
AccountMeta::new_readonly(*accounts[1].key, false),
|
||||
AccountMeta::new_readonly(*accounts[0].key, true),
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(TRANSACTION_LEVEL_STACK_HEIGHT + 1, get_stack_height());
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(0),
|
||||
Some(sibling_instruction0)
|
||||
);
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(1),
|
||||
Some(sibling_instruction1)
|
||||
);
|
||||
assert_eq!(
|
||||
get_processed_sibling_instruction(2),
|
||||
Some(sibling_instruction2)
|
||||
);
|
||||
assert_eq!(get_processed_sibling_instruction(3), None);
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user