nifty_asset_interface/generated/instructions/
group.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct Group {
13 pub asset: solana_program::pubkey::Pubkey,
15 pub group: solana_program::pubkey::Pubkey,
17 pub authority: solana_program::pubkey::Pubkey,
19}
20
21impl Group {
22 pub fn instruction(&self) -> solana_program::instruction::Instruction {
23 self.instruction_with_remaining_accounts(&[])
24 }
25 #[allow(clippy::vec_init_then_push)]
26 pub fn instruction_with_remaining_accounts(
27 &self,
28 remaining_accounts: &[solana_program::instruction::AccountMeta],
29 ) -> solana_program::instruction::Instruction {
30 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
31 accounts.push(solana_program::instruction::AccountMeta::new(
32 self.asset, true,
33 ));
34 accounts.push(solana_program::instruction::AccountMeta::new(
35 self.group, false,
36 ));
37 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38 self.authority,
39 true,
40 ));
41 accounts.extend_from_slice(remaining_accounts);
42 let data = GroupInstructionData::new().try_to_vec().unwrap();
43
44 solana_program::instruction::Instruction {
45 program_id: crate::INTERFACE_ID,
46 accounts,
47 data,
48 }
49 }
50}
51
52#[derive(BorshDeserialize, BorshSerialize)]
53struct GroupInstructionData {
54 discriminator: u8,
55}
56
57impl GroupInstructionData {
58 fn new() -> Self {
59 Self { discriminator: 13 }
60 }
61}
62
63#[derive(Default)]
71pub struct GroupBuilder {
72 asset: Option<solana_program::pubkey::Pubkey>,
73 group: Option<solana_program::pubkey::Pubkey>,
74 authority: Option<solana_program::pubkey::Pubkey>,
75 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
76}
77
78impl GroupBuilder {
79 pub fn new() -> Self {
80 Self::default()
81 }
82 #[inline(always)]
84 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
85 self.asset = Some(asset);
86 self
87 }
88 #[inline(always)]
90 pub fn group(&mut self, group: solana_program::pubkey::Pubkey) -> &mut Self {
91 self.group = Some(group);
92 self
93 }
94 #[inline(always)]
96 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
97 self.authority = Some(authority);
98 self
99 }
100 #[inline(always)]
102 pub fn add_remaining_account(
103 &mut self,
104 account: solana_program::instruction::AccountMeta,
105 ) -> &mut Self {
106 self.__remaining_accounts.push(account);
107 self
108 }
109 #[inline(always)]
111 pub fn add_remaining_accounts(
112 &mut self,
113 accounts: &[solana_program::instruction::AccountMeta],
114 ) -> &mut Self {
115 self.__remaining_accounts.extend_from_slice(accounts);
116 self
117 }
118 #[allow(clippy::clone_on_copy)]
119 pub fn instruction(&self) -> solana_program::instruction::Instruction {
120 let accounts = Group {
121 asset: self.asset.expect("asset is not set"),
122 group: self.group.expect("group is not set"),
123 authority: self.authority.expect("authority is not set"),
124 };
125
126 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
127 }
128}
129
130pub struct GroupCpiAccounts<'a, 'b> {
132 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
134 pub group: &'b solana_program::account_info::AccountInfo<'a>,
136 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
138}
139
140pub struct GroupCpi<'a, 'b> {
142 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
144 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
146 pub group: &'b solana_program::account_info::AccountInfo<'a>,
148 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
150}
151
152impl<'a, 'b> GroupCpi<'a, 'b> {
153 pub fn new(
154 program: &'b solana_program::account_info::AccountInfo<'a>,
155 accounts: GroupCpiAccounts<'a, 'b>,
156 ) -> Self {
157 Self {
158 __program: program,
159 asset: accounts.asset,
160 group: accounts.group,
161 authority: accounts.authority,
162 }
163 }
164 #[inline(always)]
165 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
166 self.invoke_signed_with_remaining_accounts(&[], &[])
167 }
168 #[inline(always)]
169 pub fn invoke_with_remaining_accounts(
170 &self,
171 remaining_accounts: &[(
172 &'b solana_program::account_info::AccountInfo<'a>,
173 bool,
174 bool,
175 )],
176 ) -> solana_program::entrypoint::ProgramResult {
177 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
178 }
179 #[inline(always)]
180 pub fn invoke_signed(
181 &self,
182 signers_seeds: &[&[&[u8]]],
183 ) -> solana_program::entrypoint::ProgramResult {
184 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
185 }
186 #[allow(clippy::clone_on_copy)]
187 #[allow(clippy::vec_init_then_push)]
188 pub fn invoke_signed_with_remaining_accounts(
189 &self,
190 signers_seeds: &[&[&[u8]]],
191 remaining_accounts: &[(
192 &'b solana_program::account_info::AccountInfo<'a>,
193 bool,
194 bool,
195 )],
196 ) -> solana_program::entrypoint::ProgramResult {
197 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
198 accounts.push(solana_program::instruction::AccountMeta::new(
199 *self.asset.key,
200 true,
201 ));
202 accounts.push(solana_program::instruction::AccountMeta::new(
203 *self.group.key,
204 false,
205 ));
206 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
207 *self.authority.key,
208 true,
209 ));
210 remaining_accounts.iter().for_each(|remaining_account| {
211 accounts.push(solana_program::instruction::AccountMeta {
212 pubkey: *remaining_account.0.key,
213 is_signer: remaining_account.1,
214 is_writable: remaining_account.2,
215 })
216 });
217 let data = GroupInstructionData::new().try_to_vec().unwrap();
218
219 let instruction = solana_program::instruction::Instruction {
220 program_id: crate::INTERFACE_ID,
221 accounts,
222 data,
223 };
224 let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
225 account_infos.push(self.__program.clone());
226 account_infos.push(self.asset.clone());
227 account_infos.push(self.group.clone());
228 account_infos.push(self.authority.clone());
229 remaining_accounts
230 .iter()
231 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
232
233 if signers_seeds.is_empty() {
234 solana_program::program::invoke(&instruction, &account_infos)
235 } else {
236 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
237 }
238 }
239}
240
241pub struct GroupCpiBuilder<'a, 'b> {
249 instruction: Box<GroupCpiBuilderInstruction<'a, 'b>>,
250}
251
252impl<'a, 'b> GroupCpiBuilder<'a, 'b> {
253 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
254 let instruction = Box::new(GroupCpiBuilderInstruction {
255 __program: program,
256 asset: None,
257 group: None,
258 authority: None,
259 __remaining_accounts: Vec::new(),
260 });
261 Self { instruction }
262 }
263 #[inline(always)]
265 pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
266 self.instruction.asset = Some(asset);
267 self
268 }
269 #[inline(always)]
271 pub fn group(&mut self, group: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
272 self.instruction.group = Some(group);
273 self
274 }
275 #[inline(always)]
277 pub fn authority(
278 &mut self,
279 authority: &'b solana_program::account_info::AccountInfo<'a>,
280 ) -> &mut Self {
281 self.instruction.authority = Some(authority);
282 self
283 }
284 #[inline(always)]
286 pub fn add_remaining_account(
287 &mut self,
288 account: &'b solana_program::account_info::AccountInfo<'a>,
289 is_writable: bool,
290 is_signer: bool,
291 ) -> &mut Self {
292 self.instruction
293 .__remaining_accounts
294 .push((account, is_writable, is_signer));
295 self
296 }
297 #[inline(always)]
302 pub fn add_remaining_accounts(
303 &mut self,
304 accounts: &[(
305 &'b solana_program::account_info::AccountInfo<'a>,
306 bool,
307 bool,
308 )],
309 ) -> &mut Self {
310 self.instruction
311 .__remaining_accounts
312 .extend_from_slice(accounts);
313 self
314 }
315 #[inline(always)]
316 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
317 self.invoke_signed(&[])
318 }
319 #[allow(clippy::clone_on_copy)]
320 #[allow(clippy::vec_init_then_push)]
321 pub fn invoke_signed(
322 &self,
323 signers_seeds: &[&[&[u8]]],
324 ) -> solana_program::entrypoint::ProgramResult {
325 let instruction = GroupCpi {
326 __program: self.instruction.__program,
327
328 asset: self.instruction.asset.expect("asset is not set"),
329
330 group: self.instruction.group.expect("group is not set"),
331
332 authority: self.instruction.authority.expect("authority is not set"),
333 };
334 instruction.invoke_signed_with_remaining_accounts(
335 signers_seeds,
336 &self.instruction.__remaining_accounts,
337 )
338 }
339}
340
341struct GroupCpiBuilderInstruction<'a, 'b> {
342 __program: &'b solana_program::account_info::AccountInfo<'a>,
343 asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
344 group: Option<&'b solana_program::account_info::AccountInfo<'a>>,
345 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
346 __remaining_accounts: Vec<(
348 &'b solana_program::account_info::AccountInfo<'a>,
349 bool,
350 bool,
351 )>,
352}