switchboard_solana/attestation_program/instructions/
function_trigger.rs1use crate::prelude::*;
2
3#[derive(Accounts)]
4#[instruction(params:FunctionTriggerParams)]
5pub struct FunctionTrigger<'info> {
6 #[account(mut)]
7 pub function: AccountInfo<'info>,
8
9 #[account(signer)]
10 pub authority: AccountInfo<'info>,
11
12 pub attestation_queue: AccountInfo<'info>,
13}
14
15#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
16pub struct FunctionTriggerParams {}
17
18impl InstructionData for FunctionTriggerParams {}
19
20impl Discriminator for FunctionTriggerParams {
21 const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200];
22}
23
24impl Discriminator for FunctionTrigger<'_> {
25 const DISCRIMINATOR: [u8; 8] = [45, 224, 218, 184, 248, 83, 239, 200];
26}
27
28impl<'info> FunctionTrigger<'info> {
29 pub fn get_instruction(&self, program_id: Pubkey) -> anchor_lang::Result<Instruction> {
30 Ok(Instruction::new_with_bytes(
31 program_id,
32 &FunctionTrigger::discriminator().try_to_vec()?,
33 self.to_account_metas(None),
34 ))
35 }
36
37 pub fn invoke(&self, program: AccountInfo<'info>) -> ProgramResult {
38 let instruction = self.get_instruction(*program.key)?;
39 let account_infos = self.to_account_infos();
40
41 invoke(&instruction, &account_infos[..])
42 }
43
44 pub fn invoke_signed(
45 &self,
46 program: AccountInfo<'info>,
47 signer_seeds: &[&[&[u8]]],
48 ) -> ProgramResult {
49 let instruction = self.get_instruction(*program.key)?;
50 let account_infos = self.to_account_infos();
51
52 invoke_signed(&instruction, &account_infos[..], signer_seeds)
53 }
54
55 fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
56 let mut account_infos = Vec::new();
57 account_infos.extend(self.function.to_account_infos());
58 account_infos.extend(self.authority.to_account_infos());
59 account_infos.extend(self.attestation_queue.to_account_infos());
60 account_infos
61 }
62
63 #[allow(unused_variables)]
64 fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
65 let mut account_metas = Vec::new();
66 account_metas.extend(self.function.to_account_metas(None));
67 account_metas.extend(self.authority.to_account_metas(None));
68 account_metas.extend(self.attestation_queue.to_account_metas(None));
69 account_metas
70 }
71}