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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use crate::anchor_traits::*;
use crate::prelude::*;
use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;
use crate::get_sb_program_id;

pub struct GuardianQuoteVerify {}

#[derive(Clone, Debug)]
pub struct GuardianQuoteVerifyParams {
    pub timestamp: i64,
    pub mr_enclave: [u8; 32],
    pub idx: u32,
    pub ed25519_key: Pubkey,
    pub secp256k1_key: [u8; 64],
    pub slot: u64,
    pub signature: [u8; 64],
    pub recovery_id: u8,
    pub advisories: Vec<u32>,
}

impl BorshSerialize for GuardianQuoteVerifyParams {
    fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
        self.timestamp.serialize(writer)?;
        self.mr_enclave.serialize(writer)?;
        self.idx.serialize(writer)?;
        writer.write_all(self.ed25519_key.as_ref())?;
        self.secp256k1_key.serialize(writer)?;
        self.slot.serialize(writer)?;
        self.signature.serialize(writer)?;
        self.recovery_id.serialize(writer)?;
        self.advisories.serialize(writer)?;
        Ok(())
    }
}

impl InstructionData for GuardianQuoteVerifyParams {}

impl Discriminator for GuardianQuoteVerifyParams {
    const DISCRIMINATOR: [u8; 8] = GuardianQuoteVerify::DISCRIMINATOR;
}

impl Discriminator for GuardianQuoteVerify {
    const DISCRIMINATOR: [u8; 8] = [168, 36, 93, 156, 157, 150, 148, 45];
}

pub struct GuardianQuoteVerifyArgs {
    pub guardian: Pubkey,
    pub oracle: Pubkey,
    pub authority: Pubkey,
    pub guardian_queue: Pubkey,
    pub timestamp: i64,
    pub mr_enclave: [u8; 32],
    pub idx: u32,
    pub ed25519_key: Pubkey,
    pub secp256k1_key: [u8; 64],
    pub slot: u64,
    pub signature: [u8; 64],
    pub recovery_id: u8,
    pub advisories: Vec<u32>,
}
pub struct GuardianQuoteVerifyAccounts {
    pub guardian: Pubkey,
    pub oracle: Pubkey,
    pub authority: Pubkey,
    pub guardian_queue: Pubkey,
    pub state: Pubkey,
    pub recent_slothashes: Pubkey,
}
impl ToAccountMetas for GuardianQuoteVerifyAccounts {
    fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
        vec![
            AccountMeta::new(self.guardian, false),
            AccountMeta::new(self.oracle, false),
            AccountMeta::new_readonly(self.authority, true),
            AccountMeta::new(self.guardian_queue, false),
            AccountMeta::new_readonly(self.state, false),
            AccountMeta::new_readonly(self.recent_slothashes, false),
        ]
    }
}

impl GuardianQuoteVerify {
    pub fn build_ix(args: GuardianQuoteVerifyArgs) -> Result<Instruction, OnDemandError> {
        let cluster = std::env::var("CLUSTER").unwrap_or("mainnet".to_string());
        Ok(crate::utils::build_ix(
            &get_sb_program_id(&cluster),
            &GuardianQuoteVerifyAccounts {
                guardian: args.guardian,
                oracle: args.oracle,
                authority: args.authority,
                guardian_queue: args.guardian_queue,
                state: State::get_pda(),
                recent_slothashes: solana_program::sysvar::slot_hashes::ID,
            },
            &GuardianQuoteVerifyParams {
                timestamp: args.timestamp,
                mr_enclave: args.mr_enclave,
                idx: args.idx,
                ed25519_key: args.ed25519_key,
                secp256k1_key: args.secp256k1_key,
                slot: args.slot,
                signature: args.signature,
                recovery_id: args.recovery_id,
                advisories: args.advisories,
            },
        ))
    }
}