Skip to content

Commit

Permalink
transfer hook: add new onchain helper
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Jan 10, 2024
1 parent 0b076b1 commit 1b717ce
Show file tree
Hide file tree
Showing 4 changed files with 521 additions and 4 deletions.
2 changes: 1 addition & 1 deletion token/js/test/e2e-2022/tokenMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('tokenMetadata', async () => {
beforeEach(async () => {
mint = Keypair.generate();

const mintLen = getMintLen(EXTENSIONS);
const mintLen = getMintLen(EXTENSIONS) + 1;
const lamports = await connection.getMinimumBalanceForRentExemption(mintLen);

const transaction = new Transaction().add(
Expand Down
4 changes: 3 additions & 1 deletion token/program-2022-test/tests/transfer_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use {
processor::Processor,
},
spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError},
spl_transfer_hook_interface::{get_extra_account_metas_address, offchain::add_extra_account_metas_for_execute},
spl_transfer_hook_interface::{
get_extra_account_metas_address, offchain::add_extra_account_metas_for_execute,
},
std::{convert::TryInto, sync::Arc},
};

Expand Down
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 1b717ce

Please sign in to comment.