assign.rs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 Assign {
  12. pub account: solana_program::pubkey::Pubkey,
  13. }
  14. impl Assign {
  15. pub fn instruction(
  16. &self,
  17. args: AssignInstructionArgs,
  18. ) -> solana_program::instruction::Instruction {
  19. self.instruction_with_remaining_accounts(args, &[])
  20. }
  21. #[allow(clippy::vec_init_then_push)]
  22. pub fn instruction_with_remaining_accounts(
  23. &self,
  24. args: AssignInstructionArgs,
  25. remaining_accounts: &[solana_program::instruction::AccountMeta],
  26. ) -> solana_program::instruction::Instruction {
  27. let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
  28. accounts.push(solana_program::instruction::AccountMeta::new(
  29. self.account,
  30. true,
  31. ));
  32. accounts.extend_from_slice(remaining_accounts);
  33. let mut data = AssignInstructionData::new().try_to_vec().unwrap();
  34. let mut args = args.try_to_vec().unwrap();
  35. data.append(&mut args);
  36. solana_program::instruction::Instruction {
  37. program_id: crate::SYSTEM_ID,
  38. accounts,
  39. data,
  40. }
  41. }
  42. }
  43. #[derive(BorshDeserialize, BorshSerialize)]
  44. struct AssignInstructionData {
  45. discriminator: u32,
  46. }
  47. impl AssignInstructionData {
  48. fn new() -> Self {
  49. Self { discriminator: 1 }
  50. }
  51. }
  52. #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
  53. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  54. pub struct AssignInstructionArgs {
  55. pub program_address: Pubkey,
  56. }
  57. /// Instruction builder for `Assign`.
  58. ///
  59. /// ### Accounts:
  60. ///
  61. /// 0. `[writable, signer]` account
  62. #[derive(Default)]
  63. pub struct AssignBuilder {
  64. account: Option<solana_program::pubkey::Pubkey>,
  65. program_address: Option<Pubkey>,
  66. __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
  67. }
  68. impl AssignBuilder {
  69. pub fn new() -> Self {
  70. Self::default()
  71. }
  72. #[inline(always)]
  73. pub fn account(&mut self, account: solana_program::pubkey::Pubkey) -> &mut Self {
  74. self.account = Some(account);
  75. self
  76. }
  77. #[inline(always)]
  78. pub fn program_address(&mut self, program_address: Pubkey) -> &mut Self {
  79. self.program_address = Some(program_address);
  80. self
  81. }
  82. /// Add an aditional account to the instruction.
  83. #[inline(always)]
  84. pub fn add_remaining_account(
  85. &mut self,
  86. account: solana_program::instruction::AccountMeta,
  87. ) -> &mut Self {
  88. self.__remaining_accounts.push(account);
  89. self
  90. }
  91. /// Add additional accounts to the instruction.
  92. #[inline(always)]
  93. pub fn add_remaining_accounts(
  94. &mut self,
  95. accounts: &[solana_program::instruction::AccountMeta],
  96. ) -> &mut Self {
  97. self.__remaining_accounts.extend_from_slice(accounts);
  98. self
  99. }
  100. #[allow(clippy::clone_on_copy)]
  101. pub fn instruction(&self) -> solana_program::instruction::Instruction {
  102. let accounts = Assign {
  103. account: self.account.expect("account is not set"),
  104. };
  105. let args = AssignInstructionArgs {
  106. program_address: self
  107. .program_address
  108. .clone()
  109. .expect("program_address is not set"),
  110. };
  111. accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
  112. }
  113. }
  114. /// `assign` CPI accounts.
  115. pub struct AssignCpiAccounts<'a, 'b> {
  116. pub account: &'b solana_program::account_info::AccountInfo<'a>,
  117. }
  118. /// `assign` CPI instruction.
  119. pub struct AssignCpi<'a, 'b> {
  120. /// The program to invoke.
  121. pub __program: &'b solana_program::account_info::AccountInfo<'a>,
  122. pub account: &'b solana_program::account_info::AccountInfo<'a>,
  123. /// The arguments for the instruction.
  124. pub __args: AssignInstructionArgs,
  125. }
  126. impl<'a, 'b> AssignCpi<'a, 'b> {
  127. pub fn new(
  128. program: &'b solana_program::account_info::AccountInfo<'a>,
  129. accounts: AssignCpiAccounts<'a, 'b>,
  130. args: AssignInstructionArgs,
  131. ) -> Self {
  132. Self {
  133. __program: program,
  134. account: accounts.account,
  135. __args: args,
  136. }
  137. }
  138. #[inline(always)]
  139. pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
  140. self.invoke_signed_with_remaining_accounts(&[], &[])
  141. }
  142. #[inline(always)]
  143. pub fn invoke_with_remaining_accounts(
  144. &self,
  145. remaining_accounts: &[(
  146. &'b solana_program::account_info::AccountInfo<'a>,
  147. bool,
  148. bool,
  149. )],
  150. ) -> solana_program::entrypoint::ProgramResult {
  151. self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
  152. }
  153. #[inline(always)]
  154. pub fn invoke_signed(
  155. &self,
  156. signers_seeds: &[&[&[u8]]],
  157. ) -> solana_program::entrypoint::ProgramResult {
  158. self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
  159. }
  160. #[allow(clippy::clone_on_copy)]
  161. #[allow(clippy::vec_init_then_push)]
  162. pub fn invoke_signed_with_remaining_accounts(
  163. &self,
  164. signers_seeds: &[&[&[u8]]],
  165. remaining_accounts: &[(
  166. &'b solana_program::account_info::AccountInfo<'a>,
  167. bool,
  168. bool,
  169. )],
  170. ) -> solana_program::entrypoint::ProgramResult {
  171. let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
  172. accounts.push(solana_program::instruction::AccountMeta::new(
  173. *self.account.key,
  174. true,
  175. ));
  176. remaining_accounts.iter().for_each(|remaining_account| {
  177. accounts.push(solana_program::instruction::AccountMeta {
  178. pubkey: *remaining_account.0.key,
  179. is_signer: remaining_account.1,
  180. is_writable: remaining_account.2,
  181. })
  182. });
  183. let mut data = AssignInstructionData::new().try_to_vec().unwrap();
  184. let mut args = self.__args.try_to_vec().unwrap();
  185. data.append(&mut args);
  186. let instruction = solana_program::instruction::Instruction {
  187. program_id: crate::SYSTEM_ID,
  188. accounts,
  189. data,
  190. };
  191. let mut account_infos = Vec::with_capacity(1 + 1 + remaining_accounts.len());
  192. account_infos.push(self.__program.clone());
  193. account_infos.push(self.account.clone());
  194. remaining_accounts
  195. .iter()
  196. .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
  197. if signers_seeds.is_empty() {
  198. solana_program::program::invoke(&instruction, &account_infos)
  199. } else {
  200. solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
  201. }
  202. }
  203. }
  204. /// Instruction builder for `Assign` via CPI.
  205. ///
  206. /// ### Accounts:
  207. ///
  208. /// 0. `[writable, signer]` account
  209. pub struct AssignCpiBuilder<'a, 'b> {
  210. instruction: Box<AssignCpiBuilderInstruction<'a, 'b>>,
  211. }
  212. impl<'a, 'b> AssignCpiBuilder<'a, 'b> {
  213. pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
  214. let instruction = Box::new(AssignCpiBuilderInstruction {
  215. __program: program,
  216. account: None,
  217. program_address: None,
  218. __remaining_accounts: Vec::new(),
  219. });
  220. Self { instruction }
  221. }
  222. #[inline(always)]
  223. pub fn account(
  224. &mut self,
  225. account: &'b solana_program::account_info::AccountInfo<'a>,
  226. ) -> &mut Self {
  227. self.instruction.account = Some(account);
  228. self
  229. }
  230. #[inline(always)]
  231. pub fn program_address(&mut self, program_address: Pubkey) -> &mut Self {
  232. self.instruction.program_address = Some(program_address);
  233. self
  234. }
  235. /// Add an additional account to the instruction.
  236. #[inline(always)]
  237. pub fn add_remaining_account(
  238. &mut self,
  239. account: &'b solana_program::account_info::AccountInfo<'a>,
  240. is_writable: bool,
  241. is_signer: bool,
  242. ) -> &mut Self {
  243. self.instruction
  244. .__remaining_accounts
  245. .push((account, is_writable, is_signer));
  246. self
  247. }
  248. /// Add additional accounts to the instruction.
  249. ///
  250. /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
  251. /// and a `bool` indicating whether the account is a signer or not.
  252. #[inline(always)]
  253. pub fn add_remaining_accounts(
  254. &mut self,
  255. accounts: &[(
  256. &'b solana_program::account_info::AccountInfo<'a>,
  257. bool,
  258. bool,
  259. )],
  260. ) -> &mut Self {
  261. self.instruction
  262. .__remaining_accounts
  263. .extend_from_slice(accounts);
  264. self
  265. }
  266. #[inline(always)]
  267. pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
  268. self.invoke_signed(&[])
  269. }
  270. #[allow(clippy::clone_on_copy)]
  271. #[allow(clippy::vec_init_then_push)]
  272. pub fn invoke_signed(
  273. &self,
  274. signers_seeds: &[&[&[u8]]],
  275. ) -> solana_program::entrypoint::ProgramResult {
  276. let args = AssignInstructionArgs {
  277. program_address: self
  278. .instruction
  279. .program_address
  280. .clone()
  281. .expect("program_address is not set"),
  282. };
  283. let instruction = AssignCpi {
  284. __program: self.instruction.__program,
  285. account: self.instruction.account.expect("account is not set"),
  286. __args: args,
  287. };
  288. instruction.invoke_signed_with_remaining_accounts(
  289. signers_seeds,
  290. &self.instruction.__remaining_accounts,
  291. )
  292. }
  293. }
  294. struct AssignCpiBuilderInstruction<'a, 'b> {
  295. __program: &'b solana_program::account_info::AccountInfo<'a>,
  296. account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
  297. program_address: Option<Pubkey>,
  298. /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
  299. __remaining_accounts: Vec<(
  300. &'b solana_program::account_info::AccountInfo<'a>,
  301. bool,
  302. bool,
  303. )>,
  304. }