solana_native_programs/system_program/generated/instructions/
initialize_nonce_account.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12pub struct InitializeNonceAccount {
14 pub nonce_account: solana_program::pubkey::Pubkey,
16 pub recent_blockhashes: solana_program::pubkey::Pubkey,
18 pub rent: solana_program::pubkey::Pubkey,
20}
21
22impl InitializeNonceAccount {
23 pub fn instruction(
24 &self,
25 args: InitializeNonceAccountInstructionArgs,
26 ) -> solana_program::instruction::Instruction {
27 self.instruction_with_remaining_accounts(args, &[])
28 }
29 #[allow(clippy::vec_init_then_push)]
30 pub fn instruction_with_remaining_accounts(
31 &self,
32 args: InitializeNonceAccountInstructionArgs,
33 remaining_accounts: &[solana_program::instruction::AccountMeta],
34 ) -> solana_program::instruction::Instruction {
35 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
36 accounts.push(solana_program::instruction::AccountMeta::new(
37 self.nonce_account,
38 false,
39 ));
40 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
41 self.recent_blockhashes,
42 false,
43 ));
44 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
45 self.rent, 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_PROGRAM_ID,
56 accounts,
57 data,
58 }
59 }
60}
61
62#[derive(BorshDeserialize, BorshSerialize)]
63struct InitializeNonceAccountInstructionData {
64 discriminator: u32,
65}
66
67impl InitializeNonceAccountInstructionData {
68 fn new() -> Self {
69 Self { discriminator: 6 }
70 }
71}
72
73#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
74#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
75pub struct InitializeNonceAccountInstructionArgs {
76 pub authority: Pubkey,
77}
78
79#[derive(Default)]
87pub struct InitializeNonceAccountBuilder {
88 nonce_account: Option<solana_program::pubkey::Pubkey>,
89 recent_blockhashes: Option<solana_program::pubkey::Pubkey>,
90 rent: Option<solana_program::pubkey::Pubkey>,
91 authority: Option<Pubkey>,
92 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
93}
94
95impl InitializeNonceAccountBuilder {
96 pub fn new() -> Self {
97 Self::default()
98 }
99 #[inline(always)]
101 pub fn nonce_account(&mut self, nonce_account: solana_program::pubkey::Pubkey) -> &mut Self {
102 self.nonce_account = Some(nonce_account);
103 self
104 }
105 #[inline(always)]
107 pub fn recent_blockhashes(
108 &mut self,
109 recent_blockhashes: solana_program::pubkey::Pubkey,
110 ) -> &mut Self {
111 self.recent_blockhashes = Some(recent_blockhashes);
112 self
113 }
114 #[inline(always)]
117 pub fn rent(&mut self, rent: solana_program::pubkey::Pubkey) -> &mut Self {
118 self.rent = Some(rent);
119 self
120 }
121 #[inline(always)]
122 pub fn authority(&mut self, authority: Pubkey) -> &mut Self {
123 self.authority = Some(authority);
124 self
125 }
126 #[inline(always)]
128 pub fn add_remaining_account(
129 &mut self,
130 account: solana_program::instruction::AccountMeta,
131 ) -> &mut Self {
132 self.__remaining_accounts.push(account);
133 self
134 }
135 #[inline(always)]
137 pub fn add_remaining_accounts(
138 &mut self,
139 accounts: &[solana_program::instruction::AccountMeta],
140 ) -> &mut Self {
141 self.__remaining_accounts.extend_from_slice(accounts);
142 self
143 }
144 #[allow(clippy::clone_on_copy)]
145 pub fn instruction(&self) -> solana_program::instruction::Instruction {
146 let accounts = InitializeNonceAccount {
147 nonce_account: self.nonce_account.expect("nonce_account is not set"),
148 recent_blockhashes: self
149 .recent_blockhashes
150 .expect("recent_blockhashes is not set"),
151 rent: self.rent.unwrap_or(solana_program::pubkey!(
152 "SysvarRent111111111111111111111111111111111"
153 )),
154 };
155 let args = InitializeNonceAccountInstructionArgs {
156 authority: self.authority.clone().expect("authority is not set"),
157 };
158
159 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
160 }
161}
162
163pub struct InitializeNonceAccountCpiAccounts<'a, 'b> {
165 pub nonce_account: &'b solana_program::account_info::AccountInfo<'a>,
167 pub recent_blockhashes: &'b solana_program::account_info::AccountInfo<'a>,
169 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
171}
172
173pub struct InitializeNonceAccountCpi<'a, 'b> {
175 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
177 pub nonce_account: &'b solana_program::account_info::AccountInfo<'a>,
179 pub recent_blockhashes: &'b solana_program::account_info::AccountInfo<'a>,
181 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
183 pub __args: InitializeNonceAccountInstructionArgs,
185}
186
187impl<'a, 'b> InitializeNonceAccountCpi<'a, 'b> {
188 pub fn new(
189 program: &'b solana_program::account_info::AccountInfo<'a>,
190 accounts: InitializeNonceAccountCpiAccounts<'a, 'b>,
191 args: InitializeNonceAccountInstructionArgs,
192 ) -> Self {
193 Self {
194 __program: program,
195 nonce_account: accounts.nonce_account,
196 recent_blockhashes: accounts.recent_blockhashes,
197 rent: accounts.rent,
198 __args: args,
199 }
200 }
201 #[inline(always)]
202 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
203 self.invoke_signed_with_remaining_accounts(&[], &[])
204 }
205 #[inline(always)]
206 pub fn invoke_with_remaining_accounts(
207 &self,
208 remaining_accounts: &[(
209 &'b solana_program::account_info::AccountInfo<'a>,
210 bool,
211 bool,
212 )],
213 ) -> solana_program::entrypoint::ProgramResult {
214 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
215 }
216 #[inline(always)]
217 pub fn invoke_signed(
218 &self,
219 signers_seeds: &[&[&[u8]]],
220 ) -> solana_program::entrypoint::ProgramResult {
221 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
222 }
223 #[allow(clippy::clone_on_copy)]
224 #[allow(clippy::vec_init_then_push)]
225 pub fn invoke_signed_with_remaining_accounts(
226 &self,
227 signers_seeds: &[&[&[u8]]],
228 remaining_accounts: &[(
229 &'b solana_program::account_info::AccountInfo<'a>,
230 bool,
231 bool,
232 )],
233 ) -> solana_program::entrypoint::ProgramResult {
234 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
235 accounts.push(solana_program::instruction::AccountMeta::new(
236 *self.nonce_account.key,
237 false,
238 ));
239 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
240 *self.recent_blockhashes.key,
241 false,
242 ));
243 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
244 *self.rent.key,
245 false,
246 ));
247 remaining_accounts.iter().for_each(|remaining_account| {
248 accounts.push(solana_program::instruction::AccountMeta {
249 pubkey: *remaining_account.0.key,
250 is_signer: remaining_account.1,
251 is_writable: remaining_account.2,
252 })
253 });
254 let mut data = InitializeNonceAccountInstructionData::new()
255 .try_to_vec()
256 .unwrap();
257 let mut args = self.__args.try_to_vec().unwrap();
258 data.append(&mut args);
259
260 let instruction = solana_program::instruction::Instruction {
261 program_id: crate::SYSTEM_PROGRAM_ID,
262 accounts,
263 data,
264 };
265 let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
266 account_infos.push(self.__program.clone());
267 account_infos.push(self.nonce_account.clone());
268 account_infos.push(self.recent_blockhashes.clone());
269 account_infos.push(self.rent.clone());
270 remaining_accounts
271 .iter()
272 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
273
274 if signers_seeds.is_empty() {
275 solana_program::program::invoke(&instruction, &account_infos)
276 } else {
277 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
278 }
279 }
280}
281
282pub struct InitializeNonceAccountCpiBuilder<'a, 'b> {
290 instruction: Box<InitializeNonceAccountCpiBuilderInstruction<'a, 'b>>,
291}
292
293impl<'a, 'b> InitializeNonceAccountCpiBuilder<'a, 'b> {
294 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
295 let instruction = Box::new(InitializeNonceAccountCpiBuilderInstruction {
296 __program: program,
297 nonce_account: None,
298 recent_blockhashes: None,
299 rent: None,
300 authority: None,
301 __remaining_accounts: Vec::new(),
302 });
303 Self { instruction }
304 }
305 #[inline(always)]
307 pub fn nonce_account(
308 &mut self,
309 nonce_account: &'b solana_program::account_info::AccountInfo<'a>,
310 ) -> &mut Self {
311 self.instruction.nonce_account = Some(nonce_account);
312 self
313 }
314 #[inline(always)]
316 pub fn recent_blockhashes(
317 &mut self,
318 recent_blockhashes: &'b solana_program::account_info::AccountInfo<'a>,
319 ) -> &mut Self {
320 self.instruction.recent_blockhashes = Some(recent_blockhashes);
321 self
322 }
323 #[inline(always)]
325 pub fn rent(&mut self, rent: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
326 self.instruction.rent = Some(rent);
327 self
328 }
329 #[inline(always)]
330 pub fn authority(&mut self, authority: Pubkey) -> &mut Self {
331 self.instruction.authority = Some(authority);
332 self
333 }
334 #[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 #[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 args = InitializeNonceAccountInstructionArgs {
376 authority: self
377 .instruction
378 .authority
379 .clone()
380 .expect("authority is not set"),
381 };
382 let instruction = InitializeNonceAccountCpi {
383 __program: self.instruction.__program,
384
385 nonce_account: self
386 .instruction
387 .nonce_account
388 .expect("nonce_account is not set"),
389
390 recent_blockhashes: self
391 .instruction
392 .recent_blockhashes
393 .expect("recent_blockhashes is not set"),
394
395 rent: self.instruction.rent.expect("rent is not set"),
396 __args: args,
397 };
398 instruction.invoke_signed_with_remaining_accounts(
399 signers_seeds,
400 &self.instruction.__remaining_accounts,
401 )
402 }
403}
404
405struct InitializeNonceAccountCpiBuilderInstruction<'a, 'b> {
406 __program: &'b solana_program::account_info::AccountInfo<'a>,
407 nonce_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
408 recent_blockhashes: Option<&'b solana_program::account_info::AccountInfo<'a>>,
409 rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
410 authority: Option<Pubkey>,
411 __remaining_accounts: Vec<(
413 &'b solana_program::account_info::AccountInfo<'a>,
414 bool,
415 bool,
416 )>,
417}