Skip to content

Commit

Permalink
transfer hook: add new onchain helper
Browse files Browse the repository at this point in the history
As another step for solving #6064, the onchain helpers now need to be
replaced. This PR makes that change in the SPL Transfer Hook interface.

Specifically, this commit adds a new `add_extra_accounts_for_execute_cpi(..)`
helper and deprecates the old one.

Like its offchain counterpart, this new helper requires the arguments for
`instruction::execute(..)` in order to validate that a proper
`ExecuteInstruction` is being resolved, thus ensuring proper account resolution.

This function, like its now-deprecated sibling, is designed specifically to add
extra accounts to an `ExecuteInstruction` CPI instruction. It's expected that
the instruction being provided is a CPI instruction for another program, and
that program will CPI to the transfer hook program in question. Details about
this have been added to the helper's documentation.
  • Loading branch information
Joe C authored Jan 11, 2024
1 parent 5f490e5 commit 095bc48
Show file tree
Hide file tree
Showing 2 changed files with 444 additions and 2 deletions.
4 changes: 2 additions & 2 deletions token/program-2022/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use {
account_info::AccountInfo, entrypoint::ProgramResult, instruction::AccountMeta,
program::invoke_signed, pubkey::Pubkey,
},
spl_transfer_hook_interface::onchain::add_cpi_accounts_for_execute,
};

/// Helper to CPI into token-2022 on-chain, looking through the additional
Expand Down Expand Up @@ -62,7 +61,8 @@ pub fn invoke_transfer_checked<'a>(
let mint_data = mint_info.try_borrow_data()?;
let mint = StateWithExtensions::<Mint>::unpack(&mint_data)?;
if let Some(program_id) = transfer_hook::get_program_id(&mint) {
add_cpi_accounts_for_execute(
#[allow(deprecated)]
spl_transfer_hook_interface::onchain::add_cpi_accounts_for_execute(
&mut cpi_instruction,
&mut cpi_account_infos,
mint_info.key,
Expand Down
Loading

0 comments on commit 095bc48

Please sign in to comment.