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