Safer invoke context (#22898)
* Safer invoke context * feedback and rebase with master
This commit is contained in:
@ -493,6 +493,7 @@ mod tests {
|
||||
let account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(index_in_transaction)
|
||||
.unwrap()
|
||||
.borrow();
|
||||
assert_eq!(account.lamports(), account_info.lamports());
|
||||
assert_eq!(account.data(), &account_info.data.borrow()[..]);
|
||||
@ -518,6 +519,7 @@ mod tests {
|
||||
let mut account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(index_in_transaction)
|
||||
.unwrap()
|
||||
.borrow_mut();
|
||||
account.set_lamports(0);
|
||||
account.set_data(vec![0; 0]);
|
||||
@ -536,6 +538,7 @@ mod tests {
|
||||
let account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(index_in_transaction)
|
||||
.unwrap()
|
||||
.borrow();
|
||||
assert_eq!(&*account, original_account);
|
||||
}
|
||||
@ -567,6 +570,7 @@ mod tests {
|
||||
let account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(index_in_transaction)
|
||||
.unwrap()
|
||||
.borrow();
|
||||
assert_eq!(account.lamports(), account_info.lamports());
|
||||
assert_eq!(account.data(), &account_info.data.borrow()[..]);
|
||||
@ -579,6 +583,7 @@ mod tests {
|
||||
let mut account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(index_in_transaction)
|
||||
.unwrap()
|
||||
.borrow_mut();
|
||||
account.set_lamports(0);
|
||||
account.set_data(vec![0; 0]);
|
||||
@ -596,6 +601,7 @@ mod tests {
|
||||
let account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(index_in_transaction)
|
||||
.unwrap()
|
||||
.borrow();
|
||||
assert_eq!(&*account, original_account);
|
||||
}
|
||||
|
@ -2546,10 +2546,12 @@ where
|
||||
for instruction_account in instruction_accounts.iter() {
|
||||
let account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(instruction_account.index_in_transaction);
|
||||
.get_account_at_index(instruction_account.index_in_transaction)
|
||||
.map_err(SyscallError::InstructionError)?;
|
||||
let account_key = invoke_context
|
||||
.transaction_context
|
||||
.get_key_of_account_at_index(instruction_account.index_in_transaction);
|
||||
.get_key_of_account_at_index(instruction_account.index_in_transaction)
|
||||
.map_err(SyscallError::InstructionError)?;
|
||||
if account.borrow().executable() {
|
||||
// Use the known account
|
||||
accounts.push((instruction_account.index_in_transaction, None));
|
||||
@ -2725,6 +2727,7 @@ fn call<'a, 'b: 'a>(
|
||||
let callee_account = invoke_context
|
||||
.transaction_context
|
||||
.get_account_at_index(*callee_account_index)
|
||||
.map_err(SyscallError::InstructionError)?
|
||||
.borrow();
|
||||
*caller_account.lamports = callee_account.lamports();
|
||||
*caller_account.owner = *callee_account.owner();
|
||||
@ -3103,16 +3106,20 @@ impl<'a, 'b> SyscallObject<BpfError> for SyscallGetProcessedSiblingInstruction<'
|
||||
*program_id =
|
||||
instruction_context.get_program_id(invoke_context.transaction_context);
|
||||
data.clone_from_slice(instruction_context.get_instruction_data());
|
||||
let account_metas = instruction_context
|
||||
.get_instruction_accounts_metas()
|
||||
.iter()
|
||||
.map(|meta| AccountMeta {
|
||||
pubkey: *invoke_context
|
||||
.get_key_of_account_at_index(meta.index_in_transaction),
|
||||
is_signer: meta.is_signer,
|
||||
is_writable: meta.is_writable,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let account_metas = question_mark!(
|
||||
instruction_context
|
||||
.get_instruction_accounts_metas()
|
||||
.iter()
|
||||
.map(|meta| Ok(AccountMeta {
|
||||
pubkey: *invoke_context
|
||||
.get_key_of_account_at_index(meta.index_in_transaction)
|
||||
.map_err(SyscallError::InstructionError)?,
|
||||
is_signer: meta.is_signer,
|
||||
is_writable: meta.is_writable,
|
||||
}))
|
||||
.collect::<Result<Vec<_>, EbpfError<BpfError>>>(),
|
||||
result
|
||||
);
|
||||
accounts.clone_from_slice(account_metas.as_slice());
|
||||
}
|
||||
*data_len = instruction_context.get_instruction_data().len();
|
||||
|
Reference in New Issue
Block a user