Skip to main content

token_acl_client/generated/instructions/
set_gating_program.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_pubkey::Pubkey;
11
12pub const SET_GATING_PROGRAM_DISCRIMINATOR: u8 = 2;
13
14/// Accounts.
15#[derive(Debug)]
16pub struct SetGatingProgram {
17    pub authority: solana_pubkey::Pubkey,
18
19    pub mint_config: solana_pubkey::Pubkey,
20}
21
22impl SetGatingProgram {
23    pub fn instruction(
24        &self,
25        args: SetGatingProgramInstructionArgs,
26    ) -> solana_instruction::Instruction {
27        self.instruction_with_remaining_accounts(args, &[])
28    }
29    #[allow(clippy::arithmetic_side_effects)]
30    #[allow(clippy::vec_init_then_push)]
31    pub fn instruction_with_remaining_accounts(
32        &self,
33        args: SetGatingProgramInstructionArgs,
34        remaining_accounts: &[solana_instruction::AccountMeta],
35    ) -> solana_instruction::Instruction {
36        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
37        accounts.push(solana_instruction::AccountMeta::new_readonly(
38            self.authority,
39            true,
40        ));
41        accounts.push(solana_instruction::AccountMeta::new(
42            self.mint_config,
43            false,
44        ));
45        accounts.extend_from_slice(remaining_accounts);
46        let mut data = SetGatingProgramInstructionData::new().try_to_vec().unwrap();
47        let mut args = args.try_to_vec().unwrap();
48        data.append(&mut args);
49
50        solana_instruction::Instruction {
51            program_id: crate::TOKEN_ACL_ID,
52            accounts,
53            data,
54        }
55    }
56}
57
58#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
59#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
60pub struct SetGatingProgramInstructionData {
61    discriminator: u8,
62}
63
64impl SetGatingProgramInstructionData {
65    pub fn new() -> Self {
66        Self { discriminator: 2 }
67    }
68
69    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
70        borsh::to_vec(self)
71    }
72}
73
74impl Default for SetGatingProgramInstructionData {
75    fn default() -> Self {
76        Self::new()
77    }
78}
79
80#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
81#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
82pub struct SetGatingProgramInstructionArgs {
83    pub new_gating_program: Pubkey,
84}
85
86impl SetGatingProgramInstructionArgs {
87    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
88        borsh::to_vec(self)
89    }
90}
91
92/// Instruction builder for `SetGatingProgram`.
93///
94/// ### Accounts:
95///
96///   0. `[signer]` authority
97///   1. `[writable]` mint_config
98#[derive(Clone, Debug, Default)]
99pub struct SetGatingProgramBuilder {
100    authority: Option<solana_pubkey::Pubkey>,
101    mint_config: Option<solana_pubkey::Pubkey>,
102    new_gating_program: Option<Pubkey>,
103    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
104}
105
106impl SetGatingProgramBuilder {
107    pub fn new() -> Self {
108        Self::default()
109    }
110    #[inline(always)]
111    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
112        self.authority = Some(authority);
113        self
114    }
115    #[inline(always)]
116    pub fn mint_config(&mut self, mint_config: solana_pubkey::Pubkey) -> &mut Self {
117        self.mint_config = Some(mint_config);
118        self
119    }
120    #[inline(always)]
121    pub fn new_gating_program(&mut self, new_gating_program: Pubkey) -> &mut Self {
122        self.new_gating_program = Some(new_gating_program);
123        self
124    }
125    /// Add an additional account to the instruction.
126    #[inline(always)]
127    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
128        self.__remaining_accounts.push(account);
129        self
130    }
131    /// Add additional accounts to the instruction.
132    #[inline(always)]
133    pub fn add_remaining_accounts(
134        &mut self,
135        accounts: &[solana_instruction::AccountMeta],
136    ) -> &mut Self {
137        self.__remaining_accounts.extend_from_slice(accounts);
138        self
139    }
140    #[allow(clippy::clone_on_copy)]
141    pub fn instruction(&self) -> solana_instruction::Instruction {
142        let accounts = SetGatingProgram {
143            authority: self.authority.expect("authority is not set"),
144            mint_config: self.mint_config.expect("mint_config is not set"),
145        };
146        let args = SetGatingProgramInstructionArgs {
147            new_gating_program: self
148                .new_gating_program
149                .clone()
150                .expect("new_gating_program is not set"),
151        };
152
153        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
154    }
155}
156
157/// `set_gating_program` CPI accounts.
158pub struct SetGatingProgramCpiAccounts<'a, 'b> {
159    pub authority: &'b solana_account_info::AccountInfo<'a>,
160
161    pub mint_config: &'b solana_account_info::AccountInfo<'a>,
162}
163
164/// `set_gating_program` CPI instruction.
165pub struct SetGatingProgramCpi<'a, 'b> {
166    /// The program to invoke.
167    pub __program: &'b solana_account_info::AccountInfo<'a>,
168
169    pub authority: &'b solana_account_info::AccountInfo<'a>,
170
171    pub mint_config: &'b solana_account_info::AccountInfo<'a>,
172    /// The arguments for the instruction.
173    pub __args: SetGatingProgramInstructionArgs,
174}
175
176impl<'a, 'b> SetGatingProgramCpi<'a, 'b> {
177    pub fn new(
178        program: &'b solana_account_info::AccountInfo<'a>,
179        accounts: SetGatingProgramCpiAccounts<'a, 'b>,
180        args: SetGatingProgramInstructionArgs,
181    ) -> Self {
182        Self {
183            __program: program,
184            authority: accounts.authority,
185            mint_config: accounts.mint_config,
186            __args: args,
187        }
188    }
189    #[inline(always)]
190    pub fn invoke(&self) -> solana_program_error::ProgramResult {
191        self.invoke_signed_with_remaining_accounts(&[], &[])
192    }
193    #[inline(always)]
194    pub fn invoke_with_remaining_accounts(
195        &self,
196        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
197    ) -> solana_program_error::ProgramResult {
198        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
199    }
200    #[inline(always)]
201    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
202        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
203    }
204    #[allow(clippy::arithmetic_side_effects)]
205    #[allow(clippy::clone_on_copy)]
206    #[allow(clippy::vec_init_then_push)]
207    pub fn invoke_signed_with_remaining_accounts(
208        &self,
209        signers_seeds: &[&[&[u8]]],
210        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
211    ) -> solana_program_error::ProgramResult {
212        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
213        accounts.push(solana_instruction::AccountMeta::new_readonly(
214            *self.authority.key,
215            true,
216        ));
217        accounts.push(solana_instruction::AccountMeta::new(
218            *self.mint_config.key,
219            false,
220        ));
221        remaining_accounts.iter().for_each(|remaining_account| {
222            accounts.push(solana_instruction::AccountMeta {
223                pubkey: *remaining_account.0.key,
224                is_signer: remaining_account.1,
225                is_writable: remaining_account.2,
226            })
227        });
228        let mut data = SetGatingProgramInstructionData::new().try_to_vec().unwrap();
229        let mut args = self.__args.try_to_vec().unwrap();
230        data.append(&mut args);
231
232        let instruction = solana_instruction::Instruction {
233            program_id: crate::TOKEN_ACL_ID,
234            accounts,
235            data,
236        };
237        let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
238        account_infos.push(self.__program.clone());
239        account_infos.push(self.authority.clone());
240        account_infos.push(self.mint_config.clone());
241        remaining_accounts
242            .iter()
243            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
244
245        if signers_seeds.is_empty() {
246            solana_cpi::invoke(&instruction, &account_infos)
247        } else {
248            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
249        }
250    }
251}
252
253/// Instruction builder for `SetGatingProgram` via CPI.
254///
255/// ### Accounts:
256///
257///   0. `[signer]` authority
258///   1. `[writable]` mint_config
259#[derive(Clone, Debug)]
260pub struct SetGatingProgramCpiBuilder<'a, 'b> {
261    instruction: Box<SetGatingProgramCpiBuilderInstruction<'a, 'b>>,
262}
263
264impl<'a, 'b> SetGatingProgramCpiBuilder<'a, 'b> {
265    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
266        let instruction = Box::new(SetGatingProgramCpiBuilderInstruction {
267            __program: program,
268            authority: None,
269            mint_config: None,
270            new_gating_program: None,
271            __remaining_accounts: Vec::new(),
272        });
273        Self { instruction }
274    }
275    #[inline(always)]
276    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
277        self.instruction.authority = Some(authority);
278        self
279    }
280    #[inline(always)]
281    pub fn mint_config(
282        &mut self,
283        mint_config: &'b solana_account_info::AccountInfo<'a>,
284    ) -> &mut Self {
285        self.instruction.mint_config = Some(mint_config);
286        self
287    }
288    #[inline(always)]
289    pub fn new_gating_program(&mut self, new_gating_program: Pubkey) -> &mut Self {
290        self.instruction.new_gating_program = Some(new_gating_program);
291        self
292    }
293    /// Add an additional account to the instruction.
294    #[inline(always)]
295    pub fn add_remaining_account(
296        &mut self,
297        account: &'b solana_account_info::AccountInfo<'a>,
298        is_writable: bool,
299        is_signer: bool,
300    ) -> &mut Self {
301        self.instruction
302            .__remaining_accounts
303            .push((account, is_writable, is_signer));
304        self
305    }
306    /// Add additional accounts to the instruction.
307    ///
308    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
309    /// and a `bool` indicating whether the account is a signer or not.
310    #[inline(always)]
311    pub fn add_remaining_accounts(
312        &mut self,
313        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
314    ) -> &mut Self {
315        self.instruction
316            .__remaining_accounts
317            .extend_from_slice(accounts);
318        self
319    }
320    #[inline(always)]
321    pub fn invoke(&self) -> solana_program_error::ProgramResult {
322        self.invoke_signed(&[])
323    }
324    #[allow(clippy::clone_on_copy)]
325    #[allow(clippy::vec_init_then_push)]
326    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
327        let args = SetGatingProgramInstructionArgs {
328            new_gating_program: self
329                .instruction
330                .new_gating_program
331                .clone()
332                .expect("new_gating_program is not set"),
333        };
334        let instruction = SetGatingProgramCpi {
335            __program: self.instruction.__program,
336
337            authority: self.instruction.authority.expect("authority is not set"),
338
339            mint_config: self
340                .instruction
341                .mint_config
342                .expect("mint_config is not set"),
343            __args: args,
344        };
345        instruction.invoke_signed_with_remaining_accounts(
346            signers_seeds,
347            &self.instruction.__remaining_accounts,
348        )
349    }
350}
351
352#[derive(Clone, Debug)]
353struct SetGatingProgramCpiBuilderInstruction<'a, 'b> {
354    __program: &'b solana_account_info::AccountInfo<'a>,
355    authority: Option<&'b solana_account_info::AccountInfo<'a>>,
356    mint_config: Option<&'b solana_account_info::AccountInfo<'a>>,
357    new_gating_program: Option<Pubkey>,
358    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
359    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
360}