allocate_with_seed.rs 14 KB

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