* add checked instructions sysvar api (#20790)
(cherry picked from commit a8098f37d0
)
# Conflicts:
# programs/bpf/rust/sysvar/src/lib.rs
# runtime/src/accounts.rs
* resolve conflicts
Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
@@ -26,9 +26,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)?;
|
||||
|
||||
|
@@ -6,6 +6,7 @@ use solana_program::{
|
||||
entrypoint,
|
||||
entrypoint::ProgramResult,
|
||||
fee_calculator::FeeCalculator,
|
||||
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 {
|
||||
@@ -57,8 +58,30 @@ pub fn process_instruction(
|
||||
// Instructions
|
||||
msg!("Instructions identifier:");
|
||||
sysvar::instructions::id().log();
|
||||
assert_eq!(*accounts[4].owner, sysvar::id());
|
||||
let index = instructions::load_current_index(&accounts[5].try_borrow_data()?);
|
||||
let instruction = instructions::load_instruction_at_checked(index as usize, &accounts[5])?;
|
||||
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),
|
||||
AccountMeta::new_readonly(*accounts[10].key, false),
|
||||
],
|
||||
)
|
||||
);
|
||||
|
||||
// Recent Blockhashes
|
||||
{
|
||||
|
Reference in New Issue
Block a user