1use crate::generated::types::RelationshipEntry;
9#[cfg(feature = "anchor")]
10use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
11#[cfg(not(feature = "anchor"))]
12use borsh::{BorshDeserialize, BorshSerialize};
13
14pub struct CreateGroupV1 {
16 pub group: solana_program::pubkey::Pubkey,
18 pub update_authority: Option<solana_program::pubkey::Pubkey>,
20 pub payer: solana_program::pubkey::Pubkey,
22 pub system_program: solana_program::pubkey::Pubkey,
24}
25
26impl CreateGroupV1 {
27 pub fn instruction(
28 &self,
29 args: CreateGroupV1InstructionArgs,
30 ) -> solana_program::instruction::Instruction {
31 self.instruction_with_remaining_accounts(args, &[])
32 }
33 #[allow(clippy::vec_init_then_push)]
34 pub fn instruction_with_remaining_accounts(
35 &self,
36 args: CreateGroupV1InstructionArgs,
37 remaining_accounts: &[solana_program::instruction::AccountMeta],
38 ) -> solana_program::instruction::Instruction {
39 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
40 accounts.push(solana_program::instruction::AccountMeta::new(
41 self.group, true,
42 ));
43 if let Some(update_authority) = self.update_authority {
44 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
45 update_authority,
46 true,
47 ));
48 } else {
49 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
50 crate::MPL_CORE_ID,
51 false,
52 ));
53 }
54 accounts.push(solana_program::instruction::AccountMeta::new(
55 self.payer, true,
56 ));
57 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
58 self.system_program,
59 false,
60 ));
61 accounts.extend_from_slice(remaining_accounts);
62 let mut data = borsh::to_vec(&(CreateGroupV1InstructionData::new())).unwrap();
63 let mut args = borsh::to_vec(&args).unwrap();
64 data.append(&mut args);
65
66 solana_program::instruction::Instruction {
67 program_id: crate::MPL_CORE_ID,
68 accounts,
69 data,
70 }
71 }
72}
73
74#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
75#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
76pub struct CreateGroupV1InstructionData {
77 discriminator: u8,
78}
79
80impl CreateGroupV1InstructionData {
81 pub fn new() -> Self {
82 Self { discriminator: 39 }
83 }
84}
85
86#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
87#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
88#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89#[derive(Clone, Debug, Eq, PartialEq)]
90pub struct CreateGroupV1InstructionArgs {
91 pub name: String,
92 pub uri: String,
93 pub relationships: Vec<RelationshipEntry>,
94}
95
96#[derive(Default)]
105pub struct CreateGroupV1Builder {
106 group: Option<solana_program::pubkey::Pubkey>,
107 update_authority: Option<solana_program::pubkey::Pubkey>,
108 payer: Option<solana_program::pubkey::Pubkey>,
109 system_program: Option<solana_program::pubkey::Pubkey>,
110 name: Option<String>,
111 uri: Option<String>,
112 relationships: Option<Vec<RelationshipEntry>>,
113 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
114}
115
116impl CreateGroupV1Builder {
117 pub fn new() -> Self {
118 Self::default()
119 }
120 #[inline(always)]
122 pub fn group(&mut self, group: solana_program::pubkey::Pubkey) -> &mut Self {
123 self.group = Some(group);
124 self
125 }
126 #[inline(always)]
129 pub fn update_authority(
130 &mut self,
131 update_authority: Option<solana_program::pubkey::Pubkey>,
132 ) -> &mut Self {
133 self.update_authority = update_authority;
134 self
135 }
136 #[inline(always)]
138 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
139 self.payer = Some(payer);
140 self
141 }
142 #[inline(always)]
145 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
146 self.system_program = Some(system_program);
147 self
148 }
149 #[inline(always)]
150 pub fn name(&mut self, name: String) -> &mut Self {
151 self.name = Some(name);
152 self
153 }
154 #[inline(always)]
155 pub fn uri(&mut self, uri: String) -> &mut Self {
156 self.uri = Some(uri);
157 self
158 }
159 #[inline(always)]
160 pub fn relationships(&mut self, relationships: Vec<RelationshipEntry>) -> &mut Self {
161 self.relationships = Some(relationships);
162 self
163 }
164 #[inline(always)]
166 pub fn add_remaining_account(
167 &mut self,
168 account: solana_program::instruction::AccountMeta,
169 ) -> &mut Self {
170 self.__remaining_accounts.push(account);
171 self
172 }
173 #[inline(always)]
175 pub fn add_remaining_accounts(
176 &mut self,
177 accounts: &[solana_program::instruction::AccountMeta],
178 ) -> &mut Self {
179 self.__remaining_accounts.extend_from_slice(accounts);
180 self
181 }
182 #[allow(clippy::clone_on_copy)]
183 pub fn instruction(&self) -> solana_program::instruction::Instruction {
184 let accounts = CreateGroupV1 {
185 group: self.group.expect("group is not set"),
186 update_authority: self.update_authority,
187 payer: self.payer.expect("payer is not set"),
188 system_program: self
189 .system_program
190 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
191 };
192 let args = CreateGroupV1InstructionArgs {
193 name: self.name.clone().expect("name is not set"),
194 uri: self.uri.clone().expect("uri is not set"),
195 relationships: self
196 .relationships
197 .clone()
198 .expect("relationships is not set"),
199 };
200
201 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
202 }
203}
204
205pub struct CreateGroupV1CpiAccounts<'a, 'b> {
207 pub group: &'b solana_program::account_info::AccountInfo<'a>,
209 pub update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
211 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
213 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
215}
216
217pub struct CreateGroupV1Cpi<'a, 'b> {
219 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
221 pub group: &'b solana_program::account_info::AccountInfo<'a>,
223 pub update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
225 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
227 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
229 pub __args: CreateGroupV1InstructionArgs,
231}
232
233impl<'a, 'b> CreateGroupV1Cpi<'a, 'b> {
234 pub fn new(
235 program: &'b solana_program::account_info::AccountInfo<'a>,
236 accounts: CreateGroupV1CpiAccounts<'a, 'b>,
237 args: CreateGroupV1InstructionArgs,
238 ) -> Self {
239 Self {
240 __program: program,
241 group: accounts.group,
242 update_authority: accounts.update_authority,
243 payer: accounts.payer,
244 system_program: accounts.system_program,
245 __args: args,
246 }
247 }
248 #[inline(always)]
249 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
250 self.invoke_signed_with_remaining_accounts(&[], &[])
251 }
252 #[inline(always)]
253 pub fn invoke_with_remaining_accounts(
254 &self,
255 remaining_accounts: &[(
256 &'b solana_program::account_info::AccountInfo<'a>,
257 bool,
258 bool,
259 )],
260 ) -> solana_program::entrypoint::ProgramResult {
261 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
262 }
263 #[inline(always)]
264 pub fn invoke_signed(
265 &self,
266 signers_seeds: &[&[&[u8]]],
267 ) -> solana_program::entrypoint::ProgramResult {
268 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
269 }
270 #[allow(clippy::clone_on_copy)]
271 #[allow(clippy::vec_init_then_push)]
272 pub fn invoke_signed_with_remaining_accounts(
273 &self,
274 signers_seeds: &[&[&[u8]]],
275 remaining_accounts: &[(
276 &'b solana_program::account_info::AccountInfo<'a>,
277 bool,
278 bool,
279 )],
280 ) -> solana_program::entrypoint::ProgramResult {
281 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
282 accounts.push(solana_program::instruction::AccountMeta::new(
283 *self.group.key,
284 true,
285 ));
286 if let Some(update_authority) = self.update_authority {
287 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
288 *update_authority.key,
289 true,
290 ));
291 } else {
292 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
293 crate::MPL_CORE_ID,
294 false,
295 ));
296 }
297 accounts.push(solana_program::instruction::AccountMeta::new(
298 *self.payer.key,
299 true,
300 ));
301 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
302 *self.system_program.key,
303 false,
304 ));
305 remaining_accounts.iter().for_each(|remaining_account| {
306 accounts.push(solana_program::instruction::AccountMeta {
307 pubkey: *remaining_account.0.key,
308 is_writable: remaining_account.1,
309 is_signer: remaining_account.2,
310 })
311 });
312 let mut data = borsh::to_vec(&(CreateGroupV1InstructionData::new())).unwrap();
313 let mut args = borsh::to_vec(&self.__args).unwrap();
314 data.append(&mut args);
315
316 let instruction = solana_program::instruction::Instruction {
317 program_id: crate::MPL_CORE_ID,
318 accounts,
319 data,
320 };
321 let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
322 account_infos.push(self.__program.clone());
323 account_infos.push(self.group.clone());
324 if let Some(update_authority) = self.update_authority {
325 account_infos.push(update_authority.clone());
326 }
327 account_infos.push(self.payer.clone());
328 account_infos.push(self.system_program.clone());
329 remaining_accounts
330 .iter()
331 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
332
333 if signers_seeds.is_empty() {
334 solana_program::program::invoke(&instruction, &account_infos)
335 } else {
336 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
337 }
338 }
339}
340
341pub struct CreateGroupV1CpiBuilder<'a, 'b> {
350 instruction: Box<CreateGroupV1CpiBuilderInstruction<'a, 'b>>,
351}
352
353impl<'a, 'b> CreateGroupV1CpiBuilder<'a, 'b> {
354 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
355 let instruction = Box::new(CreateGroupV1CpiBuilderInstruction {
356 __program: program,
357 group: None,
358 update_authority: None,
359 payer: None,
360 system_program: None,
361 name: None,
362 uri: None,
363 relationships: None,
364 __remaining_accounts: Vec::new(),
365 });
366 Self { instruction }
367 }
368 #[inline(always)]
370 pub fn group(&mut self, group: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
371 self.instruction.group = Some(group);
372 self
373 }
374 #[inline(always)]
377 pub fn update_authority(
378 &mut self,
379 update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
380 ) -> &mut Self {
381 self.instruction.update_authority = update_authority;
382 self
383 }
384 #[inline(always)]
386 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
387 self.instruction.payer = Some(payer);
388 self
389 }
390 #[inline(always)]
392 pub fn system_program(
393 &mut self,
394 system_program: &'b solana_program::account_info::AccountInfo<'a>,
395 ) -> &mut Self {
396 self.instruction.system_program = Some(system_program);
397 self
398 }
399 #[inline(always)]
400 pub fn name(&mut self, name: String) -> &mut Self {
401 self.instruction.name = Some(name);
402 self
403 }
404 #[inline(always)]
405 pub fn uri(&mut self, uri: String) -> &mut Self {
406 self.instruction.uri = Some(uri);
407 self
408 }
409 #[inline(always)]
410 pub fn relationships(&mut self, relationships: Vec<RelationshipEntry>) -> &mut Self {
411 self.instruction.relationships = Some(relationships);
412 self
413 }
414 #[inline(always)]
416 pub fn add_remaining_account(
417 &mut self,
418 account: &'b solana_program::account_info::AccountInfo<'a>,
419 is_writable: bool,
420 is_signer: bool,
421 ) -> &mut Self {
422 self.instruction
423 .__remaining_accounts
424 .push((account, is_writable, is_signer));
425 self
426 }
427 #[inline(always)]
432 pub fn add_remaining_accounts(
433 &mut self,
434 accounts: &[(
435 &'b solana_program::account_info::AccountInfo<'a>,
436 bool,
437 bool,
438 )],
439 ) -> &mut Self {
440 self.instruction
441 .__remaining_accounts
442 .extend_from_slice(accounts);
443 self
444 }
445 #[inline(always)]
446 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
447 self.invoke_signed(&[])
448 }
449 #[allow(clippy::clone_on_copy)]
450 #[allow(clippy::vec_init_then_push)]
451 pub fn invoke_signed(
452 &self,
453 signers_seeds: &[&[&[u8]]],
454 ) -> solana_program::entrypoint::ProgramResult {
455 let args = CreateGroupV1InstructionArgs {
456 name: self.instruction.name.clone().expect("name is not set"),
457 uri: self.instruction.uri.clone().expect("uri is not set"),
458 relationships: self
459 .instruction
460 .relationships
461 .clone()
462 .expect("relationships is not set"),
463 };
464 let instruction = CreateGroupV1Cpi {
465 __program: self.instruction.__program,
466
467 group: self.instruction.group.expect("group is not set"),
468
469 update_authority: self.instruction.update_authority,
470
471 payer: self.instruction.payer.expect("payer is not set"),
472
473 system_program: self
474 .instruction
475 .system_program
476 .expect("system_program is not set"),
477 __args: args,
478 };
479 instruction.invoke_signed_with_remaining_accounts(
480 signers_seeds,
481 &self.instruction.__remaining_accounts,
482 )
483 }
484}
485
486struct CreateGroupV1CpiBuilderInstruction<'a, 'b> {
487 __program: &'b solana_program::account_info::AccountInfo<'a>,
488 group: Option<&'b solana_program::account_info::AccountInfo<'a>>,
489 update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
490 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
491 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
492 name: Option<String>,
493 uri: Option<String>,
494 relationships: Option<Vec<RelationshipEntry>>,
495 __remaining_accounts: Vec<(
497 &'b solana_program::account_info::AccountInfo<'a>,
498 bool,
499 bool,
500 )>,
501}