1use crate::generated::types::DataState;
9use crate::generated::types::PluginAuthorityPair;
10use borsh::BorshDeserialize;
11use borsh::BorshSerialize;
12
13pub struct CreateV1 {
15 pub asset: solana_program::pubkey::Pubkey,
17 pub collection: Option<solana_program::pubkey::Pubkey>,
19 pub authority: Option<solana_program::pubkey::Pubkey>,
21 pub payer: solana_program::pubkey::Pubkey,
23 pub owner: Option<solana_program::pubkey::Pubkey>,
25 pub update_authority: Option<solana_program::pubkey::Pubkey>,
27 pub system_program: solana_program::pubkey::Pubkey,
29 pub log_wrapper: Option<solana_program::pubkey::Pubkey>,
31}
32
33impl CreateV1 {
34 pub fn instruction(
35 &self,
36 args: CreateV1InstructionArgs,
37 ) -> solana_program::instruction::Instruction {
38 self.instruction_with_remaining_accounts(args, &[])
39 }
40 #[allow(clippy::vec_init_then_push)]
41 pub fn instruction_with_remaining_accounts(
42 &self,
43 args: CreateV1InstructionArgs,
44 remaining_accounts: &[solana_program::instruction::AccountMeta],
45 ) -> solana_program::instruction::Instruction {
46 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
47 accounts.push(solana_program::instruction::AccountMeta::new(
48 self.asset, true,
49 ));
50 if let Some(collection) = self.collection {
51 accounts.push(solana_program::instruction::AccountMeta::new(
52 collection, false,
53 ));
54 } else {
55 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
56 crate::MPL_CORE_ID,
57 false,
58 ));
59 }
60 if let Some(authority) = self.authority {
61 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
62 authority, true,
63 ));
64 } else {
65 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
66 crate::MPL_CORE_ID,
67 false,
68 ));
69 }
70 accounts.push(solana_program::instruction::AccountMeta::new(
71 self.payer, true,
72 ));
73 if let Some(owner) = self.owner {
74 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
75 owner, false,
76 ));
77 } else {
78 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
79 crate::MPL_CORE_ID,
80 false,
81 ));
82 }
83 if let Some(update_authority) = self.update_authority {
84 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
85 update_authority,
86 false,
87 ));
88 } else {
89 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
90 crate::MPL_CORE_ID,
91 false,
92 ));
93 }
94 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
95 self.system_program,
96 false,
97 ));
98 if let Some(log_wrapper) = self.log_wrapper {
99 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
100 log_wrapper,
101 false,
102 ));
103 } else {
104 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
105 crate::MPL_CORE_ID,
106 false,
107 ));
108 }
109 accounts.extend_from_slice(remaining_accounts);
110 let mut data = CreateV1InstructionData::new().try_to_vec().unwrap();
111 let mut args = args.try_to_vec().unwrap();
112 data.append(&mut args);
113
114 solana_program::instruction::Instruction {
115 program_id: crate::MPL_CORE_ID,
116 accounts,
117 data,
118 }
119 }
120}
121
122#[derive(BorshDeserialize, BorshSerialize)]
123struct CreateV1InstructionData {
124 discriminator: u8,
125}
126
127impl CreateV1InstructionData {
128 fn new() -> Self {
129 Self { discriminator: 0 }
130 }
131}
132
133#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
134#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
135pub struct CreateV1InstructionArgs {
136 pub data_state: DataState,
137 pub name: String,
138 pub uri: String,
139 pub plugins: Option<Vec<PluginAuthorityPair>>,
140}
141
142#[derive(Default)]
155pub struct CreateV1Builder {
156 asset: Option<solana_program::pubkey::Pubkey>,
157 collection: Option<solana_program::pubkey::Pubkey>,
158 authority: Option<solana_program::pubkey::Pubkey>,
159 payer: Option<solana_program::pubkey::Pubkey>,
160 owner: Option<solana_program::pubkey::Pubkey>,
161 update_authority: Option<solana_program::pubkey::Pubkey>,
162 system_program: Option<solana_program::pubkey::Pubkey>,
163 log_wrapper: Option<solana_program::pubkey::Pubkey>,
164 data_state: Option<DataState>,
165 name: Option<String>,
166 uri: Option<String>,
167 plugins: Option<Vec<PluginAuthorityPair>>,
168 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
169}
170
171impl CreateV1Builder {
172 pub fn new() -> Self {
173 Self::default()
174 }
175 #[inline(always)]
177 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
178 self.asset = Some(asset);
179 self
180 }
181 #[inline(always)]
184 pub fn collection(&mut self, collection: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
185 self.collection = collection;
186 self
187 }
188 #[inline(always)]
191 pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
192 self.authority = authority;
193 self
194 }
195 #[inline(always)]
197 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
198 self.payer = Some(payer);
199 self
200 }
201 #[inline(always)]
204 pub fn owner(&mut self, owner: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
205 self.owner = owner;
206 self
207 }
208 #[inline(always)]
211 pub fn update_authority(
212 &mut self,
213 update_authority: Option<solana_program::pubkey::Pubkey>,
214 ) -> &mut Self {
215 self.update_authority = update_authority;
216 self
217 }
218 #[inline(always)]
221 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
222 self.system_program = Some(system_program);
223 self
224 }
225 #[inline(always)]
228 pub fn log_wrapper(
229 &mut self,
230 log_wrapper: Option<solana_program::pubkey::Pubkey>,
231 ) -> &mut Self {
232 self.log_wrapper = log_wrapper;
233 self
234 }
235 #[inline(always)]
237 pub fn data_state(&mut self, data_state: DataState) -> &mut Self {
238 self.data_state = Some(data_state);
239 self
240 }
241 #[inline(always)]
242 pub fn name(&mut self, name: String) -> &mut Self {
243 self.name = Some(name);
244 self
245 }
246 #[inline(always)]
247 pub fn uri(&mut self, uri: String) -> &mut Self {
248 self.uri = Some(uri);
249 self
250 }
251 #[inline(always)]
253 pub fn plugins(&mut self, plugins: Vec<PluginAuthorityPair>) -> &mut Self {
254 self.plugins = Some(plugins);
255 self
256 }
257 #[inline(always)]
259 pub fn add_remaining_account(
260 &mut self,
261 account: solana_program::instruction::AccountMeta,
262 ) -> &mut Self {
263 self.__remaining_accounts.push(account);
264 self
265 }
266 #[inline(always)]
268 pub fn add_remaining_accounts(
269 &mut self,
270 accounts: &[solana_program::instruction::AccountMeta],
271 ) -> &mut Self {
272 self.__remaining_accounts.extend_from_slice(accounts);
273 self
274 }
275 #[allow(clippy::clone_on_copy)]
276 pub fn instruction(&self) -> solana_program::instruction::Instruction {
277 let accounts = CreateV1 {
278 asset: self.asset.expect("asset is not set"),
279 collection: self.collection,
280 authority: self.authority,
281 payer: self.payer.expect("payer is not set"),
282 owner: self.owner,
283 update_authority: self.update_authority,
284 system_program: self
285 .system_program
286 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
287 log_wrapper: self.log_wrapper,
288 };
289 let args = CreateV1InstructionArgs {
290 data_state: self.data_state.clone().unwrap_or(DataState::AccountState),
291 name: self.name.clone().expect("name is not set"),
292 uri: self.uri.clone().expect("uri is not set"),
293 plugins: self.plugins.clone(),
294 };
295
296 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
297 }
298}
299
300pub struct CreateV1CpiAccounts<'a, 'b> {
302 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
304 pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
306 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
308 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
310 pub owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
312 pub update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
314 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
316 pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
318}
319
320pub struct CreateV1Cpi<'a, 'b> {
322 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
324 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
326 pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
328 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
330 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
332 pub owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
334 pub update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
336 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
338 pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
340 pub __args: CreateV1InstructionArgs,
342}
343
344impl<'a, 'b> CreateV1Cpi<'a, 'b> {
345 pub fn new(
346 program: &'b solana_program::account_info::AccountInfo<'a>,
347 accounts: CreateV1CpiAccounts<'a, 'b>,
348 args: CreateV1InstructionArgs,
349 ) -> Self {
350 Self {
351 __program: program,
352 asset: accounts.asset,
353 collection: accounts.collection,
354 authority: accounts.authority,
355 payer: accounts.payer,
356 owner: accounts.owner,
357 update_authority: accounts.update_authority,
358 system_program: accounts.system_program,
359 log_wrapper: accounts.log_wrapper,
360 __args: args,
361 }
362 }
363 #[inline(always)]
364 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
365 self.invoke_signed_with_remaining_accounts(&[], &[])
366 }
367 #[inline(always)]
368 pub fn invoke_with_remaining_accounts(
369 &self,
370 remaining_accounts: &[(
371 &'b solana_program::account_info::AccountInfo<'a>,
372 bool,
373 bool,
374 )],
375 ) -> solana_program::entrypoint::ProgramResult {
376 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
377 }
378 #[inline(always)]
379 pub fn invoke_signed(
380 &self,
381 signers_seeds: &[&[&[u8]]],
382 ) -> solana_program::entrypoint::ProgramResult {
383 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
384 }
385 #[allow(clippy::clone_on_copy)]
386 #[allow(clippy::vec_init_then_push)]
387 pub fn invoke_signed_with_remaining_accounts(
388 &self,
389 signers_seeds: &[&[&[u8]]],
390 remaining_accounts: &[(
391 &'b solana_program::account_info::AccountInfo<'a>,
392 bool,
393 bool,
394 )],
395 ) -> solana_program::entrypoint::ProgramResult {
396 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
397 accounts.push(solana_program::instruction::AccountMeta::new(
398 *self.asset.key,
399 true,
400 ));
401 if let Some(collection) = self.collection {
402 accounts.push(solana_program::instruction::AccountMeta::new(
403 *collection.key,
404 false,
405 ));
406 } else {
407 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
408 crate::MPL_CORE_ID,
409 false,
410 ));
411 }
412 if let Some(authority) = self.authority {
413 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
414 *authority.key,
415 true,
416 ));
417 } else {
418 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
419 crate::MPL_CORE_ID,
420 false,
421 ));
422 }
423 accounts.push(solana_program::instruction::AccountMeta::new(
424 *self.payer.key,
425 true,
426 ));
427 if let Some(owner) = self.owner {
428 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
429 *owner.key, false,
430 ));
431 } else {
432 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
433 crate::MPL_CORE_ID,
434 false,
435 ));
436 }
437 if let Some(update_authority) = self.update_authority {
438 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
439 *update_authority.key,
440 false,
441 ));
442 } else {
443 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
444 crate::MPL_CORE_ID,
445 false,
446 ));
447 }
448 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
449 *self.system_program.key,
450 false,
451 ));
452 if let Some(log_wrapper) = self.log_wrapper {
453 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
454 *log_wrapper.key,
455 false,
456 ));
457 } else {
458 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
459 crate::MPL_CORE_ID,
460 false,
461 ));
462 }
463 remaining_accounts.iter().for_each(|remaining_account| {
464 accounts.push(solana_program::instruction::AccountMeta {
465 pubkey: *remaining_account.0.key,
466 is_signer: remaining_account.1,
467 is_writable: remaining_account.2,
468 })
469 });
470 let mut data = CreateV1InstructionData::new().try_to_vec().unwrap();
471 let mut args = self.__args.try_to_vec().unwrap();
472 data.append(&mut args);
473
474 let instruction = solana_program::instruction::Instruction {
475 program_id: crate::MPL_CORE_ID,
476 accounts,
477 data,
478 };
479 let mut account_infos = Vec::with_capacity(8 + 1 + remaining_accounts.len());
480 account_infos.push(self.__program.clone());
481 account_infos.push(self.asset.clone());
482 if let Some(collection) = self.collection {
483 account_infos.push(collection.clone());
484 }
485 if let Some(authority) = self.authority {
486 account_infos.push(authority.clone());
487 }
488 account_infos.push(self.payer.clone());
489 if let Some(owner) = self.owner {
490 account_infos.push(owner.clone());
491 }
492 if let Some(update_authority) = self.update_authority {
493 account_infos.push(update_authority.clone());
494 }
495 account_infos.push(self.system_program.clone());
496 if let Some(log_wrapper) = self.log_wrapper {
497 account_infos.push(log_wrapper.clone());
498 }
499 remaining_accounts
500 .iter()
501 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
502
503 if signers_seeds.is_empty() {
504 solana_program::program::invoke(&instruction, &account_infos)
505 } else {
506 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
507 }
508 }
509}
510
511pub struct CreateV1CpiBuilder<'a, 'b> {
524 instruction: Box<CreateV1CpiBuilderInstruction<'a, 'b>>,
525}
526
527impl<'a, 'b> CreateV1CpiBuilder<'a, 'b> {
528 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
529 let instruction = Box::new(CreateV1CpiBuilderInstruction {
530 __program: program,
531 asset: None,
532 collection: None,
533 authority: None,
534 payer: None,
535 owner: None,
536 update_authority: None,
537 system_program: None,
538 log_wrapper: None,
539 data_state: None,
540 name: None,
541 uri: None,
542 plugins: None,
543 __remaining_accounts: Vec::new(),
544 });
545 Self { instruction }
546 }
547 #[inline(always)]
549 pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
550 self.instruction.asset = Some(asset);
551 self
552 }
553 #[inline(always)]
556 pub fn collection(
557 &mut self,
558 collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
559 ) -> &mut Self {
560 self.instruction.collection = collection;
561 self
562 }
563 #[inline(always)]
566 pub fn authority(
567 &mut self,
568 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
569 ) -> &mut Self {
570 self.instruction.authority = authority;
571 self
572 }
573 #[inline(always)]
575 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
576 self.instruction.payer = Some(payer);
577 self
578 }
579 #[inline(always)]
582 pub fn owner(
583 &mut self,
584 owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
585 ) -> &mut Self {
586 self.instruction.owner = owner;
587 self
588 }
589 #[inline(always)]
592 pub fn update_authority(
593 &mut self,
594 update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
595 ) -> &mut Self {
596 self.instruction.update_authority = update_authority;
597 self
598 }
599 #[inline(always)]
601 pub fn system_program(
602 &mut self,
603 system_program: &'b solana_program::account_info::AccountInfo<'a>,
604 ) -> &mut Self {
605 self.instruction.system_program = Some(system_program);
606 self
607 }
608 #[inline(always)]
611 pub fn log_wrapper(
612 &mut self,
613 log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
614 ) -> &mut Self {
615 self.instruction.log_wrapper = log_wrapper;
616 self
617 }
618 #[inline(always)]
620 pub fn data_state(&mut self, data_state: DataState) -> &mut Self {
621 self.instruction.data_state = Some(data_state);
622 self
623 }
624 #[inline(always)]
625 pub fn name(&mut self, name: String) -> &mut Self {
626 self.instruction.name = Some(name);
627 self
628 }
629 #[inline(always)]
630 pub fn uri(&mut self, uri: String) -> &mut Self {
631 self.instruction.uri = Some(uri);
632 self
633 }
634 #[inline(always)]
636 pub fn plugins(&mut self, plugins: Vec<PluginAuthorityPair>) -> &mut Self {
637 self.instruction.plugins = Some(plugins);
638 self
639 }
640 #[inline(always)]
642 pub fn add_remaining_account(
643 &mut self,
644 account: &'b solana_program::account_info::AccountInfo<'a>,
645 is_writable: bool,
646 is_signer: bool,
647 ) -> &mut Self {
648 self.instruction
649 .__remaining_accounts
650 .push((account, is_writable, is_signer));
651 self
652 }
653 #[inline(always)]
658 pub fn add_remaining_accounts(
659 &mut self,
660 accounts: &[(
661 &'b solana_program::account_info::AccountInfo<'a>,
662 bool,
663 bool,
664 )],
665 ) -> &mut Self {
666 self.instruction
667 .__remaining_accounts
668 .extend_from_slice(accounts);
669 self
670 }
671 #[inline(always)]
672 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
673 self.invoke_signed(&[])
674 }
675 #[allow(clippy::clone_on_copy)]
676 #[allow(clippy::vec_init_then_push)]
677 pub fn invoke_signed(
678 &self,
679 signers_seeds: &[&[&[u8]]],
680 ) -> solana_program::entrypoint::ProgramResult {
681 let args = CreateV1InstructionArgs {
682 data_state: self
683 .instruction
684 .data_state
685 .clone()
686 .unwrap_or(DataState::AccountState),
687 name: self.instruction.name.clone().expect("name is not set"),
688 uri: self.instruction.uri.clone().expect("uri is not set"),
689 plugins: self.instruction.plugins.clone(),
690 };
691 let instruction = CreateV1Cpi {
692 __program: self.instruction.__program,
693
694 asset: self.instruction.asset.expect("asset is not set"),
695
696 collection: self.instruction.collection,
697
698 authority: self.instruction.authority,
699
700 payer: self.instruction.payer.expect("payer is not set"),
701
702 owner: self.instruction.owner,
703
704 update_authority: self.instruction.update_authority,
705
706 system_program: self
707 .instruction
708 .system_program
709 .expect("system_program is not set"),
710
711 log_wrapper: self.instruction.log_wrapper,
712 __args: args,
713 };
714 instruction.invoke_signed_with_remaining_accounts(
715 signers_seeds,
716 &self.instruction.__remaining_accounts,
717 )
718 }
719}
720
721struct CreateV1CpiBuilderInstruction<'a, 'b> {
722 __program: &'b solana_program::account_info::AccountInfo<'a>,
723 asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
724 collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
725 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
726 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
727 owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
728 update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
729 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
730 log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
731 data_state: Option<DataState>,
732 name: Option<String>,
733 uri: Option<String>,
734 plugins: Option<Vec<PluginAuthorityPair>>,
735 __remaining_accounts: Vec<(
737 &'b solana_program::account_info::AccountInfo<'a>,
738 bool,
739 bool,
740 )>,
741}