Function switchboard_solana::prelude::fetch_zerocopy_account_async
source · pub async fn fetch_zerocopy_account_async<T: Pod + Discriminator + Owner>(
client: &RpcClient,
pubkey: Pubkey
) -> Result<T, SbError>
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 implementbytemuck::Pod
,Discriminator
, andOwner
.
§Returns
Returns a Result
containing the fetched account data of type T
if successful, or an SbError
if an error occurs.
§Errors
This function can return the following errors:
SbError::AccountNotFound
- If the account is not found.SbError::Message("no discriminator found")
- If no discriminator is found in the account data.SbError::Message("Discriminator error, check the account type")
- If the discriminator does not match the expected value.SbError::Message("AnchorParseError")
- If there is an error parsing the account data into typeT
.
§Example
use switchboard_solana::client::NonblockingRpcClient;
use switchboard_solana::error::SbError;
use switchboard_solana::types::{Discriminator, Owner};
use bytemuck::Pod;
use solana_sdk::pubkey::Pubkey;
async fn example(client: &NonblockingRpcClient, pubkey: Pubkey) -> Result<(), SbError> {
let account_data: MyAccountType = fetch_zerocopy_account_async(client, pubkey).await?;
// Do something with the fetched account data...
Ok(())
}