Replaces KeyedAccount by BorrowedAccount in system_instruction_processor. (#23217)

* Adds InstructionContext::check_number_of_instruction_accounts() and InstructionContext::get_instruction_account_key().
Bases check_sysvar_account() on instuction account indices.

* Adds instruction_account_indices enums to system_instruction_processor.

* Reorders parameters and adds InstructionContext.

* Replaces KeyedAccount by BorrowedAccount in system_instruction_processor (part 1).

* Replaces KeyedAccount by BorrowedAccount in system_instruction_processor (part 2).

* Replaces KeyedAccount by BorrowedAccount in system_instruction_processor (part 3).

* Replaces KeyedAccount by BorrowedAccount in system_instruction_processor (part 4).

* Replaces KeyedAccount by BorrowedAccount in system_instruction_processor (part 5).

* Code cleanup
This commit is contained in:
Alexander Meißner
2022-02-19 02:06:33 +01:00
committed by GitHub
parent 970f543ef6
commit ee7e411d68
4 changed files with 320 additions and 176 deletions

View File

@@ -239,11 +239,12 @@ pub mod get_sysvar_with_account_check2 {
fn check_sysvar_account<S: Sysvar>(
transaction_context: &TransactionContext,
instruction_context: &InstructionContext,
index_in_instruction: usize,
instruction_account_index: usize,
) -> Result<(), InstructionError> {
let index_in_transaction =
instruction_context.get_index_in_transaction(index_in_instruction)?;
if !S::check_id(transaction_context.get_key_of_account_at_index(index_in_transaction)?) {
if !S::check_id(
instruction_context
.get_instruction_account_key(transaction_context, instruction_account_index)?,
) {
return Err(InstructionError::InvalidArgument);
}
Ok(())