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