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