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