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