This commit is contained in:
Conner Gallagher 2023-06-26 16:47:28 -06:00
parent 38c696c1b4
commit d64386b35f
2 changed files with 37 additions and 47 deletions

View File

@ -3,32 +3,38 @@ use crate::prelude::*;
#[derive(Accounts)] #[derive(Accounts)]
#[instruction(params:FunctionTriggerParams)] #[instruction(params:FunctionTriggerParams)]
pub struct FunctionTrigger<'info> { pub struct FunctionTrigger<'info> {
#[account(mut, has_one = authority)] #[account(
mut,
has_one = authority,
has_one = attestation_queue,
)]
pub function: AccountLoader<'info, FunctionAccountData>, pub function: AccountLoader<'info, FunctionAccountData>,
pub authority: Signer<'info>, pub authority: Signer<'info>,
pub attestation_queue: AccountLoader<'info, AttestationQueueAccountData>,
} }
#[derive(Clone, AnchorSerialize, AnchorDeserialize)] #[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct FunctionTriggerParams {} pub struct FunctionTriggerParams {}
impl InstructionData for FunctionTriggerParams {} impl InstructionData for FunctionTriggerParams {}
impl Discriminator for FunctionTriggerParams { impl Discriminator for FunctionTriggerParams {
const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200]; const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200];
} }
impl Discriminator for FunctionTrigger<'_> { impl Discriminator for FunctionTrigger<'_> {
const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200]; const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200];
} }
impl<'info> FunctionTrigger<'info> { impl<'info> FunctionTrigger<'info> {
pub fn get_instruction(&self, program_id: Pubkey) -> anchor_lang::Result<Instruction> { pub fn get_instruction(&self, program_id: Pubkey) -> anchor_lang::Result<Instruction> {
let accounts = self.to_account_metas(None); Ok(Instruction::new_with_bytes(
program_id,
let mut data: Vec<u8> = FunctionTrigger::discriminator().try_to_vec()?; &FunctionTrigger::discriminator().try_to_vec()?,
let params = FunctionTriggerParams {}; self.to_account_metas(None),
let mut param_vec: Vec<u8> = params.try_to_vec()?; ))
data.append(&mut param_vec);
let instruction = Instruction::new_with_bytes(program_id, &data, accounts);
Ok(instruction)
} }
pub fn invoke(&self, program: AccountInfo<'info>) -> ProgramResult { pub fn invoke(&self, program: AccountInfo<'info>) -> ProgramResult {
@ -51,28 +57,18 @@ impl<'info> FunctionTrigger<'info> {
fn to_account_infos(&self) -> Vec<AccountInfo<'info>> { fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
let mut account_infos = Vec::new(); let mut account_infos = Vec::new();
account_infos.extend(anchor_lang::ToAccountInfos::to_account_infos( account_infos.extend(self.function.to_account_infos());
&self.function, account_infos.extend(self.authority.to_account_infos());
)); account_infos.extend(self.attestation_queue.to_account_infos());
account_infos.extend(anchor_lang::ToAccountInfos::to_account_infos(
&self.authority,
));
account_infos account_infos
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> { fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
let mut account_metas = Vec::new(); let mut account_metas = Vec::new();
account_metas.push(anchor_lang::solana_program::instruction::AccountMeta::new( account_metas.extend(self.function.to_account_metas(None));
self.function.key(), account_metas.extend(self.authority.to_account_metas(None));
false, account_metas.extend(self.attestation_queue.to_account_metas(None));
));
account_metas.push(
anchor_lang::solana_program::instruction::AccountMeta::new_readonly(
self.authority.key(),
true,
),
);
account_metas account_metas
} }
} }

View File

@ -22,44 +22,38 @@ pub struct FunctionVerify<'info> {
#[account( #[account(
has_one = attestation_queue, has_one = attestation_queue,
constraint = constraint = verifier_quote.load()?.enclave_signer == verifier_enclave_signer.key(),
verifier_quote.load()?.enclave_signer == verifier_enclave_signer.key(),
)] )]
pub verifier_quote: AccountLoader<'info, EnclaveAccountData>, pub verifier_quote: AccountLoader<'info, EnclaveAccountData>,
pub verifier_enclave_signer: Signer<'info>, pub verifier_enclave_signer: Signer<'info>,
#[account( #[account(
seeds = [ seeds = [PERMISSION_SEED,
PERMISSION_SEED, attestation_queue.load()?.authority.as_ref(),
attestation_queue.load()?.authority.as_ref(), attestation_queue.key().as_ref(),
attestation_queue.key().as_ref(), verifier_quote.key().as_ref()],
verifier_quote.key().as_ref()
],
bump = verifier_permission.load()?.bump, bump = verifier_permission.load()?.bump,
)] )]
pub verifier_permission: AccountLoader<'info, AttestationPermissionAccountData>, pub verifier_permission: AccountLoader<'info,AttestationPermissionAccountData>,
#[account( #[account(
mut, mut,
constraint = escrow.is_native() && escrow.owner == state.key() constraint = escrow.is_native() && escrow.owner == state.key()
)] )]
pub escrow: Account<'info, TokenAccount>, pub escrow: Box<Account<'info, TokenAccount>>,
#[account( #[account(
mut, mut,
constraint = receiver.is_native() constraint = receiver.is_native()
)] )]
pub receiver: Account<'info, TokenAccount>, pub receiver: Box<Account<'info, TokenAccount>>,
#[account( #[account(seeds = [STATE_SEED], bump = state.load()?.bump)]
seeds = [STATE_SEED],
bump = state.load()?.bump
)]
pub state: AccountLoader<'info, AttestationProgramState>, pub state: AccountLoader<'info, AttestationProgramState>,
pub attestation_queue: AccountLoader<'info, AttestationQueueAccountData>, pub attestation_queue: AccountLoader<'info, AttestationQueueAccountData>,
pub token_program: Program<'info, Token>, pub token_program: Program<'info, Token>,
} }
@ -137,8 +131,6 @@ impl<'info> FunctionVerify<'info> {
fn to_account_infos(&self) -> Vec<AccountInfo<'info>> { fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
let mut account_infos = Vec::new(); let mut account_infos = Vec::new();
account_infos.extend(self.state.to_account_infos());
account_infos.extend(self.attestation_queue.to_account_infos());
account_infos.extend(self.function.to_account_infos()); account_infos.extend(self.function.to_account_infos());
account_infos.extend(self.function_enclave_signer.to_account_infos()); account_infos.extend(self.function_enclave_signer.to_account_infos());
account_infos.extend(self.fn_quote.to_account_infos()); account_infos.extend(self.fn_quote.to_account_infos());
@ -147,6 +139,8 @@ impl<'info> FunctionVerify<'info> {
account_infos.extend(self.verifier_permission.to_account_infos()); account_infos.extend(self.verifier_permission.to_account_infos());
account_infos.extend(self.escrow.to_account_infos()); account_infos.extend(self.escrow.to_account_infos());
account_infos.extend(self.receiver.to_account_infos()); account_infos.extend(self.receiver.to_account_infos());
account_infos.extend(self.state.to_account_infos());
account_infos.extend(self.attestation_queue.to_account_infos());
account_infos.extend(self.token_program.to_account_infos()); account_infos.extend(self.token_program.to_account_infos());
account_infos account_infos
} }
@ -154,8 +148,6 @@ impl<'info> FunctionVerify<'info> {
#[allow(unused_variables)] #[allow(unused_variables)]
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> { fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
let mut account_metas = Vec::new(); let mut account_metas = Vec::new();
account_metas.extend(self.state.to_account_metas(None));
account_metas.extend(self.attestation_queue.to_account_metas(None));
account_metas.extend(self.function.to_account_metas(None)); account_metas.extend(self.function.to_account_metas(None));
account_metas account_metas
.extend(self.function_enclave_signer.to_account_metas(None)); .extend(self.function_enclave_signer.to_account_metas(None));
@ -166,6 +158,8 @@ impl<'info> FunctionVerify<'info> {
account_metas.extend(self.verifier_permission.to_account_metas(None)); account_metas.extend(self.verifier_permission.to_account_metas(None));
account_metas.extend(self.escrow.to_account_metas(None)); account_metas.extend(self.escrow.to_account_metas(None));
account_metas.extend(self.receiver.to_account_metas(None)); account_metas.extend(self.receiver.to_account_metas(None));
account_metas.extend(self.state.to_account_metas(None));
account_metas.extend(self.attestation_queue.to_account_metas(None));
account_metas.extend(self.token_program.to_account_metas(None)); account_metas.extend(self.token_program.to_account_metas(None));
account_metas account_metas
} }