switchboard-on-demand 0.1.5

A Rust library to interact with the Switchboard Solana program.
use crate::anchor_traits::*;
use crate::prelude::*;
use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;
use solana_program::system_program;

pub struct OracleHeartbeat {}

#[derive(Clone, BorshSerialize, Debug)]
pub struct OracleHeartbeatParams {
    pub uri: Option<[u8; 64]>,
}

impl InstructionData for OracleHeartbeatParams {}

impl Discriminator for OracleHeartbeat {
    const DISCRIMINATOR: [u8; 8] = [10, 175, 217, 130, 111, 35, 117, 54];
}
impl Discriminator for OracleHeartbeatParams {
    const DISCRIMINATOR: [u8; 8] = OracleHeartbeat::DISCRIMINATOR;
}

pub struct OracleHeartbeatArgs {
    pub oracle: Pubkey,
    pub oracle_signer: Pubkey,
    pub queue: Pubkey,
    pub queue_authority: Pubkey,
    pub gc_node: Pubkey,
    pub uri: Option<[u8; 64]>,
    pub oracle_feed_stats: Vec<Pubkey>,
    pub payer: Pubkey,
}
pub struct OracleHeartbeatAccounts {
    pub oracle: Pubkey,
    pub oracle_signer: Pubkey,
    pub queue: Pubkey,
    pub queue_authority: Pubkey,
    pub gc_node: Pubkey,
    pub payer: Pubkey,
}
impl ToAccountMetas for OracleHeartbeatAccounts {
    fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
        vec![
            AccountMeta::new(self.oracle, false),
            AccountMeta::new(OracleAccountData::stats_key(&self.oracle), false),
            AccountMeta::new_readonly(self.oracle_signer, true),
            AccountMeta::new(self.queue, false),
            AccountMeta::new_readonly(self.queue_authority, false),
            AccountMeta::new(self.gc_node, false),
            AccountMeta::new(State::get_pda(), false),
            AccountMeta::new(self.payer, true),
            AccountMeta::new_readonly(system_program::id(), false),
        ]
    }
}

impl OracleHeartbeat {
    pub fn build_ix(args: OracleHeartbeatArgs) -> Result<Instruction, OnDemandError> {
        let mut ix = crate::utils::build_ix(
            &*SWITCHBOARD_ON_DEMAND_PROGRAM_ID,
            &OracleHeartbeatAccounts {
                oracle: args.oracle,
                oracle_signer: args.oracle_signer,
                queue: args.queue,
                queue_authority: args.queue_authority,
                gc_node: args.gc_node,
                payer: args.payer,
            },
            &OracleHeartbeatParams { uri: args.uri },
        );
        for feed_stat in args.oracle_feed_stats {
            ix.accounts.push(AccountMeta::new(feed_stat, false));
        }
        Ok(ix)
    }
}