withdraw_nonce_account.rs 18 KB

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