use crate::cfg_client;
use crate::prelude::*;
#[derive(Accounts)]
#[instruction(params:ServiceRequestQuoteVerifyParams)]
pub struct ServiceRequestQuoteVerify<'info> {
#[account(mut)]
pub service: AccountInfo<'info>, pub service_worker: AccountInfo<'info>, pub function: AccountInfo<'info>, pub attestation_queue: AccountInfo<'info>, #[account(mut)]
pub escrow_wallet: AccountInfo<'info>, #[account(mut)]
pub escrow_token_wallet: AccountInfo<'info>, #[account(signer)]
pub new_enclave_signer: AccountInfo<'info>, #[account(signer)]
pub authority: AccountInfo<'info>, }
#[derive(Clone, AnchorSerialize, AnchorDeserialize, Debug)]
pub struct ServiceRequestQuoteVerifyParams {
pub quote_registry: Option<Vec<u8>>,
pub registry_key: Vec<u8>,
}
impl InstructionData for ServiceRequestQuoteVerifyParams {}
impl Discriminator for ServiceRequestQuoteVerifyParams {
const DISCRIMINATOR: [u8; 8] = [231, 168, 196, 146, 27, 43, 196, 108];
}
impl Discriminator for ServiceRequestQuoteVerify<'_> {
const DISCRIMINATOR: [u8; 8] = [231, 168, 196, 146, 27, 43, 196, 108];
}
cfg_client! {
pub struct ServiceRequestQuoteVerifyAccounts {
pub service: Pubkey,
pub service_worker: Pubkey,
pub function: Pubkey,
pub attestation_queue: Pubkey,
pub escrow_wallet: Pubkey,
pub new_enclave_signer: Pubkey,
pub authority: Pubkey,
}
impl ToAccountMetas for ServiceRequestQuoteVerifyAccounts {
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
vec![
AccountMeta::new(self.service, false),
AccountMeta::new_readonly(self.service_worker, false),
AccountMeta::new_readonly(self.function, false),
AccountMeta::new_readonly(self.attestation_queue, false),
AccountMeta::new(self.escrow_wallet, false),
AccountMeta::new(find_associated_token_address(&self.escrow_wallet, &NativeMint::id()), false),
AccountMeta::new_readonly(self.new_enclave_signer, true),
AccountMeta::new_readonly(self.authority, true),
]
}
}
}
impl<'info> ServiceRequestQuoteVerify<'info> {
pub fn get_instruction(
&self,
program_id: Pubkey,
params: &ServiceRequestQuoteVerifyParams,
) -> anchor_lang::Result<Instruction> {
let accounts = self.to_account_metas(None);
let mut data: Vec<u8> = ServiceRequestQuoteVerify::discriminator().try_to_vec()?;
data.append(&mut params.try_to_vec()?);
let instruction = Instruction::new_with_bytes(program_id, &data, accounts);
Ok(instruction)
}
pub fn invoke(
&self,
program: AccountInfo<'info>,
params: &ServiceRequestQuoteVerifyParams,
) -> ProgramResult {
let instruction = self.get_instruction(*program.key, params)?;
let account_infos = self.to_account_infos();
invoke(&instruction, &account_infos[..])
}
pub fn invoke_signed(
&self,
program: AccountInfo<'info>,
params: &ServiceRequestQuoteVerifyParams,
signer_seeds: &[&[&[u8]]],
) -> ProgramResult {
let instruction = self.get_instruction(*program.key, params)?;
let account_infos = self.to_account_infos();
invoke_signed(&instruction, &account_infos[..], signer_seeds)
}
fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
let mut account_infos = Vec::new();
account_infos.extend(self.service.to_account_infos());
account_infos.extend(self.service_worker.to_account_infos());
account_infos.extend(self.function.to_account_infos());
account_infos.extend(self.attestation_queue.to_account_infos());
account_infos.extend(self.escrow_wallet.to_account_infos());
account_infos.extend(self.escrow_token_wallet.to_account_infos());
account_infos.extend(self.new_enclave_signer.to_account_infos());
account_infos.extend(self.authority.to_account_infos());
account_infos
}
#[allow(unused_variables)]
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
let mut account_metas = Vec::new();
account_metas.extend(self.service.to_account_metas(None));
account_metas.extend(self.service_worker.to_account_metas(None));
account_metas.extend(self.function.to_account_metas(None));
account_metas.extend(self.attestation_queue.to_account_metas(None));
account_metas.extend(self.escrow_wallet.to_account_metas(None));
account_metas.extend(self.escrow_token_wallet.to_account_metas(Some(true)));
account_metas.extend(self.authority.to_account_metas(Some(true)));
account_metas
}
cfg_client! {
pub fn build_ix(
accounts: &ServiceRequestQuoteVerifyAccounts,
params: &ServiceRequestQuoteVerifyParams,
) -> Result<Instruction, SbError> {
Ok(
crate::utils::build_ix(
&*SWITCHBOARD_ATTESTATION_PROGRAM_ID,
accounts,
params,
)
)
}
}
}