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