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