authorize_nonce_account.rs 13 KB

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