solana_jonc_program_counter_client/generated/instructions/
create.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! <https://github.com/kinobi-so/kinobi>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12pub struct Create {
13    /// The program derived address of the counter account to create (seeds: ['counter', authority])
14    pub counter: solana_program::pubkey::Pubkey,
15    /// The authority of the counter
16    pub authority: solana_program::pubkey::Pubkey,
17    /// The account paying for the storage fees
18    pub payer: solana_program::pubkey::Pubkey,
19    /// The system program
20    pub system_program: solana_program::pubkey::Pubkey,
21}
22
23impl Create {
24    pub fn instruction(&self) -> solana_program::instruction::Instruction {
25        self.instruction_with_remaining_accounts(&[])
26    }
27    #[allow(clippy::vec_init_then_push)]
28    pub fn instruction_with_remaining_accounts(
29        &self,
30        remaining_accounts: &[solana_program::instruction::AccountMeta],
31    ) -> solana_program::instruction::Instruction {
32        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
33        accounts.push(solana_program::instruction::AccountMeta::new(
34            self.counter,
35            false,
36        ));
37        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38            self.authority,
39            true,
40        ));
41        accounts.push(solana_program::instruction::AccountMeta::new(
42            self.payer, true,
43        ));
44        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
45            self.system_program,
46            false,
47        ));
48        accounts.extend_from_slice(remaining_accounts);
49        let data = CreateInstructionData::new().try_to_vec().unwrap();
50
51        solana_program::instruction::Instruction {
52            program_id: crate::SOLANA_JONC_PROGRAM_COUNTER_ID,
53            accounts,
54            data,
55        }
56    }
57}
58
59#[derive(BorshDeserialize, BorshSerialize)]
60pub struct CreateInstructionData {
61    discriminator: u8,
62}
63
64impl CreateInstructionData {
65    pub fn new() -> Self {
66        Self { discriminator: 0 }
67    }
68}
69
70impl Default for CreateInstructionData {
71    fn default() -> Self {
72        Self::new()
73    }
74}
75
76/// Instruction builder for `Create`.
77///
78/// ### Accounts:
79///
80///   0. `[writable]` counter
81///   1. `[signer]` authority
82///   2. `[writable, signer]` payer
83///   3. `[optional]` system_program (default to `11111111111111111111111111111111`)
84#[derive(Clone, Debug, Default)]
85pub struct CreateBuilder {
86    counter: Option<solana_program::pubkey::Pubkey>,
87    authority: Option<solana_program::pubkey::Pubkey>,
88    payer: Option<solana_program::pubkey::Pubkey>,
89    system_program: Option<solana_program::pubkey::Pubkey>,
90    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
91}
92
93impl CreateBuilder {
94    pub fn new() -> Self {
95        Self::default()
96    }
97    /// The program derived address of the counter account to create (seeds: ['counter', authority])
98    #[inline(always)]
99    pub fn counter(&mut self, counter: solana_program::pubkey::Pubkey) -> &mut Self {
100        self.counter = Some(counter);
101        self
102    }
103    /// The authority of the counter
104    #[inline(always)]
105    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
106        self.authority = Some(authority);
107        self
108    }
109    /// The account paying for the storage fees
110    #[inline(always)]
111    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
112        self.payer = Some(payer);
113        self
114    }
115    /// `[optional account, default to '11111111111111111111111111111111']`
116    /// The system program
117    #[inline(always)]
118    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
119        self.system_program = Some(system_program);
120        self
121    }
122    /// Add an aditional account to the instruction.
123    #[inline(always)]
124    pub fn add_remaining_account(
125        &mut self,
126        account: solana_program::instruction::AccountMeta,
127    ) -> &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_program::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_program::instruction::Instruction {
142        let accounts = Create {
143            counter: self.counter.expect("counter is not set"),
144            authority: self.authority.expect("authority is not set"),
145            payer: self.payer.expect("payer is not set"),
146            system_program: self
147                .system_program
148                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
149        };
150
151        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
152    }
153}
154
155/// `create` CPI accounts.
156pub struct CreateCpiAccounts<'a, 'b> {
157    /// The program derived address of the counter account to create (seeds: ['counter', authority])
158    pub counter: &'b solana_program::account_info::AccountInfo<'a>,
159    /// The authority of the counter
160    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
161    /// The account paying for the storage fees
162    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
163    /// The system program
164    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
165}
166
167/// `create` CPI instruction.
168pub struct CreateCpi<'a, 'b> {
169    /// The program to invoke.
170    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
171    /// The program derived address of the counter account to create (seeds: ['counter', authority])
172    pub counter: &'b solana_program::account_info::AccountInfo<'a>,
173    /// The authority of the counter
174    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
175    /// The account paying for the storage fees
176    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
177    /// The system program
178    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
179}
180
181impl<'a, 'b> CreateCpi<'a, 'b> {
182    pub fn new(
183        program: &'b solana_program::account_info::AccountInfo<'a>,
184        accounts: CreateCpiAccounts<'a, 'b>,
185    ) -> Self {
186        Self {
187            __program: program,
188            counter: accounts.counter,
189            authority: accounts.authority,
190            payer: accounts.payer,
191            system_program: accounts.system_program,
192        }
193    }
194    #[inline(always)]
195    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
196        self.invoke_signed_with_remaining_accounts(&[], &[])
197    }
198    #[inline(always)]
199    pub fn invoke_with_remaining_accounts(
200        &self,
201        remaining_accounts: &[(
202            &'b solana_program::account_info::AccountInfo<'a>,
203            bool,
204            bool,
205        )],
206    ) -> solana_program::entrypoint::ProgramResult {
207        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
208    }
209    #[inline(always)]
210    pub fn invoke_signed(
211        &self,
212        signers_seeds: &[&[&[u8]]],
213    ) -> solana_program::entrypoint::ProgramResult {
214        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
215    }
216    #[allow(clippy::clone_on_copy)]
217    #[allow(clippy::vec_init_then_push)]
218    pub fn invoke_signed_with_remaining_accounts(
219        &self,
220        signers_seeds: &[&[&[u8]]],
221        remaining_accounts: &[(
222            &'b solana_program::account_info::AccountInfo<'a>,
223            bool,
224            bool,
225        )],
226    ) -> solana_program::entrypoint::ProgramResult {
227        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
228        accounts.push(solana_program::instruction::AccountMeta::new(
229            *self.counter.key,
230            false,
231        ));
232        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
233            *self.authority.key,
234            true,
235        ));
236        accounts.push(solana_program::instruction::AccountMeta::new(
237            *self.payer.key,
238            true,
239        ));
240        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
241            *self.system_program.key,
242            false,
243        ));
244        remaining_accounts.iter().for_each(|remaining_account| {
245            accounts.push(solana_program::instruction::AccountMeta {
246                pubkey: *remaining_account.0.key,
247                is_signer: remaining_account.1,
248                is_writable: remaining_account.2,
249            })
250        });
251        let data = CreateInstructionData::new().try_to_vec().unwrap();
252
253        let instruction = solana_program::instruction::Instruction {
254            program_id: crate::SOLANA_JONC_PROGRAM_COUNTER_ID,
255            accounts,
256            data,
257        };
258        let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
259        account_infos.push(self.__program.clone());
260        account_infos.push(self.counter.clone());
261        account_infos.push(self.authority.clone());
262        account_infos.push(self.payer.clone());
263        account_infos.push(self.system_program.clone());
264        remaining_accounts
265            .iter()
266            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
267
268        if signers_seeds.is_empty() {
269            solana_program::program::invoke(&instruction, &account_infos)
270        } else {
271            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
272        }
273    }
274}
275
276/// Instruction builder for `Create` via CPI.
277///
278/// ### Accounts:
279///
280///   0. `[writable]` counter
281///   1. `[signer]` authority
282///   2. `[writable, signer]` payer
283///   3. `[]` system_program
284#[derive(Clone, Debug)]
285pub struct CreateCpiBuilder<'a, 'b> {
286    instruction: Box<CreateCpiBuilderInstruction<'a, 'b>>,
287}
288
289impl<'a, 'b> CreateCpiBuilder<'a, 'b> {
290    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
291        let instruction = Box::new(CreateCpiBuilderInstruction {
292            __program: program,
293            counter: None,
294            authority: None,
295            payer: None,
296            system_program: None,
297            __remaining_accounts: Vec::new(),
298        });
299        Self { instruction }
300    }
301    /// The program derived address of the counter account to create (seeds: ['counter', authority])
302    #[inline(always)]
303    pub fn counter(
304        &mut self,
305        counter: &'b solana_program::account_info::AccountInfo<'a>,
306    ) -> &mut Self {
307        self.instruction.counter = Some(counter);
308        self
309    }
310    /// The authority of the counter
311    #[inline(always)]
312    pub fn authority(
313        &mut self,
314        authority: &'b solana_program::account_info::AccountInfo<'a>,
315    ) -> &mut Self {
316        self.instruction.authority = Some(authority);
317        self
318    }
319    /// The account paying for the storage fees
320    #[inline(always)]
321    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
322        self.instruction.payer = Some(payer);
323        self
324    }
325    /// The system program
326    #[inline(always)]
327    pub fn system_program(
328        &mut self,
329        system_program: &'b solana_program::account_info::AccountInfo<'a>,
330    ) -> &mut Self {
331        self.instruction.system_program = Some(system_program);
332        self
333    }
334    /// Add an additional account to the instruction.
335    #[inline(always)]
336    pub fn add_remaining_account(
337        &mut self,
338        account: &'b solana_program::account_info::AccountInfo<'a>,
339        is_writable: bool,
340        is_signer: bool,
341    ) -> &mut Self {
342        self.instruction
343            .__remaining_accounts
344            .push((account, is_writable, is_signer));
345        self
346    }
347    /// Add additional accounts to the instruction.
348    ///
349    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
350    /// and a `bool` indicating whether the account is a signer or not.
351    #[inline(always)]
352    pub fn add_remaining_accounts(
353        &mut self,
354        accounts: &[(
355            &'b solana_program::account_info::AccountInfo<'a>,
356            bool,
357            bool,
358        )],
359    ) -> &mut Self {
360        self.instruction
361            .__remaining_accounts
362            .extend_from_slice(accounts);
363        self
364    }
365    #[inline(always)]
366    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
367        self.invoke_signed(&[])
368    }
369    #[allow(clippy::clone_on_copy)]
370    #[allow(clippy::vec_init_then_push)]
371    pub fn invoke_signed(
372        &self,
373        signers_seeds: &[&[&[u8]]],
374    ) -> solana_program::entrypoint::ProgramResult {
375        let instruction = CreateCpi {
376            __program: self.instruction.__program,
377
378            counter: self.instruction.counter.expect("counter is not set"),
379
380            authority: self.instruction.authority.expect("authority is not set"),
381
382            payer: self.instruction.payer.expect("payer is not set"),
383
384            system_program: self
385                .instruction
386                .system_program
387                .expect("system_program is not set"),
388        };
389        instruction.invoke_signed_with_remaining_accounts(
390            signers_seeds,
391            &self.instruction.__remaining_accounts,
392        )
393    }
394}
395
396#[derive(Clone, Debug)]
397struct CreateCpiBuilderInstruction<'a, 'b> {
398    __program: &'b solana_program::account_info::AccountInfo<'a>,
399    counter: Option<&'b solana_program::account_info::AccountInfo<'a>>,
400    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
401    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
402    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
403    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
404    __remaining_accounts: Vec<(
405        &'b solana_program::account_info::AccountInfo<'a>,
406        bool,
407        bool,
408    )>,
409}