switchboard_solana/attestation_program/instructions/
function_set_escrow.rs1use crate::prelude::*;
2
3#[derive(Accounts)]
4#[instruction(params:FunctionSetEscrowParams)]
5pub struct FunctionSetEscrow<'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 #[account(mut)]
15 pub escrow_wallet: AccountInfo<'info>,
16
17 pub escrow_authority: AccountInfo<'info>,
19
20 #[account(mut)]
21 pub new_escrow: AccountInfo<'info>,
22
23 #[account(signer)]
25 pub new_escrow_authority: AccountInfo<'info>,
26
27 pub new_escrow_token_wallet: AccountInfo<'info>,
29}
30
31#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
32pub struct FunctionSetEscrowParams {}
33
34impl InstructionData for FunctionSetEscrowParams {}
35
36impl Discriminator for FunctionSetEscrowParams {
37 const DISCRIMINATOR: [u8; 8] = [63, 223, 123, 191, 23, 84, 113, 198];
38}
39
40impl Discriminator for FunctionSetEscrow<'_> {
41 const DISCRIMINATOR: [u8; 8] = [63, 223, 123, 191, 23, 84, 113, 198];
42}
43
44impl<'info> FunctionSetEscrow<'info> {
45 pub fn get_instruction(
46 &self,
47 program_id: Pubkey,
48 params: &FunctionSetEscrowParams,
49 ) -> anchor_lang::Result<Instruction> {
50 let accounts = self.to_account_metas(None);
51
52 let mut data: Vec<u8> = FunctionSetEscrow::discriminator().try_to_vec()?;
53 data.append(&mut params.try_to_vec()?);
54
55 let instruction = Instruction::new_with_bytes(program_id, &data, accounts);
56 Ok(instruction)
57 }
58
59 pub fn invoke(
60 &self,
61 program: AccountInfo<'info>,
62 params: &FunctionSetEscrowParams,
63 ) -> ProgramResult {
64 let instruction = self.get_instruction(*program.key, params)?;
65 let account_infos = self.to_account_infos();
66
67 invoke(&instruction, &account_infos[..])
68 }
69
70 pub fn invoke_signed(
71 &self,
72 program: AccountInfo<'info>,
73 params: &FunctionSetEscrowParams,
74 signer_seeds: &[&[&[u8]]],
75 ) -> ProgramResult {
76 let instruction = self.get_instruction(*program.key, params)?;
77 let account_infos = self.to_account_infos();
78
79 invoke_signed(&instruction, &account_infos[..], signer_seeds)
80 }
81
82 fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
83 let mut account_infos = Vec::new();
84 account_infos.extend(self.function.to_account_infos());
85 account_infos.extend(self.authority.to_account_infos());
86 account_infos.extend(self.attestation_queue.to_account_infos());
87 account_infos.extend(self.escrow_wallet.to_account_infos());
88 account_infos.extend(self.escrow_authority.to_account_infos());
89 account_infos.extend(self.new_escrow.to_account_infos());
90 account_infos.extend(self.new_escrow_authority.to_account_infos());
91 account_infos.extend(self.new_escrow_token_wallet.to_account_infos());
92 account_infos
93 }
94
95 #[allow(unused_variables)]
96 fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
97 let mut account_metas = Vec::new();
98 account_metas.extend(self.function.to_account_metas(None));
99 account_metas.extend(self.authority.to_account_metas(None));
100 account_metas.extend(self.attestation_queue.to_account_metas(None));
101 account_metas.extend(self.escrow_wallet.to_account_metas(None));
102 account_metas.extend(self.escrow_authority.to_account_metas(None));
103 account_metas.extend(self.new_escrow.to_account_metas(None));
104 account_metas.extend(self.new_escrow_authority.to_account_metas(None));
105 account_metas.extend(self.new_escrow_token_wallet.to_account_metas(None));
106 account_metas
107 }
108}