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