core_preview/generated/instructions/
decompress_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::CompressionProof;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12/// Accounts.
13pub struct DecompressV1 {
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 DecompressV1 {
29    pub fn instruction(
30        &self,
31        args: DecompressV1InstructionArgs,
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: DecompressV1InstructionArgs,
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_readonly(
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 = DecompressV1InstructionData::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 DecompressV1InstructionData {
98    discriminator: u8,
99}
100
101impl DecompressV1InstructionData {
102    fn new() -> Self {
103        Self { discriminator: 18 }
104    }
105}
106
107#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
108#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
109pub struct DecompressV1InstructionArgs {
110    pub compression_proof: CompressionProof,
111}
112
113/// Instruction builder for `DecompressV1`.
114///
115/// ### Accounts:
116///
117///   0. `[writable]` asset
118///   1. `[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 DecompressV1Builder {
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    compression_proof: Option<CompressionProof>,
132    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
133}
134
135impl DecompressV1Builder {
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 compression_proof(&mut self, compression_proof: CompressionProof) -> &mut Self {
184        self.compression_proof = Some(compression_proof);
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 = DecompressV1 {
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 = DecompressV1InstructionArgs {
218            compression_proof: self
219                .compression_proof
220                .clone()
221                .expect("compression_proof is not set"),
222        };
223
224        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
225    }
226}
227
228/// `decompress_v1` CPI accounts.
229pub struct DecompressV1CpiAccounts<'a, 'b> {
230    /// The address of the asset
231    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
232    /// The collection to which the asset belongs
233    pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
234    /// The account paying for the storage fees
235    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
236    /// The owner or delegate of the asset
237    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
238    /// The system program
239    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
240    /// The SPL Noop Program
241    pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
242}
243
244/// `decompress_v1` CPI instruction.
245pub struct DecompressV1Cpi<'a, 'b> {
246    /// The program to invoke.
247    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
248    /// The address of the asset
249    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
250    /// The collection to which the asset belongs
251    pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
252    /// The account paying for the storage fees
253    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
254    /// The owner or delegate of the asset
255    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
256    /// The system program
257    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
258    /// The SPL Noop Program
259    pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
260    /// The arguments for the instruction.
261    pub __args: DecompressV1InstructionArgs,
262}
263
264impl<'a, 'b> DecompressV1Cpi<'a, 'b> {
265    pub fn new(
266        program: &'b solana_program::account_info::AccountInfo<'a>,
267        accounts: DecompressV1CpiAccounts<'a, 'b>,
268        args: DecompressV1InstructionArgs,
269    ) -> Self {
270        Self {
271            __program: program,
272            asset: accounts.asset,
273            collection: accounts.collection,
274            payer: accounts.payer,
275            authority: accounts.authority,
276            system_program: accounts.system_program,
277            log_wrapper: accounts.log_wrapper,
278            __args: args,
279        }
280    }
281    #[inline(always)]
282    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
283        self.invoke_signed_with_remaining_accounts(&[], &[])
284    }
285    #[inline(always)]
286    pub fn invoke_with_remaining_accounts(
287        &self,
288        remaining_accounts: &[(
289            &'b solana_program::account_info::AccountInfo<'a>,
290            bool,
291            bool,
292        )],
293    ) -> solana_program::entrypoint::ProgramResult {
294        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
295    }
296    #[inline(always)]
297    pub fn invoke_signed(
298        &self,
299        signers_seeds: &[&[&[u8]]],
300    ) -> solana_program::entrypoint::ProgramResult {
301        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
302    }
303    #[allow(clippy::clone_on_copy)]
304    #[allow(clippy::vec_init_then_push)]
305    pub fn invoke_signed_with_remaining_accounts(
306        &self,
307        signers_seeds: &[&[&[u8]]],
308        remaining_accounts: &[(
309            &'b solana_program::account_info::AccountInfo<'a>,
310            bool,
311            bool,
312        )],
313    ) -> solana_program::entrypoint::ProgramResult {
314        let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
315        accounts.push(solana_program::instruction::AccountMeta::new(
316            *self.asset.key,
317            false,
318        ));
319        if let Some(collection) = self.collection {
320            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
321                *collection.key,
322                false,
323            ));
324        } else {
325            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
326                crate::MPL_CORE_ID,
327                false,
328            ));
329        }
330        accounts.push(solana_program::instruction::AccountMeta::new(
331            *self.payer.key,
332            true,
333        ));
334        if let Some(authority) = self.authority {
335            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
336                *authority.key,
337                true,
338            ));
339        } else {
340            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
341                crate::MPL_CORE_ID,
342                false,
343            ));
344        }
345        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
346            *self.system_program.key,
347            false,
348        ));
349        if let Some(log_wrapper) = self.log_wrapper {
350            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
351                *log_wrapper.key,
352                false,
353            ));
354        } else {
355            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
356                crate::MPL_CORE_ID,
357                false,
358            ));
359        }
360        remaining_accounts.iter().for_each(|remaining_account| {
361            accounts.push(solana_program::instruction::AccountMeta {
362                pubkey: *remaining_account.0.key,
363                is_signer: remaining_account.1,
364                is_writable: remaining_account.2,
365            })
366        });
367        let mut data = DecompressV1InstructionData::new().try_to_vec().unwrap();
368        let mut args = self.__args.try_to_vec().unwrap();
369        data.append(&mut args);
370
371        let instruction = solana_program::instruction::Instruction {
372            program_id: crate::MPL_CORE_ID,
373            accounts,
374            data,
375        };
376        let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len());
377        account_infos.push(self.__program.clone());
378        account_infos.push(self.asset.clone());
379        if let Some(collection) = self.collection {
380            account_infos.push(collection.clone());
381        }
382        account_infos.push(self.payer.clone());
383        if let Some(authority) = self.authority {
384            account_infos.push(authority.clone());
385        }
386        account_infos.push(self.system_program.clone());
387        if let Some(log_wrapper) = self.log_wrapper {
388            account_infos.push(log_wrapper.clone());
389        }
390        remaining_accounts
391            .iter()
392            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
393
394        if signers_seeds.is_empty() {
395            solana_program::program::invoke(&instruction, &account_infos)
396        } else {
397            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
398        }
399    }
400}
401
402/// Instruction builder for `DecompressV1` via CPI.
403///
404/// ### Accounts:
405///
406///   0. `[writable]` asset
407///   1. `[optional]` collection
408///   2. `[writable, signer]` payer
409///   3. `[signer, optional]` authority
410///   4. `[]` system_program
411///   5. `[optional]` log_wrapper
412pub struct DecompressV1CpiBuilder<'a, 'b> {
413    instruction: Box<DecompressV1CpiBuilderInstruction<'a, 'b>>,
414}
415
416impl<'a, 'b> DecompressV1CpiBuilder<'a, 'b> {
417    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
418        let instruction = Box::new(DecompressV1CpiBuilderInstruction {
419            __program: program,
420            asset: None,
421            collection: None,
422            payer: None,
423            authority: None,
424            system_program: None,
425            log_wrapper: None,
426            compression_proof: None,
427            __remaining_accounts: Vec::new(),
428        });
429        Self { instruction }
430    }
431    /// The address of the asset
432    #[inline(always)]
433    pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
434        self.instruction.asset = Some(asset);
435        self
436    }
437    /// `[optional account]`
438    /// The collection to which the asset belongs
439    #[inline(always)]
440    pub fn collection(
441        &mut self,
442        collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
443    ) -> &mut Self {
444        self.instruction.collection = collection;
445        self
446    }
447    /// The account paying for the storage fees
448    #[inline(always)]
449    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
450        self.instruction.payer = Some(payer);
451        self
452    }
453    /// `[optional account]`
454    /// The owner or delegate of the asset
455    #[inline(always)]
456    pub fn authority(
457        &mut self,
458        authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
459    ) -> &mut Self {
460        self.instruction.authority = authority;
461        self
462    }
463    /// The system program
464    #[inline(always)]
465    pub fn system_program(
466        &mut self,
467        system_program: &'b solana_program::account_info::AccountInfo<'a>,
468    ) -> &mut Self {
469        self.instruction.system_program = Some(system_program);
470        self
471    }
472    /// `[optional account]`
473    /// The SPL Noop Program
474    #[inline(always)]
475    pub fn log_wrapper(
476        &mut self,
477        log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
478    ) -> &mut Self {
479        self.instruction.log_wrapper = log_wrapper;
480        self
481    }
482    #[inline(always)]
483    pub fn compression_proof(&mut self, compression_proof: CompressionProof) -> &mut Self {
484        self.instruction.compression_proof = Some(compression_proof);
485        self
486    }
487    /// Add an additional account to the instruction.
488    #[inline(always)]
489    pub fn add_remaining_account(
490        &mut self,
491        account: &'b solana_program::account_info::AccountInfo<'a>,
492        is_writable: bool,
493        is_signer: bool,
494    ) -> &mut Self {
495        self.instruction
496            .__remaining_accounts
497            .push((account, is_writable, is_signer));
498        self
499    }
500    /// Add additional accounts to the instruction.
501    ///
502    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
503    /// and a `bool` indicating whether the account is a signer or not.
504    #[inline(always)]
505    pub fn add_remaining_accounts(
506        &mut self,
507        accounts: &[(
508            &'b solana_program::account_info::AccountInfo<'a>,
509            bool,
510            bool,
511        )],
512    ) -> &mut Self {
513        self.instruction
514            .__remaining_accounts
515            .extend_from_slice(accounts);
516        self
517    }
518    #[inline(always)]
519    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
520        self.invoke_signed(&[])
521    }
522    #[allow(clippy::clone_on_copy)]
523    #[allow(clippy::vec_init_then_push)]
524    pub fn invoke_signed(
525        &self,
526        signers_seeds: &[&[&[u8]]],
527    ) -> solana_program::entrypoint::ProgramResult {
528        let args = DecompressV1InstructionArgs {
529            compression_proof: self
530                .instruction
531                .compression_proof
532                .clone()
533                .expect("compression_proof is not set"),
534        };
535        let instruction = DecompressV1Cpi {
536            __program: self.instruction.__program,
537
538            asset: self.instruction.asset.expect("asset is not set"),
539
540            collection: self.instruction.collection,
541
542            payer: self.instruction.payer.expect("payer is not set"),
543
544            authority: self.instruction.authority,
545
546            system_program: self
547                .instruction
548                .system_program
549                .expect("system_program is not set"),
550
551            log_wrapper: self.instruction.log_wrapper,
552            __args: args,
553        };
554        instruction.invoke_signed_with_remaining_accounts(
555            signers_seeds,
556            &self.instruction.__remaining_accounts,
557        )
558    }
559}
560
561struct DecompressV1CpiBuilderInstruction<'a, 'b> {
562    __program: &'b solana_program::account_info::AccountInfo<'a>,
563    asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
564    collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
565    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
566    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
567    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
568    log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
569    compression_proof: Option<CompressionProof>,
570    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
571    __remaining_accounts: Vec<(
572        &'b solana_program::account_info::AccountInfo<'a>,
573        bool,
574        bool,
575    )>,
576}