switchboard-on-demand 0.1.1

A Rust library to interact with the Switchboard Solana program.
use crate::anchor_traits::*;
use crate::cfg_client;
#[allow(unused_imports)]
use crate::impl_account_deserialize;
use crate::SWITCHBOARD_ON_DEMAND_PROGRAM_ID;
use bytemuck::{Pod, Zeroable};
use solana_program::pubkey::Pubkey;

const STATE_SEED: &[u8] = b"STATE";

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct State {
    pub bump: u8,
    padding1: [u8; 7],
    pub authority: Pubkey,
    pub guardian_queue: Pubkey,
    pub min_quote_verify_votes: u64,
    pub _ebuf: [u8; 2048],
}
unsafe impl Pod for State {}
unsafe impl Zeroable for State {}

cfg_client! {
    impl_account_deserialize!(State);
}

impl Discriminator for State {
    const DISCRIMINATOR: [u8; 8] = [216, 146, 107, 94, 104, 75, 182, 177];
}

impl Owner for State {
    fn owner() -> Pubkey {
        *SWITCHBOARD_ON_DEMAND_PROGRAM_ID
    }
}

impl State {
    pub fn size() -> usize {
        8 + std::mem::size_of::<State>()
    }

    pub fn get_pda() -> Pubkey {
        let (pda_key, _) =
            Pubkey::find_program_address(&[STATE_SEED], &*SWITCHBOARD_ON_DEMAND_PROGRAM_ID);
        pda_key
    }

    pub fn get_program_pda(program_id: Option<Pubkey>) -> Pubkey {
        let (pda_key, _) = Pubkey::find_program_address(
            &[STATE_SEED],
            &program_id.unwrap_or(*SWITCHBOARD_ON_DEMAND_PROGRAM_ID),
        );
        pda_key
    }

    cfg_client! {
        pub async fn fetch_async(
            client: &solana_client::nonblocking::rpc_client::RpcClient,
        ) -> std::result::Result<Self, crate::OnDemandError> {
            let pubkey = State::get_pda();
            crate::client::fetch_zerocopy_account_async(client, pubkey).await
        }
    }
}