-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
# Note: This crate must be built using do.sh | ||
|
||
[package] | ||
name = "solana-bpf-rust-instruction-introspection" | ||
version = "1.4.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/" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
solana-sdk = { path = "../../../../sdk/", version = "1.4.0", default-features = false } | ||
bincode = "1.3.1" | ||
|
||
[features] | ||
program = ["solana-sdk/program"] | ||
default = ["program"] | ||
|
||
[lib] | ||
name = "solana_bpf_rust_instruction_introspection" | ||
crate-type = ["cdylib"] | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! @brief Example Rust-based BPF program that exercises instruction introspection | ||
extern crate solana_sdk; | ||
use solana_sdk::{ | ||
account_info::next_account_info, account_info::AccountInfo, entrypoint, | ||
entrypoint::ProgramResult, info, instruction::Instruction, program_error::ProgramError, | ||
pubkey::Pubkey, | ||
}; | ||
|
||
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, | ||
solana_sdk::sysvar::instructions::id() | ||
); | ||
let instructions: Vec<Instruction> = unsafe { | ||
bincode::deserialize(*(*instruction_accounts.data).as_ptr()) | ||
.map_err(|_| ProgramError::InvalidAccountData)? | ||
}; | ||
if secp_instruction_index as usize > instructions.len() { | ||
return Err(ProgramError::InvalidAccountData); | ||
} | ||
info!(&format!( | ||
"{}", | ||
instructions[secp_instruction_index as usize].program_id | ||
)); | ||
|
||
info!(&format!( | ||
"{}", | ||
instructions[secp_instruction_index as usize].data[0] | ||
)); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! This account contains the serialized transaction instructions | ||
//! | ||
use crate::instruction::Instruction; | ||
use crate::sysvar::Sysvar; | ||
|
||
pub type Instructions = Vec<Instruction>; | ||
|
||
crate::declare_sysvar_id!("instructions1111111111111111111111111111111", Instructions); | ||
|
||
impl Sysvar for Instructions {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters