Check that the program was granted access to program_id (#13890)
This commit is contained in:
3407
programs/bpf/rust/caller_access/Cargo.lock
generated
Normal file
3407
programs/bpf/rust/caller_access/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
programs/bpf/rust/caller_access/Cargo.toml
Normal file
18
programs/bpf/rust/caller_access/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "solana-bpf-rust-caller-access"
|
||||
version = "1.5.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-program = { path = "../../../../sdk/program", version = "1.5.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
2
programs/bpf/rust/caller_access/Xargo.toml
Normal file
2
programs/bpf/rust/caller_access/Xargo.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
52
programs/bpf/rust/caller_access/src/lib.rs
Normal file
52
programs/bpf/rust/caller_access/src/lib.rs
Normal file
@ -0,0 +1,52 @@
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
entrypoint,
|
||||
entrypoint::ProgramResult,
|
||||
instruction::{AccountMeta, Instruction},
|
||||
msg,
|
||||
program::invoke,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(
|
||||
program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
instruction_data: &[u8],
|
||||
) -> ProgramResult {
|
||||
if instruction_data.len() == 32 {
|
||||
let key = Pubkey::new_from_array(instruction_data.try_into().unwrap());
|
||||
let ix = Instruction::new(key, &[2], vec![]);
|
||||
let mut lamports = accounts[0].lamports();
|
||||
let owner = &accounts[0].owner;
|
||||
let mut data = accounts[0].try_borrow_mut_data()?;
|
||||
let account = AccountInfo::new(
|
||||
&key,
|
||||
false,
|
||||
false,
|
||||
&mut lamports,
|
||||
&mut data,
|
||||
&owner,
|
||||
true,
|
||||
0,
|
||||
);
|
||||
msg!("{:?} calling {:?}", program_id, key);
|
||||
invoke(&ix, &[account])?;
|
||||
} else {
|
||||
match instruction_data[0] {
|
||||
1 => {
|
||||
let ix = Instruction::new(
|
||||
*program_id,
|
||||
&accounts[1].key.to_bytes(),
|
||||
vec![AccountMeta::new_readonly(*program_id, false)],
|
||||
);
|
||||
msg!("{:?} calling {:?}", program_id, program_id);
|
||||
invoke(&ix, accounts)?;
|
||||
}
|
||||
|
||||
_ => msg!("Should never get here"),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user