1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct WithdrawNonceAccount {
13 pub nonce_account: solana_program::pubkey::Pubkey,
15 pub recipient_account: solana_program::pubkey::Pubkey,
17 pub recent_blockhashes: solana_program::pubkey::Pubkey,
19 pub rent: solana_program::pubkey::Pubkey,
21 pub nonce_authority: solana_program::pubkey::Pubkey,
23}
24
25impl WithdrawNonceAccount {
26 pub fn instruction(
27 &self,
28 args: WithdrawNonceAccountInstructionArgs,
29 ) -> solana_program::instruction::Instruction {
30 self.instruction_with_remaining_accounts(args, &[])
31 }
32 #[allow(clippy::vec_init_then_push)]
33 pub fn instruction_with_remaining_accounts(
34 &self,
35 args: WithdrawNonceAccountInstructionArgs,
36 remaining_accounts: &[solana_program::instruction::AccountMeta],
37 ) -> solana_program::instruction::Instruction {
38 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
39 accounts.push(solana_program::instruction::AccountMeta::new(
40 self.nonce_account,
41 false,
42 ));
43 accounts.push(solana_program::instruction::AccountMeta::new(
44 self.recipient_account,
45 false,
46 ));
47 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
48 self.recent_blockhashes,
49 false,
50 ));
51 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
52 self.rent, false,
53 ));
54 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
55 self.nonce_authority,
56 true,
57 ));
58 accounts.extend_from_slice(remaining_accounts);
59 let mut data = WithdrawNonceAccountInstructionData::new()
60 .try_to_vec()
61 .unwrap();
62 let mut args = args.try_to_vec().unwrap();
63 data.append(&mut args);
64
65 solana_program::instruction::Instruction {
66 program_id: crate::SYSTEM_PROGRAM_ID,
67 accounts,
68 data,
69 }
70 }
71}
72
73#[derive(BorshDeserialize, BorshSerialize)]
74struct WithdrawNonceAccountInstructionData {
75 discriminator: u32,
76}
77
78impl WithdrawNonceAccountInstructionData {
79 fn new() -> Self {
80 Self { discriminator: 5 }
81 }
82}
83
84#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
85#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
86pub struct WithdrawNonceAccountInstructionArgs {
87 pub lamports: u64,
88}
89
90#[derive(Default)]
100pub struct WithdrawNonceAccountBuilder {
101 nonce_account: Option<solana_program::pubkey::Pubkey>,
102 recipient_account: Option<solana_program::pubkey::Pubkey>,
103 recent_blockhashes: Option<solana_program::pubkey::Pubkey>,
104 rent: Option<solana_program::pubkey::Pubkey>,
105 nonce_authority: Option<solana_program::pubkey::Pubkey>,
106 lamports: Option<u64>,
107 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
108}
109
110impl WithdrawNonceAccountBuilder {
111 pub fn new() -> Self {
112 Self::default()
113 }
114 #[inline(always)]
116 pub fn nonce_account(&mut self, nonce_account: solana_program::pubkey::Pubkey) -> &mut Self {
117 self.nonce_account = Some(nonce_account);
118 self
119 }
120 #[inline(always)]
122 pub fn recipient_account(
123 &mut self,
124 recipient_account: solana_program::pubkey::Pubkey,
125 ) -> &mut Self {
126 self.recipient_account = Some(recipient_account);
127 self
128 }
129 #[inline(always)]
131 pub fn recent_blockhashes(
132 &mut self,
133 recent_blockhashes: solana_program::pubkey::Pubkey,
134 ) -> &mut Self {
135 self.recent_blockhashes = Some(recent_blockhashes);
136 self
137 }
138 #[inline(always)]
141 pub fn rent(&mut self, rent: solana_program::pubkey::Pubkey) -> &mut Self {
142 self.rent = Some(rent);
143 self
144 }
145 #[inline(always)]
147 pub fn nonce_authority(
148 &mut self,
149 nonce_authority: solana_program::pubkey::Pubkey,
150 ) -> &mut Self {
151 self.nonce_authority = Some(nonce_authority);
152 self
153 }
154 #[inline(always)]
155 pub fn lamports(&mut self, lamports: u64) -> &mut Self {
156 self.lamports = Some(lamports);
157 self
158 }
159 #[inline(always)]
161 pub fn add_remaining_account(
162 &mut self,
163 account: solana_program::instruction::AccountMeta,
164 ) -> &mut Self {
165 self.__remaining_accounts.push(account);
166 self
167 }
168 #[inline(always)]
170 pub fn add_remaining_accounts(
171 &mut self,
172 accounts: &[solana_program::instruction::AccountMeta],
173 ) -> &mut Self {
174 self.__remaining_accounts.extend_from_slice(accounts);
175 self
176 }
177 #[allow(clippy::clone_on_copy)]
178 pub fn instruction(&self) -> solana_program::instruction::Instruction {
179 let accounts = WithdrawNonceAccount {
180 nonce_account: self.nonce_account.expect("nonce_account is not set"),
181 recipient_account: self
182 .recipient_account
183 .expect("recipient_account is not set"),
184 recent_blockhashes: self
185 .recent_blockhashes
186 .expect("recent_blockhashes is not set"),
187 rent: self.rent.unwrap_or(solana_program::pubkey!(
188 "SysvarRent111111111111111111111111111111111"
189 )),
190 nonce_authority: self.nonce_authority.expect("nonce_authority is not set"),
191 };
192 let args = WithdrawNonceAccountInstructionArgs {
193 lamports: self.lamports.clone().expect("lamports is not set"),
194 };
195
196 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
197 }
198}
199
200pub struct WithdrawNonceAccountCpiAccounts<'a, 'b> {
202 pub nonce_account: &'b solana_program::account_info::AccountInfo<'a>,
204 pub recipient_account: &'b solana_program::account_info::AccountInfo<'a>,
206 pub recent_blockhashes: &'b solana_program::account_info::AccountInfo<'a>,
208 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
210 pub nonce_authority: &'b solana_program::account_info::AccountInfo<'a>,
212}
213
214pub struct WithdrawNonceAccountCpi<'a, 'b> {
216 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
218 pub nonce_account: &'b solana_program::account_info::AccountInfo<'a>,
220 pub recipient_account: &'b solana_program::account_info::AccountInfo<'a>,
222 pub recent_blockhashes: &'b solana_program::account_info::AccountInfo<'a>,
224 pub rent: &'b solana_program::account_info::AccountInfo<'a>,
226 pub nonce_authority: &'b solana_program::account_info::AccountInfo<'a>,
228 pub __args: WithdrawNonceAccountInstructionArgs,
230}
231
232impl<'a, 'b> WithdrawNonceAccountCpi<'a, 'b> {
233 pub fn new(
234 program: &'b solana_program::account_info::AccountInfo<'a>,
235 accounts: WithdrawNonceAccountCpiAccounts<'a, 'b>,
236 args: WithdrawNonceAccountInstructionArgs,
237 ) -> Self {
238 Self {
239 __program: program,
240 nonce_account: accounts.nonce_account,
241 recipient_account: accounts.recipient_account,
242 recent_blockhashes: accounts.recent_blockhashes,
243 rent: accounts.rent,
244 nonce_authority: accounts.nonce_authority,
245 __args: args,
246 }
247 }
248 #[inline(always)]
249 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
250 self.invoke_signed_with_remaining_accounts(&[], &[])
251 }
252 #[inline(always)]
253 pub fn invoke_with_remaining_accounts(
254 &self,
255 remaining_accounts: &[(
256 &'b solana_program::account_info::AccountInfo<'a>,
257 bool,
258 bool,
259 )],
260 ) -> solana_program::entrypoint::ProgramResult {
261 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
262 }
263 #[inline(always)]
264 pub fn invoke_signed(
265 &self,
266 signers_seeds: &[&[&[u8]]],
267 ) -> solana_program::entrypoint::ProgramResult {
268 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
269 }
270 #[allow(clippy::clone_on_copy)]
271 #[allow(clippy::vec_init_then_push)]
272 pub fn invoke_signed_with_remaining_accounts(
273 &self,
274 signers_seeds: &[&[&[u8]]],
275 remaining_accounts: &[(
276 &'b solana_program::account_info::AccountInfo<'a>,
277 bool,
278 bool,
279 )],
280 ) -> solana_program::entrypoint::ProgramResult {
281 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
282 accounts.push(solana_program::instruction::AccountMeta::new(
283 *self.nonce_account.key,
284 false,
285 ));
286 accounts.push(solana_program::instruction::AccountMeta::new(
287 *self.recipient_account.key,
288 false,
289 ));
290 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
291 *self.recent_blockhashes.key,
292 false,
293 ));
294 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
295 *self.rent.key,
296 false,
297 ));
298 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
299 *self.nonce_authority.key,
300 true,
301 ));
302 remaining_accounts.iter().for_each(|remaining_account| {
303 accounts.push(solana_program::instruction::AccountMeta {
304 pubkey: *remaining_account.0.key,
305 is_signer: remaining_account.1,
306 is_writable: remaining_account.2,
307 })
308 });
309 let mut data = WithdrawNonceAccountInstructionData::new()
310 .try_to_vec()
311 .unwrap();
312 let mut args = self.__args.try_to_vec().unwrap();
313 data.append(&mut args);
314
315 let instruction = solana_program::instruction::Instruction {
316 program_id: crate::SYSTEM_PROGRAM_ID,
317 accounts,
318 data,
319 };
320 let mut account_infos = Vec::with_capacity(5 + 1 + remaining_accounts.len());
321 account_infos.push(self.__program.clone());
322 account_infos.push(self.nonce_account.clone());
323 account_infos.push(self.recipient_account.clone());
324 account_infos.push(self.recent_blockhashes.clone());
325 account_infos.push(self.rent.clone());
326 account_infos.push(self.nonce_authority.clone());
327 remaining_accounts
328 .iter()
329 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
330
331 if signers_seeds.is_empty() {
332 solana_program::program::invoke(&instruction, &account_infos)
333 } else {
334 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
335 }
336 }
337}
338
339pub struct WithdrawNonceAccountCpiBuilder<'a, 'b> {
349 instruction: Box<WithdrawNonceAccountCpiBuilderInstruction<'a, 'b>>,
350}
351
352impl<'a, 'b> WithdrawNonceAccountCpiBuilder<'a, 'b> {
353 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
354 let instruction = Box::new(WithdrawNonceAccountCpiBuilderInstruction {
355 __program: program,
356 nonce_account: None,
357 recipient_account: None,
358 recent_blockhashes: None,
359 rent: None,
360 nonce_authority: None,
361 lamports: None,
362 __remaining_accounts: Vec::new(),
363 });
364 Self { instruction }
365 }
366 #[inline(always)]
368 pub fn nonce_account(
369 &mut self,
370 nonce_account: &'b solana_program::account_info::AccountInfo<'a>,
371 ) -> &mut Self {
372 self.instruction.nonce_account = Some(nonce_account);
373 self
374 }
375 #[inline(always)]
377 pub fn recipient_account(
378 &mut self,
379 recipient_account: &'b solana_program::account_info::AccountInfo<'a>,
380 ) -> &mut Self {
381 self.instruction.recipient_account = Some(recipient_account);
382 self
383 }
384 #[inline(always)]
386 pub fn recent_blockhashes(
387 &mut self,
388 recent_blockhashes: &'b solana_program::account_info::AccountInfo<'a>,
389 ) -> &mut Self {
390 self.instruction.recent_blockhashes = Some(recent_blockhashes);
391 self
392 }
393 #[inline(always)]
395 pub fn rent(&mut self, rent: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
396 self.instruction.rent = Some(rent);
397 self
398 }
399 #[inline(always)]
401 pub fn nonce_authority(
402 &mut self,
403 nonce_authority: &'b solana_program::account_info::AccountInfo<'a>,
404 ) -> &mut Self {
405 self.instruction.nonce_authority = Some(nonce_authority);
406 self
407 }
408 #[inline(always)]
409 pub fn lamports(&mut self, lamports: u64) -> &mut Self {
410 self.instruction.lamports = Some(lamports);
411 self
412 }
413 #[inline(always)]
415 pub fn add_remaining_account(
416 &mut self,
417 account: &'b solana_program::account_info::AccountInfo<'a>,
418 is_writable: bool,
419 is_signer: bool,
420 ) -> &mut Self {
421 self.instruction
422 .__remaining_accounts
423 .push((account, is_writable, is_signer));
424 self
425 }
426 #[inline(always)]
431 pub fn add_remaining_accounts(
432 &mut self,
433 accounts: &[(
434 &'b solana_program::account_info::AccountInfo<'a>,
435 bool,
436 bool,
437 )],
438 ) -> &mut Self {
439 self.instruction
440 .__remaining_accounts
441 .extend_from_slice(accounts);
442 self
443 }
444 #[inline(always)]
445 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
446 self.invoke_signed(&[])
447 }
448 #[allow(clippy::clone_on_copy)]
449 #[allow(clippy::vec_init_then_push)]
450 pub fn invoke_signed(
451 &self,
452 signers_seeds: &[&[&[u8]]],
453 ) -> solana_program::entrypoint::ProgramResult {
454 let args = WithdrawNonceAccountInstructionArgs {
455 lamports: self
456 .instruction
457 .lamports
458 .clone()
459 .expect("lamports is not set"),
460 };
461 let instruction = WithdrawNonceAccountCpi {
462 __program: self.instruction.__program,
463
464 nonce_account: self
465 .instruction
466 .nonce_account
467 .expect("nonce_account is not set"),
468
469 recipient_account: self
470 .instruction
471 .recipient_account
472 .expect("recipient_account is not set"),
473
474 recent_blockhashes: self
475 .instruction
476 .recent_blockhashes
477 .expect("recent_blockhashes is not set"),
478
479 rent: self.instruction.rent.expect("rent is not set"),
480
481 nonce_authority: self
482 .instruction
483 .nonce_authority
484 .expect("nonce_authority is not set"),
485 __args: args,
486 };
487 instruction.invoke_signed_with_remaining_accounts(
488 signers_seeds,
489 &self.instruction.__remaining_accounts,
490 )
491 }
492}
493
494struct WithdrawNonceAccountCpiBuilderInstruction<'a, 'b> {
495 __program: &'b solana_program::account_info::AccountInfo<'a>,
496 nonce_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
497 recipient_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
498 recent_blockhashes: Option<&'b solana_program::account_info::AccountInfo<'a>>,
499 rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
500 nonce_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
501 lamports: Option<u64>,
502 __remaining_accounts: Vec<(
504 &'b solana_program::account_info::AccountInfo<'a>,
505 bool,
506 bool,
507 )>,
508}