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