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