Skip to main content

mpl_core/generated/instructions/
update_collection_v1.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
8#[cfg(feature = "anchor")]
9use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
10#[cfg(not(feature = "anchor"))]
11use borsh::{BorshDeserialize, BorshSerialize};
12
13/// Accounts.
14pub struct UpdateCollectionV1 {
15    /// The address of the asset
16    pub collection: solana_program::pubkey::Pubkey,
17    /// The account paying for the storage fees
18    pub payer: solana_program::pubkey::Pubkey,
19    /// The update authority or update authority delegate of the asset
20    pub authority: Option<solana_program::pubkey::Pubkey>,
21    /// The new update authority of the asset
22    pub new_update_authority: Option<solana_program::pubkey::Pubkey>,
23    /// The system program
24    pub system_program: solana_program::pubkey::Pubkey,
25    /// The SPL Noop Program
26    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 = borsh::to_vec(&(UpdateCollectionV1InstructionData::new())).unwrap();
88        let mut args = borsh::to_vec(&args).unwrap();
89        data.append(&mut args);
90
91        solana_program::instruction::Instruction {
92            program_id: crate::MPL_CORE_ID,
93            accounts,
94            data,
95        }
96    }
97}
98
99#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
100#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
101pub struct UpdateCollectionV1InstructionData {
102    discriminator: u8,
103}
104
105impl UpdateCollectionV1InstructionData {
106    pub fn new() -> Self {
107        Self { discriminator: 16 }
108    }
109}
110
111#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
112#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
113#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
114#[derive(Clone, Debug, Eq, PartialEq)]
115pub struct UpdateCollectionV1InstructionArgs {
116    pub new_name: Option<String>,
117    pub new_uri: Option<String>,
118}
119
120/// Instruction builder for `UpdateCollectionV1`.
121///
122/// ### Accounts:
123///
124///   0. `[writable]` collection
125///   1. `[writable, signer]` payer
126///   2. `[signer, optional]` authority
127///   3. `[optional]` new_update_authority
128///   4. `[optional]` system_program (default to `11111111111111111111111111111111`)
129///   5. `[optional]` log_wrapper
130#[derive(Default)]
131pub struct UpdateCollectionV1Builder {
132    collection: Option<solana_program::pubkey::Pubkey>,
133    payer: Option<solana_program::pubkey::Pubkey>,
134    authority: Option<solana_program::pubkey::Pubkey>,
135    new_update_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    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
141}
142
143impl UpdateCollectionV1Builder {
144    pub fn new() -> Self {
145        Self::default()
146    }
147    /// The address of the asset
148    #[inline(always)]
149    pub fn collection(&mut self, collection: solana_program::pubkey::Pubkey) -> &mut Self {
150        self.collection = Some(collection);
151        self
152    }
153    /// The account paying for the storage fees
154    #[inline(always)]
155    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
156        self.payer = Some(payer);
157        self
158    }
159    /// `[optional account]`
160    /// The update authority or update authority delegate of the asset
161    #[inline(always)]
162    pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
163        self.authority = authority;
164        self
165    }
166    /// `[optional account]`
167    /// The new update authority of the asset
168    #[inline(always)]
169    pub fn new_update_authority(
170        &mut self,
171        new_update_authority: Option<solana_program::pubkey::Pubkey>,
172    ) -> &mut Self {
173        self.new_update_authority = new_update_authority;
174        self
175    }
176    /// `[optional account, default to '11111111111111111111111111111111']`
177    /// The system program
178    #[inline(always)]
179    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
180        self.system_program = Some(system_program);
181        self
182    }
183    /// `[optional account]`
184    /// The SPL Noop Program
185    #[inline(always)]
186    pub fn log_wrapper(
187        &mut self,
188        log_wrapper: Option<solana_program::pubkey::Pubkey>,
189    ) -> &mut Self {
190        self.log_wrapper = log_wrapper;
191        self
192    }
193    /// `[optional argument]`
194    #[inline(always)]
195    pub fn new_name(&mut self, new_name: String) -> &mut Self {
196        self.new_name = Some(new_name);
197        self
198    }
199    /// `[optional argument]`
200    #[inline(always)]
201    pub fn new_uri(&mut self, new_uri: String) -> &mut Self {
202        self.new_uri = Some(new_uri);
203        self
204    }
205    /// Add an aditional account to the instruction.
206    #[inline(always)]
207    pub fn add_remaining_account(
208        &mut self,
209        account: solana_program::instruction::AccountMeta,
210    ) -> &mut Self {
211        self.__remaining_accounts.push(account);
212        self
213    }
214    /// Add additional accounts to the instruction.
215    #[inline(always)]
216    pub fn add_remaining_accounts(
217        &mut self,
218        accounts: &[solana_program::instruction::AccountMeta],
219    ) -> &mut Self {
220        self.__remaining_accounts.extend_from_slice(accounts);
221        self
222    }
223    #[allow(clippy::clone_on_copy)]
224    pub fn instruction(&self) -> solana_program::instruction::Instruction {
225        let accounts = UpdateCollectionV1 {
226            collection: self.collection.expect("collection is not set"),
227            payer: self.payer.expect("payer is not set"),
228            authority: self.authority,
229            new_update_authority: self.new_update_authority,
230            system_program: self
231                .system_program
232                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
233            log_wrapper: self.log_wrapper,
234        };
235        let args = UpdateCollectionV1InstructionArgs {
236            new_name: self.new_name.clone(),
237            new_uri: self.new_uri.clone(),
238        };
239
240        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
241    }
242}
243
244/// `update_collection_v1` CPI accounts.
245pub struct UpdateCollectionV1CpiAccounts<'a, 'b> {
246    /// The address of the asset
247    pub collection: &'b solana_program::account_info::AccountInfo<'a>,
248    /// The account paying for the storage fees
249    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
250    /// The update authority or update authority delegate of the asset
251    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
252    /// The new update authority of the asset
253    pub new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
254    /// The system program
255    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
256    /// The SPL Noop Program
257    pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
258}
259
260/// `update_collection_v1` CPI instruction.
261pub struct UpdateCollectionV1Cpi<'a, 'b> {
262    /// The program to invoke.
263    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
264    /// The address of the asset
265    pub collection: &'b solana_program::account_info::AccountInfo<'a>,
266    /// The account paying for the storage fees
267    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
268    /// The update authority or update authority delegate of the asset
269    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
270    /// The new update authority of the asset
271    pub new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
272    /// The system program
273    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
274    /// The SPL Noop Program
275    pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
276    /// The arguments for the instruction.
277    pub __args: UpdateCollectionV1InstructionArgs,
278}
279
280impl<'a, 'b> UpdateCollectionV1Cpi<'a, 'b> {
281    pub fn new(
282        program: &'b solana_program::account_info::AccountInfo<'a>,
283        accounts: UpdateCollectionV1CpiAccounts<'a, 'b>,
284        args: UpdateCollectionV1InstructionArgs,
285    ) -> Self {
286        Self {
287            __program: program,
288            collection: accounts.collection,
289            payer: accounts.payer,
290            authority: accounts.authority,
291            new_update_authority: accounts.new_update_authority,
292            system_program: accounts.system_program,
293            log_wrapper: accounts.log_wrapper,
294            __args: args,
295        }
296    }
297    #[inline(always)]
298    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
299        self.invoke_signed_with_remaining_accounts(&[], &[])
300    }
301    #[inline(always)]
302    pub fn invoke_with_remaining_accounts(
303        &self,
304        remaining_accounts: &[(
305            &'b solana_program::account_info::AccountInfo<'a>,
306            bool,
307            bool,
308        )],
309    ) -> solana_program::entrypoint::ProgramResult {
310        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
311    }
312    #[inline(always)]
313    pub fn invoke_signed(
314        &self,
315        signers_seeds: &[&[&[u8]]],
316    ) -> solana_program::entrypoint::ProgramResult {
317        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
318    }
319    #[allow(clippy::clone_on_copy)]
320    #[allow(clippy::vec_init_then_push)]
321    pub fn invoke_signed_with_remaining_accounts(
322        &self,
323        signers_seeds: &[&[&[u8]]],
324        remaining_accounts: &[(
325            &'b solana_program::account_info::AccountInfo<'a>,
326            bool,
327            bool,
328        )],
329    ) -> solana_program::entrypoint::ProgramResult {
330        let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
331        accounts.push(solana_program::instruction::AccountMeta::new(
332            *self.collection.key,
333            false,
334        ));
335        accounts.push(solana_program::instruction::AccountMeta::new(
336            *self.payer.key,
337            true,
338        ));
339        if let Some(authority) = self.authority {
340            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
341                *authority.key,
342                true,
343            ));
344        } else {
345            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
346                crate::MPL_CORE_ID,
347                false,
348            ));
349        }
350        if let Some(new_update_authority) = self.new_update_authority {
351            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
352                *new_update_authority.key,
353                false,
354            ));
355        } else {
356            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
357                crate::MPL_CORE_ID,
358                false,
359            ));
360        }
361        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
362            *self.system_program.key,
363            false,
364        ));
365        if let Some(log_wrapper) = self.log_wrapper {
366            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
367                *log_wrapper.key,
368                false,
369            ));
370        } else {
371            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
372                crate::MPL_CORE_ID,
373                false,
374            ));
375        }
376        remaining_accounts.iter().for_each(|remaining_account| {
377            accounts.push(solana_program::instruction::AccountMeta {
378                pubkey: *remaining_account.0.key,
379                is_writable: remaining_account.1,
380                is_signer: remaining_account.2,
381            })
382        });
383        let mut data = borsh::to_vec(&(UpdateCollectionV1InstructionData::new())).unwrap();
384        let mut args = borsh::to_vec(&self.__args).unwrap();
385        data.append(&mut args);
386
387        let instruction = solana_program::instruction::Instruction {
388            program_id: crate::MPL_CORE_ID,
389            accounts,
390            data,
391        };
392        let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len());
393        account_infos.push(self.__program.clone());
394        account_infos.push(self.collection.clone());
395        account_infos.push(self.payer.clone());
396        if let Some(authority) = self.authority {
397            account_infos.push(authority.clone());
398        }
399        if let Some(new_update_authority) = self.new_update_authority {
400            account_infos.push(new_update_authority.clone());
401        }
402        account_infos.push(self.system_program.clone());
403        if let Some(log_wrapper) = self.log_wrapper {
404            account_infos.push(log_wrapper.clone());
405        }
406        remaining_accounts
407            .iter()
408            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
409
410        if signers_seeds.is_empty() {
411            solana_program::program::invoke(&instruction, &account_infos)
412        } else {
413            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
414        }
415    }
416}
417
418/// Instruction builder for `UpdateCollectionV1` via CPI.
419///
420/// ### Accounts:
421///
422///   0. `[writable]` collection
423///   1. `[writable, signer]` payer
424///   2. `[signer, optional]` authority
425///   3. `[optional]` new_update_authority
426///   4. `[]` system_program
427///   5. `[optional]` log_wrapper
428pub struct UpdateCollectionV1CpiBuilder<'a, 'b> {
429    instruction: Box<UpdateCollectionV1CpiBuilderInstruction<'a, 'b>>,
430}
431
432impl<'a, 'b> UpdateCollectionV1CpiBuilder<'a, 'b> {
433    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
434        let instruction = Box::new(UpdateCollectionV1CpiBuilderInstruction {
435            __program: program,
436            collection: None,
437            payer: None,
438            authority: None,
439            new_update_authority: None,
440            system_program: None,
441            log_wrapper: None,
442            new_name: None,
443            new_uri: None,
444            __remaining_accounts: Vec::new(),
445        });
446        Self { instruction }
447    }
448    /// The address of the asset
449    #[inline(always)]
450    pub fn collection(
451        &mut self,
452        collection: &'b solana_program::account_info::AccountInfo<'a>,
453    ) -> &mut Self {
454        self.instruction.collection = Some(collection);
455        self
456    }
457    /// The account paying for the storage fees
458    #[inline(always)]
459    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
460        self.instruction.payer = Some(payer);
461        self
462    }
463    /// `[optional account]`
464    /// The update authority or update authority delegate of the asset
465    #[inline(always)]
466    pub fn authority(
467        &mut self,
468        authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
469    ) -> &mut Self {
470        self.instruction.authority = authority;
471        self
472    }
473    /// `[optional account]`
474    /// The new update authority of the asset
475    #[inline(always)]
476    pub fn new_update_authority(
477        &mut self,
478        new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
479    ) -> &mut Self {
480        self.instruction.new_update_authority = new_update_authority;
481        self
482    }
483    /// The system program
484    #[inline(always)]
485    pub fn system_program(
486        &mut self,
487        system_program: &'b solana_program::account_info::AccountInfo<'a>,
488    ) -> &mut Self {
489        self.instruction.system_program = Some(system_program);
490        self
491    }
492    /// `[optional account]`
493    /// The SPL Noop Program
494    #[inline(always)]
495    pub fn log_wrapper(
496        &mut self,
497        log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
498    ) -> &mut Self {
499        self.instruction.log_wrapper = log_wrapper;
500        self
501    }
502    /// `[optional argument]`
503    #[inline(always)]
504    pub fn new_name(&mut self, new_name: String) -> &mut Self {
505        self.instruction.new_name = Some(new_name);
506        self
507    }
508    /// `[optional argument]`
509    #[inline(always)]
510    pub fn new_uri(&mut self, new_uri: String) -> &mut Self {
511        self.instruction.new_uri = Some(new_uri);
512        self
513    }
514    /// Add an additional account to the instruction.
515    #[inline(always)]
516    pub fn add_remaining_account(
517        &mut self,
518        account: &'b solana_program::account_info::AccountInfo<'a>,
519        is_writable: bool,
520        is_signer: bool,
521    ) -> &mut Self {
522        self.instruction
523            .__remaining_accounts
524            .push((account, is_writable, is_signer));
525        self
526    }
527    /// Add additional accounts to the instruction.
528    ///
529    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
530    /// and a `bool` indicating whether the account is a signer or not.
531    #[inline(always)]
532    pub fn add_remaining_accounts(
533        &mut self,
534        accounts: &[(
535            &'b solana_program::account_info::AccountInfo<'a>,
536            bool,
537            bool,
538        )],
539    ) -> &mut Self {
540        self.instruction
541            .__remaining_accounts
542            .extend_from_slice(accounts);
543        self
544    }
545    #[inline(always)]
546    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
547        self.invoke_signed(&[])
548    }
549    #[allow(clippy::clone_on_copy)]
550    #[allow(clippy::vec_init_then_push)]
551    pub fn invoke_signed(
552        &self,
553        signers_seeds: &[&[&[u8]]],
554    ) -> solana_program::entrypoint::ProgramResult {
555        let args = UpdateCollectionV1InstructionArgs {
556            new_name: self.instruction.new_name.clone(),
557            new_uri: self.instruction.new_uri.clone(),
558        };
559        let instruction = UpdateCollectionV1Cpi {
560            __program: self.instruction.__program,
561
562            collection: self.instruction.collection.expect("collection is not set"),
563
564            payer: self.instruction.payer.expect("payer is not set"),
565
566            authority: self.instruction.authority,
567
568            new_update_authority: self.instruction.new_update_authority,
569
570            system_program: self
571                .instruction
572                .system_program
573                .expect("system_program is not set"),
574
575            log_wrapper: self.instruction.log_wrapper,
576            __args: args,
577        };
578        instruction.invoke_signed_with_remaining_accounts(
579            signers_seeds,
580            &self.instruction.__remaining_accounts,
581        )
582    }
583}
584
585struct UpdateCollectionV1CpiBuilderInstruction<'a, 'b> {
586    __program: &'b solana_program::account_info::AccountInfo<'a>,
587    collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
588    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
589    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
590    new_update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
591    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
592    log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
593    new_name: Option<String>,
594    new_uri: Option<String>,
595    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
596    __remaining_accounts: Vec<(
597        &'b solana_program::account_info::AccountInfo<'a>,
598        bool,
599        bool,
600    )>,
601}