assign_with_seed.rs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 kaigan::types::U64PrefixString;
  10. use solana_program::pubkey::Pubkey;
  11. /// Accounts.
  12. #[derive(Debug)]
  13. pub struct AssignWithSeed {
  14. pub account: solana_program::pubkey::Pubkey,
  15. pub base_account: solana_program::pubkey::Pubkey,
  16. }
  17. impl AssignWithSeed {
  18. pub fn instruction(
  19. &self,
  20. args: AssignWithSeedInstructionArgs,
  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: AssignWithSeedInstructionArgs,
  28. remaining_accounts: &[solana_program::instruction::AccountMeta],
  29. ) -> solana_program::instruction::Instruction {
  30. let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
  31. accounts.push(solana_program::instruction::AccountMeta::new(
  32. self.account,
  33. false,
  34. ));
  35. accounts.push(solana_program::instruction::AccountMeta::new_readonly(
  36. self.base_account,
  37. true,
  38. ));
  39. accounts.extend_from_slice(remaining_accounts);
  40. let mut data = AssignWithSeedInstructionData::new().try_to_vec().unwrap();
  41. let mut args = args.try_to_vec().unwrap();
  42. data.append(&mut args);
  43. solana_program::instruction::Instruction {
  44. program_id: crate::SYSTEM_ID,
  45. accounts,
  46. data,
  47. }
  48. }
  49. }
  50. #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
  51. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  52. pub struct AssignWithSeedInstructionData {
  53. discriminator: u32,
  54. }
  55. impl AssignWithSeedInstructionData {
  56. pub fn new() -> Self {
  57. Self { discriminator: 10 }
  58. }
  59. }
  60. impl Default for AssignWithSeedInstructionData {
  61. fn default() -> Self {
  62. Self::new()
  63. }
  64. }
  65. #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
  66. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  67. pub struct AssignWithSeedInstructionArgs {
  68. pub base: Pubkey,
  69. pub seed: U64PrefixString,
  70. pub program_address: Pubkey,
  71. }
  72. /// Instruction builder for `AssignWithSeed`.
  73. ///
  74. /// ### Accounts:
  75. ///
  76. /// 0. `[writable]` account
  77. /// 1. `[signer]` base_account
  78. #[derive(Clone, Debug, Default)]
  79. pub struct AssignWithSeedBuilder {
  80. account: Option<solana_program::pubkey::Pubkey>,
  81. base_account: Option<solana_program::pubkey::Pubkey>,
  82. base: Option<Pubkey>,
  83. seed: Option<U64PrefixString>,
  84. program_address: Option<Pubkey>,
  85. __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
  86. }
  87. impl AssignWithSeedBuilder {
  88. pub fn new() -> Self {
  89. Self::default()
  90. }
  91. #[inline(always)]
  92. pub fn account(&mut self, account: solana_program::pubkey::Pubkey) -> &mut Self {
  93. self.account = Some(account);
  94. self
  95. }
  96. #[inline(always)]
  97. pub fn base_account(&mut self, base_account: solana_program::pubkey::Pubkey) -> &mut Self {
  98. self.base_account = Some(base_account);
  99. self
  100. }
  101. #[inline(always)]
  102. pub fn base(&mut self, base: Pubkey) -> &mut Self {
  103. self.base = Some(base);
  104. self
  105. }
  106. #[inline(always)]
  107. pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
  108. self.seed = Some(seed);
  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 additional 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 = AssignWithSeed {
  137. account: self.account.expect("account is not set"),
  138. base_account: self.base_account.expect("base_account is not set"),
  139. };
  140. let args = AssignWithSeedInstructionArgs {
  141. base: self.base.clone().expect("base is not set"),
  142. seed: self.seed.clone().expect("seed 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. /// `assign_with_seed` CPI accounts.
  152. pub struct AssignWithSeedCpiAccounts<'a, 'b> {
  153. pub account: &'b solana_program::account_info::AccountInfo<'a>,
  154. pub base_account: &'b solana_program::account_info::AccountInfo<'a>,
  155. }
  156. /// `assign_with_seed` CPI instruction.
  157. pub struct AssignWithSeedCpi<'a, 'b> {
  158. /// The program to invoke.
  159. pub __program: &'b solana_program::account_info::AccountInfo<'a>,
  160. pub 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: AssignWithSeedInstructionArgs,
  164. }
  165. impl<'a, 'b> AssignWithSeedCpi<'a, 'b> {
  166. pub fn new(
  167. program: &'b solana_program::account_info::AccountInfo<'a>,
  168. accounts: AssignWithSeedCpiAccounts<'a, 'b>,
  169. args: AssignWithSeedInstructionArgs,
  170. ) -> Self {
  171. Self {
  172. __program: program,
  173. account: accounts.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.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 = AssignWithSeedInstructionData::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(3 + remaining_accounts.len());
  236. account_infos.push(self.__program.clone());
  237. account_infos.push(self.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 `AssignWithSeed` via CPI.
  250. ///
  251. /// ### Accounts:
  252. ///
  253. /// 0. `[writable]` account
  254. /// 1. `[signer]` base_account
  255. #[derive(Clone, Debug)]
  256. pub struct AssignWithSeedCpiBuilder<'a, 'b> {
  257. instruction: Box<AssignWithSeedCpiBuilderInstruction<'a, 'b>>,
  258. }
  259. impl<'a, 'b> AssignWithSeedCpiBuilder<'a, 'b> {
  260. pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
  261. let instruction = Box::new(AssignWithSeedCpiBuilderInstruction {
  262. __program: program,
  263. account: None,
  264. base_account: None,
  265. base: None,
  266. seed: None,
  267. program_address: None,
  268. __remaining_accounts: Vec::new(),
  269. });
  270. Self { instruction }
  271. }
  272. #[inline(always)]
  273. pub fn account(
  274. &mut self,
  275. account: &'b solana_program::account_info::AccountInfo<'a>,
  276. ) -> &mut Self {
  277. self.instruction.account = Some(account);
  278. self
  279. }
  280. #[inline(always)]
  281. pub fn base_account(
  282. &mut self,
  283. base_account: &'b solana_program::account_info::AccountInfo<'a>,
  284. ) -> &mut Self {
  285. self.instruction.base_account = Some(base_account);
  286. self
  287. }
  288. #[inline(always)]
  289. pub fn base(&mut self, base: Pubkey) -> &mut Self {
  290. self.instruction.base = Some(base);
  291. self
  292. }
  293. #[inline(always)]
  294. pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
  295. self.instruction.seed = Some(seed);
  296. self
  297. }
  298. #[inline(always)]
  299. pub fn program_address(&mut self, program_address: Pubkey) -> &mut Self {
  300. self.instruction.program_address = Some(program_address);
  301. self
  302. }
  303. /// Add an additional account to the instruction.
  304. #[inline(always)]
  305. pub fn add_remaining_account(
  306. &mut self,
  307. account: &'b solana_program::account_info::AccountInfo<'a>,
  308. is_writable: bool,
  309. is_signer: bool,
  310. ) -> &mut Self {
  311. self.instruction
  312. .__remaining_accounts
  313. .push((account, is_writable, is_signer));
  314. self
  315. }
  316. /// Add additional accounts to the instruction.
  317. ///
  318. /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
  319. /// and a `bool` indicating whether the account is a signer or not.
  320. #[inline(always)]
  321. pub fn add_remaining_accounts(
  322. &mut self,
  323. accounts: &[(
  324. &'b solana_program::account_info::AccountInfo<'a>,
  325. bool,
  326. bool,
  327. )],
  328. ) -> &mut Self {
  329. self.instruction
  330. .__remaining_accounts
  331. .extend_from_slice(accounts);
  332. self
  333. }
  334. #[inline(always)]
  335. pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
  336. self.invoke_signed(&[])
  337. }
  338. #[allow(clippy::clone_on_copy)]
  339. #[allow(clippy::vec_init_then_push)]
  340. pub fn invoke_signed(
  341. &self,
  342. signers_seeds: &[&[&[u8]]],
  343. ) -> solana_program::entrypoint::ProgramResult {
  344. let args = AssignWithSeedInstructionArgs {
  345. base: self.instruction.base.clone().expect("base is not set"),
  346. seed: self.instruction.seed.clone().expect("seed is not set"),
  347. program_address: self
  348. .instruction
  349. .program_address
  350. .clone()
  351. .expect("program_address is not set"),
  352. };
  353. let instruction = AssignWithSeedCpi {
  354. __program: self.instruction.__program,
  355. account: self.instruction.account.expect("account is not set"),
  356. base_account: self
  357. .instruction
  358. .base_account
  359. .expect("base_account is not set"),
  360. __args: args,
  361. };
  362. instruction.invoke_signed_with_remaining_accounts(
  363. signers_seeds,
  364. &self.instruction.__remaining_accounts,
  365. )
  366. }
  367. }
  368. #[derive(Clone, Debug)]
  369. struct AssignWithSeedCpiBuilderInstruction<'a, 'b> {
  370. __program: &'b solana_program::account_info::AccountInfo<'a>,
  371. account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
  372. base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
  373. base: Option<Pubkey>,
  374. seed: Option<U64PrefixString>,
  375. program_address: Option<Pubkey>,
  376. /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
  377. __remaining_accounts: Vec<(
  378. &'b solana_program::account_info::AccountInfo<'a>,
  379. bool,
  380. bool,
  381. )>,
  382. }