1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::cfg_client;
use crate::anchor_traits::*;
use crate::prelude::*;
use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;

pub struct OracleSetConfigs {}

#[derive(Clone, BorshSerialize, Debug)]
pub struct OracleSetConfigsParams {
    pub new_authority: Option<Pubkey>,
    pub new_secp_authority: Option<[u8; 64]>,
}

impl InstructionData for OracleSetConfigsParams {}

impl Discriminator for OracleSetConfigs {
    const DISCRIMINATOR: [u8; 8] = [129, 111, 223, 4, 191, 188, 70, 180];
}
impl Discriminator for OracleSetConfigsParams {
    const DISCRIMINATOR: [u8; 8] = OracleSetConfigs::DISCRIMINATOR;
}

pub struct OracleSetConfigsArgs {
    pub oracle: Pubkey,
    pub authority: Pubkey,
    pub secp_authority: [u8; 64],
}
pub struct OracleSetConfigsAccounts {
    pub oracle: Pubkey,
    pub authority: Pubkey,
}
impl ToAccountMetas for OracleSetConfigsAccounts {
    fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
        vec![
            AccountMeta::new(self.oracle, false),
            AccountMeta::new_readonly(self.authority, true),
        ]
    }
}

cfg_client! {
use solana_client::nonblocking::rpc_client::RpcClient;

impl OracleSetConfigs {
    pub async fn build_ix(_client: &RpcClient, args: OracleSetConfigsArgs) -> Result<Instruction, OnDemandError> {
        let ix = crate::utils::build_ix(
            &*SWITCHBOARD_ON_DEMAND_PROGRAM_ID,
            &OracleSetConfigsAccounts {
                oracle: args.oracle,
                authority: args.authority,
            },
            &OracleSetConfigsParams {
                new_authority: Some(args.authority),
                new_secp_authority: Some(args.secp_authority),
            },
        );
        Ok(ix)
    }
}
}