switchboard-on-demand 0.7.1

A Rust library to interact with the Switchboard Solana program.
Documentation
use solana_program::account_info::AccountInfo;
use solana_program::clock::Clock;

use crate::check_pubkey_eq;

/// Optimized function to parse the Clock sysvar from an AccountInfo.
#[inline(always)]
pub fn parse_clock<'a, T>(clock_sysvar: T) -> &'a Clock
where
    T: AsRef<AccountInfo<'a>>,
{
    assert!(check_pubkey_eq(
        clock_sysvar.as_ref().key,
        &solana_program::sysvar::clock::ID
    ));
    unsafe {
        let clock_data = *(&clock_sysvar.as_ref().data.as_ptr());
        &*(clock_data as *const _ as *const Clock)
    }
}