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