add checked instructions sysvar api (#20790)

This commit is contained in:
Jack May
2021-10-19 21:01:58 -07:00
committed by GitHub
parent 58164517e4
commit a8098f37d0
5 changed files with 116 additions and 7 deletions

View File

@ -33,9 +33,9 @@ fn process_instruction(
return Err(ProgramError::InvalidAccountData);
}
let instruction = instructions::load_instruction_at(
let instruction = instructions::load_instruction_at_checked(
secp_instruction_index as usize,
&instruction_accounts.try_borrow_data()?,
instruction_accounts,
)
.map_err(|_| ProgramError::InvalidAccountData)?;

View File

@ -7,6 +7,7 @@ use solana_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
instruction::{AccountMeta, Instruction},
msg,
program_error::ProgramError,
pubkey::Pubkey,
@ -19,7 +20,7 @@ use solana_program::{
entrypoint!(process_instruction);
#[allow(clippy::unnecessary_wraps)]
pub fn process_instruction(
_program_id: &Pubkey,
program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
@ -48,7 +49,27 @@ pub fn process_instruction(
sysvar::instructions::id().log();
assert_eq!(*accounts[4].owner, sysvar::id());
let index = instructions::load_current_index(&accounts[4].try_borrow_data()?);
let instruction = instructions::load_instruction_at_checked(index as usize, &accounts[4])?;
assert_eq!(0, index);
assert_eq!(
instruction,
Instruction::new_with_bytes(
*program_id,
&[] as &[u8],
vec![
AccountMeta::new(*accounts[0].key, true),
AccountMeta::new(*accounts[1].key, false),
AccountMeta::new_readonly(*accounts[2].key, false),
AccountMeta::new_readonly(*accounts[3].key, false),
AccountMeta::new_readonly(*accounts[4].key, false),
AccountMeta::new_readonly(*accounts[5].key, false),
AccountMeta::new_readonly(*accounts[6].key, false),
AccountMeta::new_readonly(*accounts[7].key, false),
AccountMeta::new_readonly(*accounts[8].key, false),
AccountMeta::new_readonly(*accounts[9].key, false),
],
)
);
// Recent Blockhashes
#[allow(deprecated)]