spl_token_2022::offchain

Function add_extra_account_metas

Source
pub async fn add_extra_account_metas<F, Fut>(
    instruction: &mut Instruction,
    source_pubkey: &Pubkey,
    mint_pubkey: &Pubkey,
    destination_pubkey: &Pubkey,
    authority_pubkey: &Pubkey,
    amount: u64,
    fetch_account_data_fn: F,
) -> Result<(), AccountFetchError>
where F: Fn(Pubkey) -> Fut, Fut: Future<Output = AccountDataResult>,
Expand description

Offchain helper to add required account metas to an instruction, including the ones required by the transfer hook.

To be client-agnostic and to avoid pulling in the full solana-sdk, this simply takes a function that will return its data as Future<Vec<u8>> for the given address. Can be called in the following way:

let mut transfer_instruction = spl_token_2022::instruction::transfer_checked(
    &spl_token_2022::id(),
    source_pubkey,
    mint_pubkey,
    destination_pubkey,
    authority_pubkey,
    signer_pubkeys,
    amount,
    decimals,
)?;
add_extra_account_metas(
    &mut transfer_instruction,
    source_pubkey,
    mint_pubkey,
    destination_pubkey,
    authority_pubkey,
    amount,
    fetch_account_data_fn,
).await?;