allocate_with_seed.rs 14 KB

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