1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::OnDemandError;
use futures::TryFutureExt;
use solana_sdk::clock::Clock;

pub async fn fetch_async(
    client: &solana_client::nonblocking::rpc_client::RpcClient,
) -> std::result::Result<Clock, crate::OnDemandError> {
    let pubkey = solana_sdk::sysvar::clock::id();
    let data = client
        .get_account_data(&pubkey)
        .map_err(|_| OnDemandError::AccountNotFound)
        .await?
        .to_vec();
    bincode::deserialize(&data).map_err(|_| OnDemandError::AccountNotFound)
}