1#[cfg(feature = "anchor")]
9use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
10#[cfg(not(feature = "anchor"))]
11use borsh::{BorshDeserialize, BorshSerialize};
12
13pub struct UpdateCollectionV1 {
15 pub collection: solana_program::pubkey::Pubkey,
17 pub payer: solana_program::pubkey::Pubkey,
19 pub authority: Option<solana_program::pubkey::Pubkey>,
21 pub new_update_authority: Option<solana_program::pubkey::Pubkey>,
23 pub system_program: solana_program::pubkey::Pubkey,
25 pub log_wrapper: Option<solana_program::pubkey::Pubkey>,
27}
28
29impl UpdateCollectionV1 {
30 pub fn instruction(
31 &self,
32 args: UpdateCollectionV1InstructionArgs,
33 ) -> solana_program::instruction::Instruction {
34 self.instruction_with_remaining_accounts(args, &[])
35 }
36 #[allow(clippy::vec_init_then_push)]
37 pub fn instruction_with_remaining_accounts(
38 &self,
39 args: UpdateCollectionV1InstructionArgs,
40 remaining_accounts: &[solana_program::instruction::AccountMeta],
41 ) -> solana_program::instruction::Instruction {
42 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
43 accounts.push(solana_program::instruction::AccountMeta::new(
44 self.collection,
45 false,
46 ));
47 accounts.push(solana_program::instruction::AccountMeta::new(
48 self.payer, true,
49 ));
50 if let Some(authority) = self.authority {
51 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
52 authority, true,
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(new_update_authority) = self.new_update_authority {
61 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
62 new_update_authority,
63 false,
64 ));
65 } else {
66 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
67 crate::MPL_CORE_ID,
68 false,
69 ));
70 }
71 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
72 self.system_program,
73 false,
74 ));
75 if let Some(log_wrapper) = self.log_wrapper {
76 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
77 log_wrapper,
78 false,
79 ));
80 } else {
81 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
82 crate::MPL_CORE_ID,
83 false,
84 ));
85 }
86 accounts.extend_from_slice(remaining_accounts);
87 let mut data = UpdateCollectionV1InstructionData::new()
88 .try_to_vec()
89 .unwrap();
90 let mut args = args.try_to_vec().unwrap();
91 data.append(&mut args);
92
93 solana_program::instruction::Instruction {
94 program_id: crate::MPL_CORE_ID,
95 accounts,
96 data,
97 }
98 }
99}
100
101#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
102#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
103pub struct UpdateCollectionV1InstructionData {
104 discriminator: u8,
105}
106
107impl UpdateCollectionV1InstructionData {
108 pub fn new() -> Self {
109 Self { discriminator: 16 }
110 }
111}
112
113#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
114#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
115#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
116#[derive(Clone, Debug, Eq, PartialEq)]
117pub struct UpdateCollectionV1InstructionArgs {
118 pub new_name: Option<String>,
119 pub new_uri: Option<String>,
120}
121
122#[derive(Default)]
133pub struct UpdateCollectionV1Builder {
134 collection: Option<solana_program::pubkey::Pubkey>,
135 payer: Option<solana_program::pubkey::Pubkey>,
136 authority: Option<solana_program::pubkey::Pubkey>,
137 new_update_authority: Option<solana_program::pubkey::Pubkey>,
138 system_program: Option<solana_program::pubkey::Pubkey>,
139 log_wrapper: Option<solana_program::pubkey::Pubkey>,
140 new_name: Option<String>,
141 new_uri: Option<String>,
142 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
143}
144
145impl UpdateCollectionV1Builder {
146 pub fn new() -> Self {
147 Self::default()
148 }
149 #[inline(always)]
151 pub fn collection(&mut self, collection: solana_program::pubkey::Pubkey) -> &mut Self {
152 self.collection = Some(collection);
153 self
154 }
155 #[inline(always)]
157 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
158 self.payer = Some(payer);
159 self
160 }
161 #[inline(always)]
164 pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
165 self.authority = authority;
166 self
167 }
168 #[inline(always)]
171 pub fn new_update_authority(
172 &mut self,
173 new_update_authority: Option<solana_program::pubkey::Pubkey>,
174 ) -> &mut Self {
175 self.new_update_authority = new_update_authority;
176 self
177 }
178 #[inline(always)]
181 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
182 self.system_program = Some(system_program);
183 self
184 }
185 #[inline(always)]
188 pub fn log_wrapper(
189 &mut self,
190 log_wrapper: Option<solana_program::pubkey::Pubkey>,
191 ) -> &mut Self {
192 self.log_wrapper = log_wrapper;
193 self
194 }
195 #[inline(always)]
197 pub fn new_name(&mut self, new_name: String) -> &mut Self {
198 self.new_name = Some(new_name);
199 self
200 }
201 #[inline(always)]
203 pub fn new_uri(&mut self, new_uri: String) -> &mut Self {
204 self.new_uri = Some(new_uri);
205 self
206 }
207 #[inline(always)]
209 pub fn add_remaining_account(
210 &mut self,
211 account: solana_program::instruction::AccountMeta,
212 ) -> &mut Self {
213 self.__remaining_accounts.push(account);
214 self
215 }
216 #[inline(always)]
218 pub fn add_remaining_accounts(
219 &mut self,
220 accounts: &[solana_program::instruction::AccountMeta],
221 ) -> &mut Self {
222 self.__remaining_accounts.extend_from_slice(accounts);
223 self
224 }
225 #[allow(clippy::clone_on_copy)]
226 pub fn instruction(&self) -> solana_program::instruction::Instruction {
227 let accounts = UpdateCollectionV1 {
228 collection: self.collection.expect("collection is not set"),
229 payer: self.payer.expect("payer is not set"),
230 authority: self.authority,
231 new_update_authority: self.new_update_authority,
232 system_program: self
233 .system_program
234 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
235 log_wrapper: self.log_wrapper,
236 };
237 let args = UpdateCollectionV1InstructionArgs {
238 new_name: self.new_name.clone(),
239 new_uri: self.new_uri.clone(),
240 };
241
242 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
243 }
244}
245
246pub struct UpdateCollectionV1CpiAccounts<'a, 'b> {
248 pub collection: &'b solana_program::account_info::AccountInfo<'a>,
250 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
252 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
254 pub new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
256 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
258 pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
260}
261
262pub struct UpdateCollectionV1Cpi<'a, 'b> {
264 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
266 pub collection: &'b solana_program::account_info::AccountInfo<'a>,
268 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
270 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
272 pub new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
274 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
276 pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
278 pub __args: UpdateCollectionV1InstructionArgs,
280}
281
282impl<'a, 'b> UpdateCollectionV1Cpi<'a, 'b> {
283 pub fn new(
284 program: &'b solana_program::account_info::AccountInfo<'a>,
285 accounts: UpdateCollectionV1CpiAccounts<'a, 'b>,
286 args: UpdateCollectionV1InstructionArgs,
287 ) -> Self {
288 Self {
289 __program: program,
290 collection: accounts.collection,
291 payer: accounts.payer,
292 authority: accounts.authority,
293 new_update_authority: accounts.new_update_authority,
294 system_program: accounts.system_program,
295 log_wrapper: accounts.log_wrapper,
296 __args: args,
297 }
298 }
299 #[inline(always)]
300 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
301 self.invoke_signed_with_remaining_accounts(&[], &[])
302 }
303 #[inline(always)]
304 pub fn invoke_with_remaining_accounts(
305 &self,
306 remaining_accounts: &[(
307 &'b solana_program::account_info::AccountInfo<'a>,
308 bool,
309 bool,
310 )],
311 ) -> solana_program::entrypoint::ProgramResult {
312 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
313 }
314 #[inline(always)]
315 pub fn invoke_signed(
316 &self,
317 signers_seeds: &[&[&[u8]]],
318 ) -> solana_program::entrypoint::ProgramResult {
319 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
320 }
321 #[allow(clippy::clone_on_copy)]
322 #[allow(clippy::vec_init_then_push)]
323 pub fn invoke_signed_with_remaining_accounts(
324 &self,
325 signers_seeds: &[&[&[u8]]],
326 remaining_accounts: &[(
327 &'b solana_program::account_info::AccountInfo<'a>,
328 bool,
329 bool,
330 )],
331 ) -> solana_program::entrypoint::ProgramResult {
332 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
333 accounts.push(solana_program::instruction::AccountMeta::new(
334 *self.collection.key,
335 false,
336 ));
337 accounts.push(solana_program::instruction::AccountMeta::new(
338 *self.payer.key,
339 true,
340 ));
341 if let Some(authority) = self.authority {
342 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
343 *authority.key,
344 true,
345 ));
346 } else {
347 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
348 crate::MPL_CORE_ID,
349 false,
350 ));
351 }
352 if let Some(new_update_authority) = self.new_update_authority {
353 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
354 *new_update_authority.key,
355 false,
356 ));
357 } else {
358 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
359 crate::MPL_CORE_ID,
360 false,
361 ));
362 }
363 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
364 *self.system_program.key,
365 false,
366 ));
367 if let Some(log_wrapper) = self.log_wrapper {
368 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
369 *log_wrapper.key,
370 false,
371 ));
372 } else {
373 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
374 crate::MPL_CORE_ID,
375 false,
376 ));
377 }
378 remaining_accounts.iter().for_each(|remaining_account| {
379 accounts.push(solana_program::instruction::AccountMeta {
380 pubkey: *remaining_account.0.key,
381 is_signer: remaining_account.1,
382 is_writable: remaining_account.2,
383 })
384 });
385 let mut data = UpdateCollectionV1InstructionData::new()
386 .try_to_vec()
387 .unwrap();
388 let mut args = self.__args.try_to_vec().unwrap();
389 data.append(&mut args);
390
391 let instruction = solana_program::instruction::Instruction {
392 program_id: crate::MPL_CORE_ID,
393 accounts,
394 data,
395 };
396 let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len());
397 account_infos.push(self.__program.clone());
398 account_infos.push(self.collection.clone());
399 account_infos.push(self.payer.clone());
400 if let Some(authority) = self.authority {
401 account_infos.push(authority.clone());
402 }
403 if let Some(new_update_authority) = self.new_update_authority {
404 account_infos.push(new_update_authority.clone());
405 }
406 account_infos.push(self.system_program.clone());
407 if let Some(log_wrapper) = self.log_wrapper {
408 account_infos.push(log_wrapper.clone());
409 }
410 remaining_accounts
411 .iter()
412 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
413
414 if signers_seeds.is_empty() {
415 solana_program::program::invoke(&instruction, &account_infos)
416 } else {
417 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
418 }
419 }
420}
421
422pub struct UpdateCollectionV1CpiBuilder<'a, 'b> {
433 instruction: Box<UpdateCollectionV1CpiBuilderInstruction<'a, 'b>>,
434}
435
436impl<'a, 'b> UpdateCollectionV1CpiBuilder<'a, 'b> {
437 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
438 let instruction = Box::new(UpdateCollectionV1CpiBuilderInstruction {
439 __program: program,
440 collection: None,
441 payer: None,
442 authority: None,
443 new_update_authority: None,
444 system_program: None,
445 log_wrapper: None,
446 new_name: None,
447 new_uri: None,
448 __remaining_accounts: Vec::new(),
449 });
450 Self { instruction }
451 }
452 #[inline(always)]
454 pub fn collection(
455 &mut self,
456 collection: &'b solana_program::account_info::AccountInfo<'a>,
457 ) -> &mut Self {
458 self.instruction.collection = Some(collection);
459 self
460 }
461 #[inline(always)]
463 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
464 self.instruction.payer = Some(payer);
465 self
466 }
467 #[inline(always)]
470 pub fn authority(
471 &mut self,
472 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
473 ) -> &mut Self {
474 self.instruction.authority = authority;
475 self
476 }
477 #[inline(always)]
480 pub fn new_update_authority(
481 &mut self,
482 new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
483 ) -> &mut Self {
484 self.instruction.new_update_authority = new_update_authority;
485 self
486 }
487 #[inline(always)]
489 pub fn system_program(
490 &mut self,
491 system_program: &'b solana_program::account_info::AccountInfo<'a>,
492 ) -> &mut Self {
493 self.instruction.system_program = Some(system_program);
494 self
495 }
496 #[inline(always)]
499 pub fn log_wrapper(
500 &mut self,
501 log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
502 ) -> &mut Self {
503 self.instruction.log_wrapper = log_wrapper;
504 self
505 }
506 #[inline(always)]
508 pub fn new_name(&mut self, new_name: String) -> &mut Self {
509 self.instruction.new_name = Some(new_name);
510 self
511 }
512 #[inline(always)]
514 pub fn new_uri(&mut self, new_uri: String) -> &mut Self {
515 self.instruction.new_uri = Some(new_uri);
516 self
517 }
518 #[inline(always)]
520 pub fn add_remaining_account(
521 &mut self,
522 account: &'b solana_program::account_info::AccountInfo<'a>,
523 is_writable: bool,
524 is_signer: bool,
525 ) -> &mut Self {
526 self.instruction
527 .__remaining_accounts
528 .push((account, is_writable, is_signer));
529 self
530 }
531 #[inline(always)]
536 pub fn add_remaining_accounts(
537 &mut self,
538 accounts: &[(
539 &'b solana_program::account_info::AccountInfo<'a>,
540 bool,
541 bool,
542 )],
543 ) -> &mut Self {
544 self.instruction
545 .__remaining_accounts
546 .extend_from_slice(accounts);
547 self
548 }
549 #[inline(always)]
550 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
551 self.invoke_signed(&[])
552 }
553 #[allow(clippy::clone_on_copy)]
554 #[allow(clippy::vec_init_then_push)]
555 pub fn invoke_signed(
556 &self,
557 signers_seeds: &[&[&[u8]]],
558 ) -> solana_program::entrypoint::ProgramResult {
559 let args = UpdateCollectionV1InstructionArgs {
560 new_name: self.instruction.new_name.clone(),
561 new_uri: self.instruction.new_uri.clone(),
562 };
563 let instruction = UpdateCollectionV1Cpi {
564 __program: self.instruction.__program,
565
566 collection: self.instruction.collection.expect("collection is not set"),
567
568 payer: self.instruction.payer.expect("payer is not set"),
569
570 authority: self.instruction.authority,
571
572 new_update_authority: self.instruction.new_update_authority,
573
574 system_program: self
575 .instruction
576 .system_program
577 .expect("system_program is not set"),
578
579 log_wrapper: self.instruction.log_wrapper,
580 __args: args,
581 };
582 instruction.invoke_signed_with_remaining_accounts(
583 signers_seeds,
584 &self.instruction.__remaining_accounts,
585 )
586 }
587}
588
589struct UpdateCollectionV1CpiBuilderInstruction<'a, 'b> {
590 __program: &'b solana_program::account_info::AccountInfo<'a>,
591 collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
592 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
593 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
594 new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
595 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
596 log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
597 new_name: Option<String>,
598 new_uri: Option<String>,
599 __remaining_accounts: Vec<(
601 &'b solana_program::account_info::AccountInfo<'a>,
602 bool,
603 bool,
604 )>,
605}