pub async fn add_extra_account_metas_for_execute<F, Fut>(
    instruction: &mut Instruction,
    program_id: &Pubkey,
    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 get all additional required account metas for an execute instruction, based on a validation state account.

The instruction being provided to this function must contain at least the same account keys as the ones being provided, in order. Specifically:

  1. source
  2. mint
  3. destination
  4. authority

The program_id should be the program ID of the program that the created ExecuteInstruction is for.

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:

add_extra_account_metas_for_execute(
    &mut instruction,
    &program_id,
    &source,
    &mint,
    &destination,
    &authority,
    amount,
    |address| self.client.get_account(&address).map_ok(|opt| opt.map(|acc| acc.data)),
)
.await?;