Replaces KeyedAccount
by BorrowedAccount
in nonce_keyed_account
. (#23214)
* Adds get_sysvar_with_account_check2 for ABIv2. * Replaces get_signers() and get_sysvar_with_account_check() in system_instruction_processor. * Replaces KeyedAccount by BorrowedAccount in nonce_keyed_account.
This commit is contained in:
committed by
GitHub
parent
da00b39f4f
commit
1a68f81f89
@ -11,6 +11,7 @@ use {
|
||||
clock::Clock, epoch_schedule::EpochSchedule, rent::Rent, slot_hashes::SlotHashes,
|
||||
stake_history::StakeHistory, Sysvar, SysvarId,
|
||||
},
|
||||
transaction_context::{InstructionContext, TransactionContext},
|
||||
},
|
||||
std::sync::Arc,
|
||||
};
|
||||
@ -231,3 +232,86 @@ pub mod get_sysvar_with_account_check {
|
||||
invoke_context.get_sysvar_cache().get_stake_history()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod get_sysvar_with_account_check2 {
|
||||
use super::*;
|
||||
|
||||
fn check_sysvar_account<S: Sysvar>(
|
||||
transaction_context: &TransactionContext,
|
||||
instruction_context: &InstructionContext,
|
||||
index_in_instruction: 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)?) {
|
||||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn clock(
|
||||
invoke_context: &InvokeContext,
|
||||
instruction_context: &InstructionContext,
|
||||
index_in_instruction: usize,
|
||||
) -> Result<Arc<Clock>, InstructionError> {
|
||||
check_sysvar_account::<Clock>(
|
||||
invoke_context.transaction_context,
|
||||
instruction_context,
|
||||
index_in_instruction,
|
||||
)?;
|
||||
invoke_context.get_sysvar_cache().get_clock()
|
||||
}
|
||||
|
||||
pub fn rent(
|
||||
invoke_context: &InvokeContext,
|
||||
instruction_context: &InstructionContext,
|
||||
index_in_instruction: usize,
|
||||
) -> Result<Arc<Rent>, InstructionError> {
|
||||
check_sysvar_account::<Rent>(
|
||||
invoke_context.transaction_context,
|
||||
instruction_context,
|
||||
index_in_instruction,
|
||||
)?;
|
||||
invoke_context.get_sysvar_cache().get_rent()
|
||||
}
|
||||
|
||||
pub fn slot_hashes(
|
||||
invoke_context: &InvokeContext,
|
||||
instruction_context: &InstructionContext,
|
||||
index_in_instruction: usize,
|
||||
) -> Result<Arc<SlotHashes>, InstructionError> {
|
||||
check_sysvar_account::<SlotHashes>(
|
||||
invoke_context.transaction_context,
|
||||
instruction_context,
|
||||
index_in_instruction,
|
||||
)?;
|
||||
invoke_context.get_sysvar_cache().get_slot_hashes()
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub fn recent_blockhashes(
|
||||
invoke_context: &InvokeContext,
|
||||
instruction_context: &InstructionContext,
|
||||
index_in_instruction: usize,
|
||||
) -> Result<Arc<RecentBlockhashes>, InstructionError> {
|
||||
check_sysvar_account::<RecentBlockhashes>(
|
||||
invoke_context.transaction_context,
|
||||
instruction_context,
|
||||
index_in_instruction,
|
||||
)?;
|
||||
invoke_context.get_sysvar_cache().get_recent_blockhashes()
|
||||
}
|
||||
|
||||
pub fn stake_history(
|
||||
invoke_context: &InvokeContext,
|
||||
instruction_context: &InstructionContext,
|
||||
index_in_instruction: usize,
|
||||
) -> Result<Arc<StakeHistory>, InstructionError> {
|
||||
check_sysvar_account::<StakeHistory>(
|
||||
invoke_context.transaction_context,
|
||||
instruction_context,
|
||||
index_in_instruction,
|
||||
)?;
|
||||
invoke_context.get_sysvar_cache().get_stake_history()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user