add checked instructions sysvar api (#20790)
This commit is contained in:
@ -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)?;
|
||||
|
||||
|
@ -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)]
|
||||
|
Reference in New Issue
Block a user