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