Skip to main content

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