1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct VerifyCollectionV1 {
13 pub authority: solana_program::pubkey::Pubkey,
15 pub delegate_record: Option<solana_program::pubkey::Pubkey>,
17 pub metadata: solana_program::pubkey::Pubkey,
19 pub collection_mint: solana_program::pubkey::Pubkey,
21 pub collection_metadata: Option<solana_program::pubkey::Pubkey>,
23 pub collection_master_edition: Option<solana_program::pubkey::Pubkey>,
25 pub system_program: solana_program::pubkey::Pubkey,
27 pub sysvar_instructions: solana_program::pubkey::Pubkey,
29}
30
31impl VerifyCollectionV1 {
32 pub fn instruction(&self) -> solana_program::instruction::Instruction {
33 self.instruction_with_remaining_accounts(&[])
34 }
35 #[allow(clippy::vec_init_then_push)]
36 pub fn instruction_with_remaining_accounts(
37 &self,
38 remaining_accounts: &[solana_program::instruction::AccountMeta],
39 ) -> solana_program::instruction::Instruction {
40 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
41 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42 self.authority,
43 true,
44 ));
45 if let Some(delegate_record) = self.delegate_record {
46 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
47 delegate_record,
48 false,
49 ));
50 } else {
51 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
52 crate::MPL_TOKEN_METADATA_ID,
53 false,
54 ));
55 }
56 accounts.push(solana_program::instruction::AccountMeta::new(
57 self.metadata,
58 false,
59 ));
60 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
61 self.collection_mint,
62 false,
63 ));
64 if let Some(collection_metadata) = self.collection_metadata {
65 accounts.push(solana_program::instruction::AccountMeta::new(
66 collection_metadata,
67 false,
68 ));
69 } else {
70 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
71 crate::MPL_TOKEN_METADATA_ID,
72 false,
73 ));
74 }
75 if let Some(collection_master_edition) = self.collection_master_edition {
76 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
77 collection_master_edition,
78 false,
79 ));
80 } else {
81 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
82 crate::MPL_TOKEN_METADATA_ID,
83 false,
84 ));
85 }
86 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
87 self.system_program,
88 false,
89 ));
90 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
91 self.sysvar_instructions,
92 false,
93 ));
94 accounts.extend_from_slice(remaining_accounts);
95 let data = VerifyCollectionV1InstructionData::new()
96 .try_to_vec()
97 .unwrap();
98
99 solana_program::instruction::Instruction {
100 program_id: crate::MPL_TOKEN_METADATA_ID,
101 accounts,
102 data,
103 }
104 }
105}
106
107#[derive(BorshDeserialize, BorshSerialize)]
108struct VerifyCollectionV1InstructionData {
109 discriminator: u8,
110 verify_collection_v1_discriminator: u8,
111}
112
113impl VerifyCollectionV1InstructionData {
114 fn new() -> Self {
115 Self {
116 discriminator: 52,
117 verify_collection_v1_discriminator: 1,
118 }
119 }
120}
121
122#[derive(Default)]
135pub struct VerifyCollectionV1Builder {
136 authority: Option<solana_program::pubkey::Pubkey>,
137 delegate_record: Option<solana_program::pubkey::Pubkey>,
138 metadata: Option<solana_program::pubkey::Pubkey>,
139 collection_mint: Option<solana_program::pubkey::Pubkey>,
140 collection_metadata: Option<solana_program::pubkey::Pubkey>,
141 collection_master_edition: Option<solana_program::pubkey::Pubkey>,
142 system_program: Option<solana_program::pubkey::Pubkey>,
143 sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
144 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
145}
146
147impl VerifyCollectionV1Builder {
148 pub fn new() -> Self {
149 Self::default()
150 }
151 #[inline(always)]
153 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
154 self.authority = Some(authority);
155 self
156 }
157 #[inline(always)]
160 pub fn delegate_record(
161 &mut self,
162 delegate_record: Option<solana_program::pubkey::Pubkey>,
163 ) -> &mut Self {
164 self.delegate_record = delegate_record;
165 self
166 }
167 #[inline(always)]
169 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
170 self.metadata = Some(metadata);
171 self
172 }
173 #[inline(always)]
175 pub fn collection_mint(
176 &mut self,
177 collection_mint: solana_program::pubkey::Pubkey,
178 ) -> &mut Self {
179 self.collection_mint = Some(collection_mint);
180 self
181 }
182 #[inline(always)]
185 pub fn collection_metadata(
186 &mut self,
187 collection_metadata: Option<solana_program::pubkey::Pubkey>,
188 ) -> &mut Self {
189 self.collection_metadata = collection_metadata;
190 self
191 }
192 #[inline(always)]
195 pub fn collection_master_edition(
196 &mut self,
197 collection_master_edition: Option<solana_program::pubkey::Pubkey>,
198 ) -> &mut Self {
199 self.collection_master_edition = collection_master_edition;
200 self
201 }
202 #[inline(always)]
205 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
206 self.system_program = Some(system_program);
207 self
208 }
209 #[inline(always)]
212 pub fn sysvar_instructions(
213 &mut self,
214 sysvar_instructions: solana_program::pubkey::Pubkey,
215 ) -> &mut Self {
216 self.sysvar_instructions = Some(sysvar_instructions);
217 self
218 }
219 #[inline(always)]
221 pub fn add_remaining_account(
222 &mut self,
223 account: solana_program::instruction::AccountMeta,
224 ) -> &mut Self {
225 self.__remaining_accounts.push(account);
226 self
227 }
228 #[inline(always)]
230 pub fn add_remaining_accounts(
231 &mut self,
232 accounts: &[solana_program::instruction::AccountMeta],
233 ) -> &mut Self {
234 self.__remaining_accounts.extend_from_slice(accounts);
235 self
236 }
237 #[allow(clippy::clone_on_copy)]
238 pub fn instruction(&self) -> solana_program::instruction::Instruction {
239 let accounts = VerifyCollectionV1 {
240 authority: self.authority.expect("authority is not set"),
241 delegate_record: self.delegate_record,
242 metadata: self.metadata.expect("metadata is not set"),
243 collection_mint: self.collection_mint.expect("collection_mint is not set"),
244 collection_metadata: self.collection_metadata,
245 collection_master_edition: self.collection_master_edition,
246 system_program: self
247 .system_program
248 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
249 sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
250 "Sysvar1nstructions1111111111111111111111111"
251 )),
252 };
253
254 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
255 }
256}
257
258pub struct VerifyCollectionV1CpiAccounts<'a, 'b> {
260 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
262 pub delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
264 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
266 pub collection_mint: &'b solana_program::account_info::AccountInfo<'a>,
268 pub collection_metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
270 pub collection_master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
272 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
274 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
276}
277
278pub struct VerifyCollectionV1Cpi<'a, 'b> {
280 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
282 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
284 pub delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
286 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
288 pub collection_mint: &'b solana_program::account_info::AccountInfo<'a>,
290 pub collection_metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
292 pub collection_master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
294 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
296 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
298}
299
300impl<'a, 'b> VerifyCollectionV1Cpi<'a, 'b> {
301 pub fn new(
302 program: &'b solana_program::account_info::AccountInfo<'a>,
303 accounts: VerifyCollectionV1CpiAccounts<'a, 'b>,
304 ) -> Self {
305 Self {
306 __program: program,
307 authority: accounts.authority,
308 delegate_record: accounts.delegate_record,
309 metadata: accounts.metadata,
310 collection_mint: accounts.collection_mint,
311 collection_metadata: accounts.collection_metadata,
312 collection_master_edition: accounts.collection_master_edition,
313 system_program: accounts.system_program,
314 sysvar_instructions: accounts.sysvar_instructions,
315 }
316 }
317 #[inline(always)]
318 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
319 self.invoke_signed_with_remaining_accounts(&[], &[])
320 }
321 #[inline(always)]
322 pub fn invoke_with_remaining_accounts(
323 &self,
324 remaining_accounts: &[(
325 &'b solana_program::account_info::AccountInfo<'a>,
326 bool,
327 bool,
328 )],
329 ) -> solana_program::entrypoint::ProgramResult {
330 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
331 }
332 #[inline(always)]
333 pub fn invoke_signed(
334 &self,
335 signers_seeds: &[&[&[u8]]],
336 ) -> solana_program::entrypoint::ProgramResult {
337 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
338 }
339 #[allow(clippy::clone_on_copy)]
340 #[allow(clippy::vec_init_then_push)]
341 pub fn invoke_signed_with_remaining_accounts(
342 &self,
343 signers_seeds: &[&[&[u8]]],
344 remaining_accounts: &[(
345 &'b solana_program::account_info::AccountInfo<'a>,
346 bool,
347 bool,
348 )],
349 ) -> solana_program::entrypoint::ProgramResult {
350 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
351 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
352 *self.authority.key,
353 true,
354 ));
355 if let Some(delegate_record) = self.delegate_record {
356 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
357 *delegate_record.key,
358 false,
359 ));
360 } else {
361 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
362 crate::MPL_TOKEN_METADATA_ID,
363 false,
364 ));
365 }
366 accounts.push(solana_program::instruction::AccountMeta::new(
367 *self.metadata.key,
368 false,
369 ));
370 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
371 *self.collection_mint.key,
372 false,
373 ));
374 if let Some(collection_metadata) = self.collection_metadata {
375 accounts.push(solana_program::instruction::AccountMeta::new(
376 *collection_metadata.key,
377 false,
378 ));
379 } else {
380 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
381 crate::MPL_TOKEN_METADATA_ID,
382 false,
383 ));
384 }
385 if let Some(collection_master_edition) = self.collection_master_edition {
386 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
387 *collection_master_edition.key,
388 false,
389 ));
390 } else {
391 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
392 crate::MPL_TOKEN_METADATA_ID,
393 false,
394 ));
395 }
396 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
397 *self.system_program.key,
398 false,
399 ));
400 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
401 *self.sysvar_instructions.key,
402 false,
403 ));
404 remaining_accounts.iter().for_each(|remaining_account| {
405 accounts.push(solana_program::instruction::AccountMeta {
406 pubkey: *remaining_account.0.key,
407 is_signer: remaining_account.1,
408 is_writable: remaining_account.2,
409 })
410 });
411 let data = VerifyCollectionV1InstructionData::new()
412 .try_to_vec()
413 .unwrap();
414
415 let instruction = solana_program::instruction::Instruction {
416 program_id: crate::MPL_TOKEN_METADATA_ID,
417 accounts,
418 data,
419 };
420 let mut account_infos = Vec::with_capacity(8 + 1 + remaining_accounts.len());
421 account_infos.push(self.__program.clone());
422 account_infos.push(self.authority.clone());
423 if let Some(delegate_record) = self.delegate_record {
424 account_infos.push(delegate_record.clone());
425 }
426 account_infos.push(self.metadata.clone());
427 account_infos.push(self.collection_mint.clone());
428 if let Some(collection_metadata) = self.collection_metadata {
429 account_infos.push(collection_metadata.clone());
430 }
431 if let Some(collection_master_edition) = self.collection_master_edition {
432 account_infos.push(collection_master_edition.clone());
433 }
434 account_infos.push(self.system_program.clone());
435 account_infos.push(self.sysvar_instructions.clone());
436 remaining_accounts
437 .iter()
438 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
439
440 if signers_seeds.is_empty() {
441 solana_program::program::invoke(&instruction, &account_infos)
442 } else {
443 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
444 }
445 }
446}
447
448pub struct VerifyCollectionV1CpiBuilder<'a, 'b> {
461 instruction: Box<VerifyCollectionV1CpiBuilderInstruction<'a, 'b>>,
462}
463
464impl<'a, 'b> VerifyCollectionV1CpiBuilder<'a, 'b> {
465 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
466 let instruction = Box::new(VerifyCollectionV1CpiBuilderInstruction {
467 __program: program,
468 authority: None,
469 delegate_record: None,
470 metadata: None,
471 collection_mint: None,
472 collection_metadata: None,
473 collection_master_edition: None,
474 system_program: None,
475 sysvar_instructions: None,
476 __remaining_accounts: Vec::new(),
477 });
478 Self { instruction }
479 }
480 #[inline(always)]
482 pub fn authority(
483 &mut self,
484 authority: &'b solana_program::account_info::AccountInfo<'a>,
485 ) -> &mut Self {
486 self.instruction.authority = Some(authority);
487 self
488 }
489 #[inline(always)]
492 pub fn delegate_record(
493 &mut self,
494 delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
495 ) -> &mut Self {
496 self.instruction.delegate_record = delegate_record;
497 self
498 }
499 #[inline(always)]
501 pub fn metadata(
502 &mut self,
503 metadata: &'b solana_program::account_info::AccountInfo<'a>,
504 ) -> &mut Self {
505 self.instruction.metadata = Some(metadata);
506 self
507 }
508 #[inline(always)]
510 pub fn collection_mint(
511 &mut self,
512 collection_mint: &'b solana_program::account_info::AccountInfo<'a>,
513 ) -> &mut Self {
514 self.instruction.collection_mint = Some(collection_mint);
515 self
516 }
517 #[inline(always)]
520 pub fn collection_metadata(
521 &mut self,
522 collection_metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
523 ) -> &mut Self {
524 self.instruction.collection_metadata = collection_metadata;
525 self
526 }
527 #[inline(always)]
530 pub fn collection_master_edition(
531 &mut self,
532 collection_master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
533 ) -> &mut Self {
534 self.instruction.collection_master_edition = collection_master_edition;
535 self
536 }
537 #[inline(always)]
539 pub fn system_program(
540 &mut self,
541 system_program: &'b solana_program::account_info::AccountInfo<'a>,
542 ) -> &mut Self {
543 self.instruction.system_program = Some(system_program);
544 self
545 }
546 #[inline(always)]
548 pub fn sysvar_instructions(
549 &mut self,
550 sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
551 ) -> &mut Self {
552 self.instruction.sysvar_instructions = Some(sysvar_instructions);
553 self
554 }
555 #[inline(always)]
557 pub fn add_remaining_account(
558 &mut self,
559 account: &'b solana_program::account_info::AccountInfo<'a>,
560 is_writable: bool,
561 is_signer: bool,
562 ) -> &mut Self {
563 self.instruction
564 .__remaining_accounts
565 .push((account, is_writable, is_signer));
566 self
567 }
568 #[inline(always)]
573 pub fn add_remaining_accounts(
574 &mut self,
575 accounts: &[(
576 &'b solana_program::account_info::AccountInfo<'a>,
577 bool,
578 bool,
579 )],
580 ) -> &mut Self {
581 self.instruction
582 .__remaining_accounts
583 .extend_from_slice(accounts);
584 self
585 }
586 #[inline(always)]
587 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
588 self.invoke_signed(&[])
589 }
590 #[allow(clippy::clone_on_copy)]
591 #[allow(clippy::vec_init_then_push)]
592 pub fn invoke_signed(
593 &self,
594 signers_seeds: &[&[&[u8]]],
595 ) -> solana_program::entrypoint::ProgramResult {
596 let instruction = VerifyCollectionV1Cpi {
597 __program: self.instruction.__program,
598
599 authority: self.instruction.authority.expect("authority is not set"),
600
601 delegate_record: self.instruction.delegate_record,
602
603 metadata: self.instruction.metadata.expect("metadata is not set"),
604
605 collection_mint: self
606 .instruction
607 .collection_mint
608 .expect("collection_mint is not set"),
609
610 collection_metadata: self.instruction.collection_metadata,
611
612 collection_master_edition: self.instruction.collection_master_edition,
613
614 system_program: self
615 .instruction
616 .system_program
617 .expect("system_program is not set"),
618
619 sysvar_instructions: self
620 .instruction
621 .sysvar_instructions
622 .expect("sysvar_instructions is not set"),
623 };
624 instruction.invoke_signed_with_remaining_accounts(
625 signers_seeds,
626 &self.instruction.__remaining_accounts,
627 )
628 }
629}
630
631struct VerifyCollectionV1CpiBuilderInstruction<'a, 'b> {
632 __program: &'b solana_program::account_info::AccountInfo<'a>,
633 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
634 delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
635 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
636 collection_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
637 collection_metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
638 collection_master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
639 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
640 sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
641 __remaining_accounts: Vec<(
643 &'b solana_program::account_info::AccountInfo<'a>,
644 bool,
645 bool,
646 )>,
647}