switchboard_solana/attestation_program/instructions/
function_set_config.rs

1use crate::prelude::*;
2
3#[derive(Accounts)]
4#[instruction(params:FunctionSetConfigParams)]
5pub struct FunctionSetConfig<'info> {
6    #[account(mut)]
7    pub function: AccountInfo<'info>,
8
9    #[account(signer)]
10    pub authority: AccountInfo<'info>,
11}
12
13#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
14pub struct FunctionSetConfigParams {
15    pub name: Option<Vec<u8>>,
16    pub metadata: Option<Vec<u8>>,
17    pub container: Option<Vec<u8>>,
18    pub container_registry: Option<Vec<u8>>,
19    pub version: Option<Vec<u8>>,
20    pub schedule: Option<Vec<u8>>,
21    pub mr_enclaves: Option<Vec<[u8; 32]>>,
22    pub requests_disabled: Option<bool>,
23    pub requests_require_authorization: Option<bool>,
24    pub requests_fee: Option<u64>,
25}
26
27impl InstructionData for FunctionSetConfigParams {}
28
29impl Discriminator for FunctionSetConfigParams {
30    const DISCRIMINATOR: [u8; 8] = [232, 132, 21, 251, 253, 189, 96, 94];
31}
32
33impl Discriminator for FunctionSetConfig<'_> {
34    const DISCRIMINATOR: [u8; 8] = [232, 132, 21, 251, 253, 189, 96, 94];
35}
36
37impl<'info> FunctionSetConfig<'info> {
38    pub fn get_instruction(
39        &self,
40        program_id: Pubkey,
41        params: &FunctionSetConfigParams,
42    ) -> anchor_lang::Result<Instruction> {
43        let accounts = self.to_account_metas(None);
44
45        let mut data: Vec<u8> = FunctionSetConfig::discriminator().try_to_vec()?;
46        data.append(&mut params.try_to_vec()?);
47
48        let instruction = Instruction::new_with_bytes(program_id, &data, accounts);
49        Ok(instruction)
50    }
51
52    pub fn invoke(
53        &self,
54        program: AccountInfo<'info>,
55        params: &FunctionSetConfigParams,
56    ) -> ProgramResult {
57        let instruction = self.get_instruction(*program.key, params)?;
58        let account_infos = self.to_account_infos();
59
60        invoke(&instruction, &account_infos[..])
61    }
62
63    pub fn invoke_signed(
64        &self,
65        program: AccountInfo<'info>,
66        params: &FunctionSetConfigParams,
67        signer_seeds: &[&[&[u8]]],
68    ) -> ProgramResult {
69        let instruction = self.get_instruction(*program.key, params)?;
70        let account_infos = self.to_account_infos();
71
72        invoke_signed(&instruction, &account_infos[..], signer_seeds)
73    }
74
75    fn to_account_infos(&self) -> Vec<AccountInfo<'info>> {
76        let mut account_infos = Vec::new();
77        account_infos.extend(self.function.to_account_infos());
78        account_infos.extend(self.authority.to_account_infos());
79        account_infos
80    }
81
82    #[allow(unused_variables)]
83    fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
84        let mut account_metas = Vec::new();
85        account_metas.extend(self.function.to_account_metas(None));
86        account_metas.extend(self.authority.to_account_metas(None));
87        account_metas
88    }
89}