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