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