pub async fn fetch_zerocopy_account_async<T: Pod + Discriminator + Owner>(
    client: &RpcClient,
    pubkey: Pubkey
) -> Result<T, OnDemandError>
Expand description

Fetches an account asynchronously using the provided client and public key.

§Arguments

  • client - The non-blocking RPC client used to fetch the account.
  • pubkey - The public key of the account to fetch.

§Generic Parameters

  • T - The type of the account data. Must implement bytemuck::Pod, Discriminator, and Owner.

§Returns

Returns a Result containing the fetched account data of type T if successful, or an OnDemandError if an error occurs.

§Errors

This function can return the following errors:

  • OnDemandError::AccountNotFound - If the account is not found.
  • OnDemandError::Message("no discriminator found") - If no discriminator is found in the account data.
  • OnDemandError::Message("Discriminator error, check the account type") - If the discriminator does not match the expected value.
  • OnDemandError::Message("AnchorParseError") - If there is an error parsing the account data into type T.

§Example

use switchboard_solana::client::NonblockingRpcClient;
use switchboard_solana::error::OnDemandError;
use switchboard_solana::types::{Discriminator, Owner};
use bytemuck::Pod;
use solana_sdk::pubkey::Pubkey;

async fn example(client: &NonblockingRpcClient, pubkey: Pubkey) -> Result<(), OnDemandError> {
    let account_data: MyAccountType = fetch_zerocopy_account_async(client, pubkey).await?;
    // Do something with the fetched account data...
    Ok(())
}