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