#[cfg(feature = "anchor")]
use anchor_lang::solana_program;
#[cfg(not(feature = "anchor"))]
use crate::solana_program;
use crate::{borrow_account_data, check_pubkey_eq, get_account_key, AsAccountInfo};
#[inline(always)]
pub fn get_slot<'a, T>(clock_sysvar: T) -> u64
where
T: AsAccountInfo<'a>,
{
assert!(check_pubkey_eq(
*get_account_key!(clock_sysvar.as_account_info()),
solana_program::sysvar::clock::ID
));
unsafe {
let clock_data = borrow_account_data!(clock_sysvar.as_account_info());
core::ptr::read_unaligned(clock_data.as_ptr() as *const u64)
}
}
crate::cfg_client! {
use crate::OnDemandError;
use futures::TryFutureExt;
pub async fn fetch_async(
client: &crate::RpcClient,
) -> std::result::Result<anchor_client::solana_sdk::sysvar::clock::Clock, crate::OnDemandError> {
let pubkey = anchor_client::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)
}
}