Files
solana/programs/bpf/rust/invoke_and_error/src/lib.rs
Justin Starry c97f34a0fd Add script for running nightly rustfmt on all workspaces (#23244)
* Add script for running nightly rustfmt on all workspaces

* invalidate ci cache
2022-02-22 11:59:06 +08:00

36 lines
978 B
Rust

//! Invokes an instruction and returns an error, the instruction invoked
//! uses the instruction data provided and all the accounts
use solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
instruction::{AccountMeta, Instruction},
program::invoke,
pubkey::Pubkey,
};
solana_program::entrypoint!(process_instruction);
fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
let to_call = accounts[0].key;
let infos = accounts;
let instruction = Instruction {
accounts: accounts[1..]
.iter()
.map(|acc| AccountMeta {
pubkey: *acc.key,
is_signer: acc.is_signer,
is_writable: acc.is_writable,
})
.collect(),
data: instruction_data.to_owned(),
program_id: *to_call,
};
let _ = invoke(&instruction, infos);
Err(42.into())
}