add unchecked invokes (#20313)
This commit is contained in:
parent
5e05f12c48
commit
8188c1dd59
|
@ -2,18 +2,36 @@ use crate::{
|
|||
account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
/// Invoke a cross-program instruction
|
||||
/// Invoke a cross-program instruction.
|
||||
///
|
||||
/// Note that the program id of the instruction being issued must also be included in
|
||||
/// `account_infos`.
|
||||
/// Notes:
|
||||
/// - RefCell checking can be compute unit expensive, to avoid that expense use
|
||||
/// `invoke_unchecked` instead, but at your own risk.
|
||||
/// - The program id of the instruction being issued must also be included in
|
||||
/// `account_infos`.
|
||||
pub fn invoke(instruction: &Instruction, account_infos: &[AccountInfo]) -> ProgramResult {
|
||||
invoke_signed(instruction, account_infos, &[])
|
||||
}
|
||||
|
||||
/// Invoke a cross-program instruction but don't enforce RefCell handling.
|
||||
///
|
||||
/// Notes:
|
||||
/// - The missing checks ensured that the invocation doesn't violate the borrow
|
||||
/// rules of the `AccountInfo` fields that are wrapped in `RefCell`s. To
|
||||
/// include the checks call `invoke` instead.
|
||||
/// - The program id of the instruction being issued must also be included in
|
||||
/// `account_infos`.
|
||||
pub fn invoke_unchecked(instruction: &Instruction, account_infos: &[AccountInfo]) -> ProgramResult {
|
||||
invoke_signed_unchecked(instruction, account_infos, &[])
|
||||
}
|
||||
|
||||
/// Invoke a cross-program instruction with program signatures
|
||||
///
|
||||
/// Note that the program id of the instruction being issued must also be included in
|
||||
/// `account_infos`.
|
||||
/// Notes:
|
||||
/// - RefCell checking can be compute unit expensive, to avoid that expense use
|
||||
/// `invoke_signed_unchecked` instead, but at your own risk.
|
||||
/// - The program id of the instruction being issued must also be included in
|
||||
/// `account_infos`.
|
||||
pub fn invoke_signed(
|
||||
instruction: &Instruction,
|
||||
account_infos: &[AccountInfo],
|
||||
|
@ -35,6 +53,23 @@ pub fn invoke_signed(
|
|||
}
|
||||
}
|
||||
|
||||
invoke_signed_unchecked(instruction, account_infos, signers_seeds)
|
||||
}
|
||||
|
||||
/// Invoke a cross-program instruction with program signatures but don't check
|
||||
/// RefCell handling.
|
||||
///
|
||||
/// Note:
|
||||
/// - The missing checks ensured that the invocation doesn't violate the borrow
|
||||
/// rules of the `AccountInfo` fields that are wrapped in `RefCell`s. To
|
||||
/// include the checks call `invoke_signed` instead.
|
||||
/// - The program id of the instruction being issued must also be included in
|
||||
/// `account_infos`.
|
||||
pub fn invoke_signed_unchecked(
|
||||
instruction: &Instruction,
|
||||
account_infos: &[AccountInfo],
|
||||
signers_seeds: &[&[&[u8]]],
|
||||
) -> ProgramResult {
|
||||
#[cfg(target_arch = "bpf")]
|
||||
{
|
||||
extern "C" {
|
||||
|
|
Loading…
Reference in New Issue