mpl_core/generated/instructions/
update_v2.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! [https://github.com/metaplex-foundation/kinobi]
6//!
7
8use crate::generated::types::UpdateAuthority;
9#[cfg(feature = "anchor")]
10use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
11#[cfg(not(feature = "anchor"))]
12use borsh::{BorshDeserialize, BorshSerialize};
13
14/// Accounts.
15pub struct UpdateV2 {
16    /// The address of the asset
17    pub asset: solana_program::pubkey::Pubkey,
18    /// The collection to which the asset belongs
19    pub collection: Option<solana_program::pubkey::Pubkey>,
20    /// The account paying for the storage fees
21    pub payer: solana_program::pubkey::Pubkey,
22    /// The update authority or update authority delegate of the asset
23    pub authority: Option<solana_program::pubkey::Pubkey>,
24    /// A new collection to which to move the asset
25    pub new_collection: Option<solana_program::pubkey::Pubkey>,
26    /// The system program
27    pub system_program: solana_program::pubkey::Pubkey,
28    /// The SPL Noop Program
29    pub log_wrapper: Option<solana_program::pubkey::Pubkey>,
30}
31
32impl UpdateV2 {
33    pub fn instruction(
34        &self,
35        args: UpdateV2InstructionArgs,
36    ) -> solana_program::instruction::Instruction {
37        self.instruction_with_remaining_accounts(args, &[])
38    }
39    #[allow(clippy::vec_init_then_push)]
40    pub fn instruction_with_remaining_accounts(
41        &self,
42        args: UpdateV2InstructionArgs,
43        remaining_accounts: &[solana_program::instruction::AccountMeta],
44    ) -> solana_program::instruction::Instruction {
45        let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
46        accounts.push(solana_program::instruction::AccountMeta::new(
47            self.asset, false,
48        ));
49        if let Some(collection) = self.collection {
50            accounts.push(solana_program::instruction::AccountMeta::new(
51                collection, false,
52            ));
53        } else {
54            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
55                crate::MPL_CORE_ID,
56                false,
57            ));
58        }
59        accounts.push(solana_program::instruction::AccountMeta::new(
60            self.payer, true,
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        if let Some(new_collection) = self.new_collection {
73            accounts.push(solana_program::instruction::AccountMeta::new(
74                new_collection,
75                false,
76            ));
77        } else {
78            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
79                crate::MPL_CORE_ID,
80                false,
81            ));
82        }
83        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
84            self.system_program,
85            false,
86        ));
87        if let Some(log_wrapper) = self.log_wrapper {
88            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
89                log_wrapper,
90                false,
91            ));
92        } else {
93            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
94                crate::MPL_CORE_ID,
95                false,
96            ));
97        }
98        accounts.extend_from_slice(remaining_accounts);
99        let mut data = UpdateV2InstructionData::new().try_to_vec().unwrap();
100        let mut args = args.try_to_vec().unwrap();
101        data.append(&mut args);
102
103        solana_program::instruction::Instruction {
104            program_id: crate::MPL_CORE_ID,
105            accounts,
106            data,
107        }
108    }
109}
110
111#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
112#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
113pub struct UpdateV2InstructionData {
114    discriminator: u8,
115}
116
117impl UpdateV2InstructionData {
118    pub fn new() -> Self {
119        Self { discriminator: 30 }
120    }
121}
122
123#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
124#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
125#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
126#[derive(Clone, Debug, Eq, PartialEq)]
127pub struct UpdateV2InstructionArgs {
128    pub new_name: Option<String>,
129    pub new_uri: Option<String>,
130    pub new_update_authority: Option<UpdateAuthority>,
131}
132
133/// Instruction builder for `UpdateV2`.
134///
135/// ### Accounts:
136///
137///   0. `[writable]` asset
138///   1. `[writable, optional]` collection
139///   2. `[writable, signer]` payer
140///   3. `[signer, optional]` authority
141///   4. `[writable, optional]` new_collection
142///   5. `[optional]` system_program (default to `11111111111111111111111111111111`)
143///   6. `[optional]` log_wrapper
144#[derive(Default)]
145pub struct UpdateV2Builder {
146    asset: Option<solana_program::pubkey::Pubkey>,
147    collection: Option<solana_program::pubkey::Pubkey>,
148    payer: Option<solana_program::pubkey::Pubkey>,
149    authority: Option<solana_program::pubkey::Pubkey>,
150    new_collection: Option<solana_program::pubkey::Pubkey>,
151    system_program: Option<solana_program::pubkey::Pubkey>,
152    log_wrapper: Option<solana_program::pubkey::Pubkey>,
153    new_name: Option<String>,
154    new_uri: Option<String>,
155    new_update_authority: Option<UpdateAuthority>,
156    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
157}
158
159impl UpdateV2Builder {
160    pub fn new() -> Self {
161        Self::default()
162    }
163    /// The address of the asset
164    #[inline(always)]
165    pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
166        self.asset = Some(asset);
167        self
168    }
169    /// `[optional account]`
170    /// The collection to which the asset belongs
171    #[inline(always)]
172    pub fn collection(&mut self, collection: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
173        self.collection = collection;
174        self
175    }
176    /// The account paying for the storage fees
177    #[inline(always)]
178    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
179        self.payer = Some(payer);
180        self
181    }
182    /// `[optional account]`
183    /// The update authority or update authority delegate of the asset
184    #[inline(always)]
185    pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
186        self.authority = authority;
187        self
188    }
189    /// `[optional account]`
190    /// A new collection to which to move the asset
191    #[inline(always)]
192    pub fn new_collection(
193        &mut self,
194        new_collection: Option<solana_program::pubkey::Pubkey>,
195    ) -> &mut Self {
196        self.new_collection = new_collection;
197        self
198    }
199    /// `[optional account, default to '11111111111111111111111111111111']`
200    /// The system program
201    #[inline(always)]
202    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
203        self.system_program = Some(system_program);
204        self
205    }
206    /// `[optional account]`
207    /// The SPL Noop Program
208    #[inline(always)]
209    pub fn log_wrapper(
210        &mut self,
211        log_wrapper: Option<solana_program::pubkey::Pubkey>,
212    ) -> &mut Self {
213        self.log_wrapper = log_wrapper;
214        self
215    }
216    /// `[optional argument]`
217    #[inline(always)]
218    pub fn new_name(&mut self, new_name: String) -> &mut Self {
219        self.new_name = Some(new_name);
220        self
221    }
222    /// `[optional argument]`
223    #[inline(always)]
224    pub fn new_uri(&mut self, new_uri: String) -> &mut Self {
225        self.new_uri = Some(new_uri);
226        self
227    }
228    /// `[optional argument]`
229    #[inline(always)]
230    pub fn new_update_authority(&mut self, new_update_authority: UpdateAuthority) -> &mut Self {
231        self.new_update_authority = Some(new_update_authority);
232        self
233    }
234    /// Add an aditional account to the instruction.
235    #[inline(always)]
236    pub fn add_remaining_account(
237        &mut self,
238        account: solana_program::instruction::AccountMeta,
239    ) -> &mut Self {
240        self.__remaining_accounts.push(account);
241        self
242    }
243    /// Add additional accounts to the instruction.
244    #[inline(always)]
245    pub fn add_remaining_accounts(
246        &mut self,
247        accounts: &[solana_program::instruction::AccountMeta],
248    ) -> &mut Self {
249        self.__remaining_accounts.extend_from_slice(accounts);
250        self
251    }
252    #[allow(clippy::clone_on_copy)]
253    pub fn instruction(&self) -> solana_program::instruction::Instruction {
254        let accounts = UpdateV2 {
255            asset: self.asset.expect("asset is not set"),
256            collection: self.collection,
257            payer: self.payer.expect("payer is not set"),
258            authority: self.authority,
259            new_collection: self.new_collection,
260            system_program: self
261                .system_program
262                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
263            log_wrapper: self.log_wrapper,
264        };
265        let args = UpdateV2InstructionArgs {
266            new_name: self.new_name.clone(),
267            new_uri: self.new_uri.clone(),
268            new_update_authority: self.new_update_authority.clone(),
269        };
270
271        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
272    }
273}
274
275/// `update_v2` CPI accounts.
276pub struct UpdateV2CpiAccounts<'a, 'b> {
277    /// The address of the asset
278    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
279    /// The collection to which the asset belongs
280    pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
281    /// The account paying for the storage fees
282    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
283    /// The update authority or update authority delegate of the asset
284    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
285    /// A new collection to which to move the asset
286    pub new_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
287    /// The system program
288    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
289    /// The SPL Noop Program
290    pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
291}
292
293/// `update_v2` CPI instruction.
294pub struct UpdateV2Cpi<'a, 'b> {
295    /// The program to invoke.
296    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
297    /// The address of the asset
298    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
299    /// The collection to which the asset belongs
300    pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
301    /// The account paying for the storage fees
302    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
303    /// The update authority or update authority delegate of the asset
304    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
305    /// A new collection to which to move the asset
306    pub new_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
307    /// The system program
308    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
309    /// The SPL Noop Program
310    pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
311    /// The arguments for the instruction.
312    pub __args: UpdateV2InstructionArgs,
313}
314
315impl<'a, 'b> UpdateV2Cpi<'a, 'b> {
316    pub fn new(
317        program: &'b solana_program::account_info::AccountInfo<'a>,
318        accounts: UpdateV2CpiAccounts<'a, 'b>,
319        args: UpdateV2InstructionArgs,
320    ) -> Self {
321        Self {
322            __program: program,
323            asset: accounts.asset,
324            collection: accounts.collection,
325            payer: accounts.payer,
326            authority: accounts.authority,
327            new_collection: accounts.new_collection,
328            system_program: accounts.system_program,
329            log_wrapper: accounts.log_wrapper,
330            __args: args,
331        }
332    }
333    #[inline(always)]
334    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
335        self.invoke_signed_with_remaining_accounts(&[], &[])
336    }
337    #[inline(always)]
338    pub fn invoke_with_remaining_accounts(
339        &self,
340        remaining_accounts: &[(
341            &'b solana_program::account_info::AccountInfo<'a>,
342            bool,
343            bool,
344        )],
345    ) -> solana_program::entrypoint::ProgramResult {
346        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
347    }
348    #[inline(always)]
349    pub fn invoke_signed(
350        &self,
351        signers_seeds: &[&[&[u8]]],
352    ) -> solana_program::entrypoint::ProgramResult {
353        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
354    }
355    #[allow(clippy::clone_on_copy)]
356    #[allow(clippy::vec_init_then_push)]
357    pub fn invoke_signed_with_remaining_accounts(
358        &self,
359        signers_seeds: &[&[&[u8]]],
360        remaining_accounts: &[(
361            &'b solana_program::account_info::AccountInfo<'a>,
362            bool,
363            bool,
364        )],
365    ) -> solana_program::entrypoint::ProgramResult {
366        let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
367        accounts.push(solana_program::instruction::AccountMeta::new(
368            *self.asset.key,
369            false,
370        ));
371        if let Some(collection) = self.collection {
372            accounts.push(solana_program::instruction::AccountMeta::new(
373                *collection.key,
374                false,
375            ));
376        } else {
377            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
378                crate::MPL_CORE_ID,
379                false,
380            ));
381        }
382        accounts.push(solana_program::instruction::AccountMeta::new(
383            *self.payer.key,
384            true,
385        ));
386        if let Some(authority) = self.authority {
387            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
388                *authority.key,
389                true,
390            ));
391        } else {
392            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
393                crate::MPL_CORE_ID,
394                false,
395            ));
396        }
397        if let Some(new_collection) = self.new_collection {
398            accounts.push(solana_program::instruction::AccountMeta::new(
399                *new_collection.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        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
409            *self.system_program.key,
410            false,
411        ));
412        if let Some(log_wrapper) = self.log_wrapper {
413            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
414                *log_wrapper.key,
415                false,
416            ));
417        } else {
418            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
419                crate::MPL_CORE_ID,
420                false,
421            ));
422        }
423        remaining_accounts.iter().for_each(|remaining_account| {
424            accounts.push(solana_program::instruction::AccountMeta {
425                pubkey: *remaining_account.0.key,
426                is_signer: remaining_account.1,
427                is_writable: remaining_account.2,
428            })
429        });
430        let mut data = UpdateV2InstructionData::new().try_to_vec().unwrap();
431        let mut args = self.__args.try_to_vec().unwrap();
432        data.append(&mut args);
433
434        let instruction = solana_program::instruction::Instruction {
435            program_id: crate::MPL_CORE_ID,
436            accounts,
437            data,
438        };
439        let mut account_infos = Vec::with_capacity(7 + 1 + remaining_accounts.len());
440        account_infos.push(self.__program.clone());
441        account_infos.push(self.asset.clone());
442        if let Some(collection) = self.collection {
443            account_infos.push(collection.clone());
444        }
445        account_infos.push(self.payer.clone());
446        if let Some(authority) = self.authority {
447            account_infos.push(authority.clone());
448        }
449        if let Some(new_collection) = self.new_collection {
450            account_infos.push(new_collection.clone());
451        }
452        account_infos.push(self.system_program.clone());
453        if let Some(log_wrapper) = self.log_wrapper {
454            account_infos.push(log_wrapper.clone());
455        }
456        remaining_accounts
457            .iter()
458            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
459
460        if signers_seeds.is_empty() {
461            solana_program::program::invoke(&instruction, &account_infos)
462        } else {
463            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
464        }
465    }
466}
467
468/// Instruction builder for `UpdateV2` via CPI.
469///
470/// ### Accounts:
471///
472///   0. `[writable]` asset
473///   1. `[writable, optional]` collection
474///   2. `[writable, signer]` payer
475///   3. `[signer, optional]` authority
476///   4. `[writable, optional]` new_collection
477///   5. `[]` system_program
478///   6. `[optional]` log_wrapper
479pub struct UpdateV2CpiBuilder<'a, 'b> {
480    instruction: Box<UpdateV2CpiBuilderInstruction<'a, 'b>>,
481}
482
483impl<'a, 'b> UpdateV2CpiBuilder<'a, 'b> {
484    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
485        let instruction = Box::new(UpdateV2CpiBuilderInstruction {
486            __program: program,
487            asset: None,
488            collection: None,
489            payer: None,
490            authority: None,
491            new_collection: None,
492            system_program: None,
493            log_wrapper: None,
494            new_name: None,
495            new_uri: None,
496            new_update_authority: None,
497            __remaining_accounts: Vec::new(),
498        });
499        Self { instruction }
500    }
501    /// The address of the asset
502    #[inline(always)]
503    pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
504        self.instruction.asset = Some(asset);
505        self
506    }
507    /// `[optional account]`
508    /// The collection to which the asset belongs
509    #[inline(always)]
510    pub fn collection(
511        &mut self,
512        collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
513    ) -> &mut Self {
514        self.instruction.collection = collection;
515        self
516    }
517    /// The account paying for the storage fees
518    #[inline(always)]
519    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
520        self.instruction.payer = Some(payer);
521        self
522    }
523    /// `[optional account]`
524    /// The update authority or update authority delegate of the asset
525    #[inline(always)]
526    pub fn authority(
527        &mut self,
528        authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
529    ) -> &mut Self {
530        self.instruction.authority = authority;
531        self
532    }
533    /// `[optional account]`
534    /// A new collection to which to move the asset
535    #[inline(always)]
536    pub fn new_collection(
537        &mut self,
538        new_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
539    ) -> &mut Self {
540        self.instruction.new_collection = new_collection;
541        self
542    }
543    /// The system program
544    #[inline(always)]
545    pub fn system_program(
546        &mut self,
547        system_program: &'b solana_program::account_info::AccountInfo<'a>,
548    ) -> &mut Self {
549        self.instruction.system_program = Some(system_program);
550        self
551    }
552    /// `[optional account]`
553    /// The SPL Noop Program
554    #[inline(always)]
555    pub fn log_wrapper(
556        &mut self,
557        log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
558    ) -> &mut Self {
559        self.instruction.log_wrapper = log_wrapper;
560        self
561    }
562    /// `[optional argument]`
563    #[inline(always)]
564    pub fn new_name(&mut self, new_name: String) -> &mut Self {
565        self.instruction.new_name = Some(new_name);
566        self
567    }
568    /// `[optional argument]`
569    #[inline(always)]
570    pub fn new_uri(&mut self, new_uri: String) -> &mut Self {
571        self.instruction.new_uri = Some(new_uri);
572        self
573    }
574    /// `[optional argument]`
575    #[inline(always)]
576    pub fn new_update_authority(&mut self, new_update_authority: UpdateAuthority) -> &mut Self {
577        self.instruction.new_update_authority = Some(new_update_authority);
578        self
579    }
580    /// Add an additional account to the instruction.
581    #[inline(always)]
582    pub fn add_remaining_account(
583        &mut self,
584        account: &'b solana_program::account_info::AccountInfo<'a>,
585        is_writable: bool,
586        is_signer: bool,
587    ) -> &mut Self {
588        self.instruction
589            .__remaining_accounts
590            .push((account, is_writable, is_signer));
591        self
592    }
593    /// Add additional accounts to the instruction.
594    ///
595    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
596    /// and a `bool` indicating whether the account is a signer or not.
597    #[inline(always)]
598    pub fn add_remaining_accounts(
599        &mut self,
600        accounts: &[(
601            &'b solana_program::account_info::AccountInfo<'a>,
602            bool,
603            bool,
604        )],
605    ) -> &mut Self {
606        self.instruction
607            .__remaining_accounts
608            .extend_from_slice(accounts);
609        self
610    }
611    #[inline(always)]
612    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
613        self.invoke_signed(&[])
614    }
615    #[allow(clippy::clone_on_copy)]
616    #[allow(clippy::vec_init_then_push)]
617    pub fn invoke_signed(
618        &self,
619        signers_seeds: &[&[&[u8]]],
620    ) -> solana_program::entrypoint::ProgramResult {
621        let args = UpdateV2InstructionArgs {
622            new_name: self.instruction.new_name.clone(),
623            new_uri: self.instruction.new_uri.clone(),
624            new_update_authority: self.instruction.new_update_authority.clone(),
625        };
626        let instruction = UpdateV2Cpi {
627            __program: self.instruction.__program,
628
629            asset: self.instruction.asset.expect("asset is not set"),
630
631            collection: self.instruction.collection,
632
633            payer: self.instruction.payer.expect("payer is not set"),
634
635            authority: self.instruction.authority,
636
637            new_collection: self.instruction.new_collection,
638
639            system_program: self
640                .instruction
641                .system_program
642                .expect("system_program is not set"),
643
644            log_wrapper: self.instruction.log_wrapper,
645            __args: args,
646        };
647        instruction.invoke_signed_with_remaining_accounts(
648            signers_seeds,
649            &self.instruction.__remaining_accounts,
650        )
651    }
652}
653
654struct UpdateV2CpiBuilderInstruction<'a, 'b> {
655    __program: &'b solana_program::account_info::AccountInfo<'a>,
656    asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
657    collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
658    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
659    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
660    new_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
661    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
662    log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
663    new_name: Option<String>,
664    new_uri: Option<String>,
665    new_update_authority: Option<UpdateAuthority>,
666    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
667    __remaining_accounts: Vec<(
668        &'b solana_program::account_info::AccountInfo<'a>,
669        bool,
670        bool,
671    )>,
672}