assign.rs 10 KB

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