Skip to main content

release_test_client/generated/instructions/
add_entry.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_program::pubkey::Pubkey;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct AddEntry {
15    /// The whitelist account
16    pub whitelist_account: solana_program::pubkey::Pubkey,
17    /// The whitelist authority
18    pub whitelist_authority: solana_program::pubkey::Pubkey,
19    /// The whitelist entry account
20    pub whitelist_entry_account: solana_program::pubkey::Pubkey,
21    /// Payer account (must be a system account)
22    pub payer: solana_program::pubkey::Pubkey,
23    /// System program
24    pub system_program: solana_program::pubkey::Pubkey,
25}
26
27impl AddEntry {
28    pub fn instruction(
29        &self,
30        args: AddEntryInstructionArgs,
31    ) -> solana_program::instruction::Instruction {
32        self.instruction_with_remaining_accounts(args, &[])
33    }
34    #[allow(clippy::vec_init_then_push)]
35    pub fn instruction_with_remaining_accounts(
36        &self,
37        args: AddEntryInstructionArgs,
38        remaining_accounts: &[solana_program::instruction::AccountMeta],
39    ) -> solana_program::instruction::Instruction {
40        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
41        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42            self.whitelist_account,
43            false,
44        ));
45        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
46            self.whitelist_authority,
47            true,
48        ));
49        accounts.push(solana_program::instruction::AccountMeta::new(
50            self.whitelist_entry_account,
51            false,
52        ));
53        accounts.push(solana_program::instruction::AccountMeta::new(
54            self.payer, true,
55        ));
56        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
57            self.system_program,
58            false,
59        ));
60        accounts.extend_from_slice(remaining_accounts);
61        let mut data = borsh::to_vec(&AddEntryInstructionData::new()).unwrap();
62        let mut args = borsh::to_vec(&args).unwrap();
63        data.append(&mut args);
64
65        solana_program::instruction::Instruction {
66            program_id: crate::RELEASE_TEST_PROGRAM_ID,
67            accounts,
68            data,
69        }
70    }
71}
72
73#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
74#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
75pub struct AddEntryInstructionData {
76    discriminator: u8,
77}
78
79impl AddEntryInstructionData {
80    pub fn new() -> Self {
81        Self { discriminator: 4 }
82    }
83}
84
85impl Default for AddEntryInstructionData {
86    fn default() -> Self {
87        Self::new()
88    }
89}
90
91#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93pub struct AddEntryInstructionArgs {
94    pub program_authority: Pubkey,
95}
96
97/// Instruction builder for `AddEntry`.
98///
99/// ### Accounts:
100///
101///   0. `[]` whitelist_account
102///   1. `[signer]` whitelist_authority
103///   2. `[writable]` whitelist_entry_account
104///   3. `[writable, signer]` payer
105///   4. `[optional]` system_program (default to `11111111111111111111111111111111`)
106#[derive(Clone, Debug, Default)]
107pub struct AddEntryBuilder {
108    whitelist_account: Option<solana_program::pubkey::Pubkey>,
109    whitelist_authority: Option<solana_program::pubkey::Pubkey>,
110    whitelist_entry_account: Option<solana_program::pubkey::Pubkey>,
111    payer: Option<solana_program::pubkey::Pubkey>,
112    system_program: Option<solana_program::pubkey::Pubkey>,
113    program_authority: Option<Pubkey>,
114    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
115}
116
117impl AddEntryBuilder {
118    pub fn new() -> Self {
119        Self::default()
120    }
121    /// The whitelist account
122    #[inline(always)]
123    pub fn whitelist_account(
124        &mut self,
125        whitelist_account: solana_program::pubkey::Pubkey,
126    ) -> &mut Self {
127        self.whitelist_account = Some(whitelist_account);
128        self
129    }
130    /// The whitelist authority
131    #[inline(always)]
132    pub fn whitelist_authority(
133        &mut self,
134        whitelist_authority: solana_program::pubkey::Pubkey,
135    ) -> &mut Self {
136        self.whitelist_authority = Some(whitelist_authority);
137        self
138    }
139    /// The whitelist entry account
140    #[inline(always)]
141    pub fn whitelist_entry_account(
142        &mut self,
143        whitelist_entry_account: solana_program::pubkey::Pubkey,
144    ) -> &mut Self {
145        self.whitelist_entry_account = Some(whitelist_entry_account);
146        self
147    }
148    /// Payer account (must be a system account)
149    #[inline(always)]
150    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
151        self.payer = Some(payer);
152        self
153    }
154    /// `[optional account, default to '11111111111111111111111111111111']`
155    /// System program
156    #[inline(always)]
157    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
158        self.system_program = Some(system_program);
159        self
160    }
161    #[inline(always)]
162    pub fn program_authority(&mut self, program_authority: Pubkey) -> &mut Self {
163        self.program_authority = Some(program_authority);
164        self
165    }
166    /// Add an additional account to the instruction.
167    #[inline(always)]
168    pub fn add_remaining_account(
169        &mut self,
170        account: solana_program::instruction::AccountMeta,
171    ) -> &mut Self {
172        self.__remaining_accounts.push(account);
173        self
174    }
175    /// Add additional accounts to the instruction.
176    #[inline(always)]
177    pub fn add_remaining_accounts(
178        &mut self,
179        accounts: &[solana_program::instruction::AccountMeta],
180    ) -> &mut Self {
181        self.__remaining_accounts.extend_from_slice(accounts);
182        self
183    }
184    #[allow(clippy::clone_on_copy)]
185    pub fn instruction(&self) -> solana_program::instruction::Instruction {
186        let accounts = AddEntry {
187            whitelist_account: self
188                .whitelist_account
189                .expect("whitelist_account is not set"),
190            whitelist_authority: self
191                .whitelist_authority
192                .expect("whitelist_authority is not set"),
193            whitelist_entry_account: self
194                .whitelist_entry_account
195                .expect("whitelist_entry_account is not set"),
196            payer: self.payer.expect("payer is not set"),
197            system_program: self
198                .system_program
199                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
200        };
201        let args = AddEntryInstructionArgs {
202            program_authority: self
203                .program_authority
204                .clone()
205                .expect("program_authority is not set"),
206        };
207
208        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
209    }
210}
211
212/// `add_entry` CPI accounts.
213pub struct AddEntryCpiAccounts<'a, 'b> {
214    /// The whitelist account
215    pub whitelist_account: &'b solana_program::account_info::AccountInfo<'a>,
216    /// The whitelist authority
217    pub whitelist_authority: &'b solana_program::account_info::AccountInfo<'a>,
218    /// The whitelist entry account
219    pub whitelist_entry_account: &'b solana_program::account_info::AccountInfo<'a>,
220    /// Payer account (must be a system account)
221    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
222    /// System program
223    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
224}
225
226/// `add_entry` CPI instruction.
227pub struct AddEntryCpi<'a, 'b> {
228    /// The program to invoke.
229    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
230    /// The whitelist account
231    pub whitelist_account: &'b solana_program::account_info::AccountInfo<'a>,
232    /// The whitelist authority
233    pub whitelist_authority: &'b solana_program::account_info::AccountInfo<'a>,
234    /// The whitelist entry account
235    pub whitelist_entry_account: &'b solana_program::account_info::AccountInfo<'a>,
236    /// Payer account (must be a system account)
237    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
238    /// System program
239    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
240    /// The arguments for the instruction.
241    pub __args: AddEntryInstructionArgs,
242}
243
244impl<'a, 'b> AddEntryCpi<'a, 'b> {
245    pub fn new(
246        program: &'b solana_program::account_info::AccountInfo<'a>,
247        accounts: AddEntryCpiAccounts<'a, 'b>,
248        args: AddEntryInstructionArgs,
249    ) -> Self {
250        Self {
251            __program: program,
252            whitelist_account: accounts.whitelist_account,
253            whitelist_authority: accounts.whitelist_authority,
254            whitelist_entry_account: accounts.whitelist_entry_account,
255            payer: accounts.payer,
256            system_program: accounts.system_program,
257            __args: args,
258        }
259    }
260    #[inline(always)]
261    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
262        self.invoke_signed_with_remaining_accounts(&[], &[])
263    }
264    #[inline(always)]
265    pub fn invoke_with_remaining_accounts(
266        &self,
267        remaining_accounts: &[(
268            &'b solana_program::account_info::AccountInfo<'a>,
269            bool,
270            bool,
271        )],
272    ) -> solana_program::entrypoint::ProgramResult {
273        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
274    }
275    #[inline(always)]
276    pub fn invoke_signed(
277        &self,
278        signers_seeds: &[&[&[u8]]],
279    ) -> solana_program::entrypoint::ProgramResult {
280        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
281    }
282    #[allow(clippy::clone_on_copy)]
283    #[allow(clippy::vec_init_then_push)]
284    pub fn invoke_signed_with_remaining_accounts(
285        &self,
286        signers_seeds: &[&[&[u8]]],
287        remaining_accounts: &[(
288            &'b solana_program::account_info::AccountInfo<'a>,
289            bool,
290            bool,
291        )],
292    ) -> solana_program::entrypoint::ProgramResult {
293        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
294        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
295            *self.whitelist_account.key,
296            false,
297        ));
298        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
299            *self.whitelist_authority.key,
300            true,
301        ));
302        accounts.push(solana_program::instruction::AccountMeta::new(
303            *self.whitelist_entry_account.key,
304            false,
305        ));
306        accounts.push(solana_program::instruction::AccountMeta::new(
307            *self.payer.key,
308            true,
309        ));
310        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
311            *self.system_program.key,
312            false,
313        ));
314        remaining_accounts.iter().for_each(|remaining_account| {
315            accounts.push(solana_program::instruction::AccountMeta {
316                pubkey: *remaining_account.0.key,
317                is_signer: remaining_account.1,
318                is_writable: remaining_account.2,
319            })
320        });
321        let mut data = borsh::to_vec(&AddEntryInstructionData::new()).unwrap();
322        let mut args = borsh::to_vec(&self.__args).unwrap();
323        data.append(&mut args);
324
325        let instruction = solana_program::instruction::Instruction {
326            program_id: crate::RELEASE_TEST_PROGRAM_ID,
327            accounts,
328            data,
329        };
330        let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len());
331        account_infos.push(self.__program.clone());
332        account_infos.push(self.whitelist_account.clone());
333        account_infos.push(self.whitelist_authority.clone());
334        account_infos.push(self.whitelist_entry_account.clone());
335        account_infos.push(self.payer.clone());
336        account_infos.push(self.system_program.clone());
337        remaining_accounts
338            .iter()
339            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
340
341        if signers_seeds.is_empty() {
342            solana_program::program::invoke(&instruction, &account_infos)
343        } else {
344            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
345        }
346    }
347}
348
349/// Instruction builder for `AddEntry` via CPI.
350///
351/// ### Accounts:
352///
353///   0. `[]` whitelist_account
354///   1. `[signer]` whitelist_authority
355///   2. `[writable]` whitelist_entry_account
356///   3. `[writable, signer]` payer
357///   4. `[]` system_program
358#[derive(Clone, Debug)]
359pub struct AddEntryCpiBuilder<'a, 'b> {
360    instruction: Box<AddEntryCpiBuilderInstruction<'a, 'b>>,
361}
362
363impl<'a, 'b> AddEntryCpiBuilder<'a, 'b> {
364    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
365        let instruction = Box::new(AddEntryCpiBuilderInstruction {
366            __program: program,
367            whitelist_account: None,
368            whitelist_authority: None,
369            whitelist_entry_account: None,
370            payer: None,
371            system_program: None,
372            program_authority: None,
373            __remaining_accounts: Vec::new(),
374        });
375        Self { instruction }
376    }
377    /// The whitelist account
378    #[inline(always)]
379    pub fn whitelist_account(
380        &mut self,
381        whitelist_account: &'b solana_program::account_info::AccountInfo<'a>,
382    ) -> &mut Self {
383        self.instruction.whitelist_account = Some(whitelist_account);
384        self
385    }
386    /// The whitelist authority
387    #[inline(always)]
388    pub fn whitelist_authority(
389        &mut self,
390        whitelist_authority: &'b solana_program::account_info::AccountInfo<'a>,
391    ) -> &mut Self {
392        self.instruction.whitelist_authority = Some(whitelist_authority);
393        self
394    }
395    /// The whitelist entry account
396    #[inline(always)]
397    pub fn whitelist_entry_account(
398        &mut self,
399        whitelist_entry_account: &'b solana_program::account_info::AccountInfo<'a>,
400    ) -> &mut Self {
401        self.instruction.whitelist_entry_account = Some(whitelist_entry_account);
402        self
403    }
404    /// Payer account (must be a system account)
405    #[inline(always)]
406    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
407        self.instruction.payer = Some(payer);
408        self
409    }
410    /// System program
411    #[inline(always)]
412    pub fn system_program(
413        &mut self,
414        system_program: &'b solana_program::account_info::AccountInfo<'a>,
415    ) -> &mut Self {
416        self.instruction.system_program = Some(system_program);
417        self
418    }
419    #[inline(always)]
420    pub fn program_authority(&mut self, program_authority: Pubkey) -> &mut Self {
421        self.instruction.program_authority = Some(program_authority);
422        self
423    }
424    /// Add an additional account to the instruction.
425    #[inline(always)]
426    pub fn add_remaining_account(
427        &mut self,
428        account: &'b solana_program::account_info::AccountInfo<'a>,
429        is_writable: bool,
430        is_signer: bool,
431    ) -> &mut Self {
432        self.instruction
433            .__remaining_accounts
434            .push((account, is_writable, is_signer));
435        self
436    }
437    /// Add additional accounts to the instruction.
438    ///
439    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
440    /// and a `bool` indicating whether the account is a signer or not.
441    #[inline(always)]
442    pub fn add_remaining_accounts(
443        &mut self,
444        accounts: &[(
445            &'b solana_program::account_info::AccountInfo<'a>,
446            bool,
447            bool,
448        )],
449    ) -> &mut Self {
450        self.instruction
451            .__remaining_accounts
452            .extend_from_slice(accounts);
453        self
454    }
455    #[inline(always)]
456    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
457        self.invoke_signed(&[])
458    }
459    #[allow(clippy::clone_on_copy)]
460    #[allow(clippy::vec_init_then_push)]
461    pub fn invoke_signed(
462        &self,
463        signers_seeds: &[&[&[u8]]],
464    ) -> solana_program::entrypoint::ProgramResult {
465        let args = AddEntryInstructionArgs {
466            program_authority: self
467                .instruction
468                .program_authority
469                .clone()
470                .expect("program_authority is not set"),
471        };
472        let instruction = AddEntryCpi {
473            __program: self.instruction.__program,
474
475            whitelist_account: self
476                .instruction
477                .whitelist_account
478                .expect("whitelist_account is not set"),
479
480            whitelist_authority: self
481                .instruction
482                .whitelist_authority
483                .expect("whitelist_authority is not set"),
484
485            whitelist_entry_account: self
486                .instruction
487                .whitelist_entry_account
488                .expect("whitelist_entry_account is not set"),
489
490            payer: self.instruction.payer.expect("payer is not set"),
491
492            system_program: self
493                .instruction
494                .system_program
495                .expect("system_program is not set"),
496            __args: args,
497        };
498        instruction.invoke_signed_with_remaining_accounts(
499            signers_seeds,
500            &self.instruction.__remaining_accounts,
501        )
502    }
503}
504
505#[derive(Clone, Debug)]
506struct AddEntryCpiBuilderInstruction<'a, 'b> {
507    __program: &'b solana_program::account_info::AccountInfo<'a>,
508    whitelist_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
509    whitelist_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
510    whitelist_entry_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
511    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
512    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
513    program_authority: Option<Pubkey>,
514    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
515    __remaining_accounts: Vec<(
516        &'b solana_program::account_info::AccountInfo<'a>,
517        bool,
518        bool,
519    )>,
520}