wip
This commit is contained in:
parent
38c696c1b4
commit
d64386b35f
|
@ -3,32 +3,38 @@ use crate::prelude::*;
|
|||
#[derive(Accounts)]
|
||||
#[instruction(params:FunctionTriggerParams)]
|
||||
pub struct FunctionTrigger<'info> {
|
||||
#[account(mut, has_one = authority)]
|
||||
#[account(
|
||||
mut,
|
||||
has_one = authority,
|
||||
has_one = attestation_queue,
|
||||
)]
|
||||
pub function: AccountLoader<'info, FunctionAccountData>,
|
||||
|
||||
pub authority: Signer<'info>,
|
||||
|
||||
pub attestation_queue: AccountLoader<'info, AttestationQueueAccountData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
|
||||
pub struct FunctionTriggerParams {}
|
||||
|
||||
impl InstructionData for FunctionTriggerParams {}
|
||||
|
||||
impl Discriminator for FunctionTriggerParams {
|
||||
const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200];
|
||||
}
|
||||
|
||||
impl Discriminator for FunctionTrigger<'_> {
|
||||
const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200];
|
||||
}
|
||||
|
||||
impl<'info> FunctionTrigger<'info> {
|
||||
pub fn get_instruction(&self, program_id: Pubkey) -> anchor_lang::Result<Instruction> {
|
||||
let accounts = self.to_account_metas(None);
|
||||
|
||||
let mut data: Vec<u8> = FunctionTrigger::discriminator().try_to_vec()?;
|
||||
let params = FunctionTriggerParams {};
|
||||
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)
|
||||
Ok(Instruction::new_with_bytes(
|
||||
program_id,
|
||||
&FunctionTrigger::discriminator().try_to_vec()?,
|
||||
self.to_account_metas(None),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn invoke(&self, program: AccountInfo<'info>) -> ProgramResult {
|
||||
|
@ -51,28 +57,18 @@ impl<'info> FunctionTrigger<'info> {
|
|||
|
||||
fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
|
||||
let mut account_infos = Vec::new();
|
||||
account_infos.extend(anchor_lang::ToAccountInfos::to_account_infos(
|
||||
&self.function,
|
||||
));
|
||||
account_infos.extend(anchor_lang::ToAccountInfos::to_account_infos(
|
||||
&self.authority,
|
||||
));
|
||||
account_infos.extend(self.function.to_account_infos());
|
||||
account_infos.extend(self.authority.to_account_infos());
|
||||
account_infos.extend(self.attestation_queue.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.push(anchor_lang::solana_program::instruction::AccountMeta::new(
|
||||
self.function.key(),
|
||||
false,
|
||||
));
|
||||
account_metas.push(
|
||||
anchor_lang::solana_program::instruction::AccountMeta::new_readonly(
|
||||
self.authority.key(),
|
||||
true,
|
||||
),
|
||||
);
|
||||
account_metas.extend(self.function.to_account_metas(None));
|
||||
account_metas.extend(self.authority.to_account_metas(None));
|
||||
account_metas.extend(self.attestation_queue.to_account_metas(None));
|
||||
account_metas
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,44 +22,38 @@ pub struct FunctionVerify<'info> {
|
|||
|
||||
#[account(
|
||||
has_one = attestation_queue,
|
||||
constraint =
|
||||
verifier_quote.load()?.enclave_signer == verifier_enclave_signer.key(),
|
||||
constraint = verifier_quote.load()?.enclave_signer == verifier_enclave_signer.key(),
|
||||
)]
|
||||
pub verifier_quote: AccountLoader<'info, EnclaveAccountData>,
|
||||
|
||||
pub verifier_enclave_signer: Signer<'info>,
|
||||
|
||||
#[account(
|
||||
seeds = [
|
||||
PERMISSION_SEED,
|
||||
attestation_queue.load()?.authority.as_ref(),
|
||||
attestation_queue.key().as_ref(),
|
||||
verifier_quote.key().as_ref()
|
||||
],
|
||||
seeds = [PERMISSION_SEED,
|
||||
attestation_queue.load()?.authority.as_ref(),
|
||||
attestation_queue.key().as_ref(),
|
||||
verifier_quote.key().as_ref()],
|
||||
bump = verifier_permission.load()?.bump,
|
||||
)]
|
||||
pub verifier_permission: AccountLoader<'info, AttestationPermissionAccountData>,
|
||||
pub verifier_permission: AccountLoader<'info,AttestationPermissionAccountData>,
|
||||
|
||||
#[account(
|
||||
mut,
|
||||
constraint = escrow.is_native() && escrow.owner == state.key()
|
||||
)]
|
||||
pub escrow: Account<'info, TokenAccount>,
|
||||
pub escrow: Box<Account<'info, TokenAccount>>,
|
||||
|
||||
#[account(
|
||||
mut,
|
||||
mut,
|
||||
constraint = receiver.is_native()
|
||||
)]
|
||||
pub receiver: Account<'info, TokenAccount>,
|
||||
pub receiver: Box<Account<'info, TokenAccount>>,
|
||||
|
||||
#[account(
|
||||
seeds = [STATE_SEED],
|
||||
bump = state.load()?.bump
|
||||
)]
|
||||
#[account(seeds = [STATE_SEED], bump = state.load()?.bump)]
|
||||
pub state: AccountLoader<'info, AttestationProgramState>,
|
||||
|
||||
pub attestation_queue: AccountLoader<'info, AttestationQueueAccountData>,
|
||||
|
||||
|
||||
pub token_program: Program<'info, Token>,
|
||||
}
|
||||
|
||||
|
@ -137,8 +131,6 @@ impl<'info> FunctionVerify<'info> {
|
|||
|
||||
fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
|
||||
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_enclave_signer.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.escrow.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
|
||||
}
|
||||
|
@ -154,8 +148,6 @@ impl<'info> FunctionVerify<'info> {
|
|||
#[allow(unused_variables)]
|
||||
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
|
||||
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_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.escrow.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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue