Safer invoke context (#22898)

* Safer invoke context

* feedback and rebase with master
This commit is contained in:
Jack May
2022-02-03 02:34:51 -08:00
committed by GitHub
parent bd1850df25
commit cc94a93b56
8 changed files with 150 additions and 65 deletions

View File

@ -96,13 +96,23 @@ impl TransactionContext {
}
/// Searches for an account by its key
pub fn get_key_of_account_at_index(&self, index_in_transaction: usize) -> &Pubkey {
&self.account_keys[index_in_transaction]
pub fn get_key_of_account_at_index(
&self,
index_in_transaction: usize,
) -> Result<&Pubkey, InstructionError> {
self.account_keys
.get(index_in_transaction)
.ok_or(InstructionError::NotEnoughAccountKeys)
}
/// Searches for an account by its key
pub fn get_account_at_index(&self, index_in_transaction: usize) -> &RefCell<AccountSharedData> {
&self.accounts[index_in_transaction]
pub fn get_account_at_index(
&self,
index_in_transaction: usize,
) -> Result<&RefCell<AccountSharedData>, InstructionError> {
self.accounts
.get(index_in_transaction)
.ok_or(InstructionError::NotEnoughAccountKeys)
}
/// Searches for an account by its key