1use crate::generated::types::CompressionProof;
9#[cfg(feature = "anchor")]
10use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
11#[cfg(not(feature = "anchor"))]
12use borsh::{BorshDeserialize, BorshSerialize};
13
14pub struct DecompressV1 {
16 pub asset: solana_program::pubkey::Pubkey,
18 pub collection: Option<solana_program::pubkey::Pubkey>,
20 pub payer: solana_program::pubkey::Pubkey,
22 pub authority: Option<solana_program::pubkey::Pubkey>,
24 pub system_program: solana_program::pubkey::Pubkey,
26 pub log_wrapper: Option<solana_program::pubkey::Pubkey>,
28}
29
30impl DecompressV1 {
31 pub fn instruction(
32 &self,
33 args: DecompressV1InstructionArgs,
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: DecompressV1InstructionArgs,
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_readonly(
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 = DecompressV1InstructionData::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 DecompressV1InstructionData {
101 discriminator: u8,
102}
103
104impl DecompressV1InstructionData {
105 pub fn new() -> Self {
106 Self { discriminator: 18 }
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 DecompressV1InstructionArgs {
115 pub compression_proof: CompressionProof,
116}
117
118#[derive(Default)]
129pub struct DecompressV1Builder {
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 compression_proof: Option<CompressionProof>,
137 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
138}
139
140impl DecompressV1Builder {
141 pub fn new() -> Self {
142 Self::default()
143 }
144 #[inline(always)]
146 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
147 self.asset = Some(asset);
148 self
149 }
150 #[inline(always)]
153 pub fn collection(&mut self, collection: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
154 self.collection = collection;
155 self
156 }
157 #[inline(always)]
159 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
160 self.payer = Some(payer);
161 self
162 }
163 #[inline(always)]
166 pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
167 self.authority = authority;
168 self
169 }
170 #[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 #[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 compression_proof(&mut self, compression_proof: CompressionProof) -> &mut Self {
189 self.compression_proof = Some(compression_proof);
190 self
191 }
192 #[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 #[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 = DecompressV1 {
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 = DecompressV1InstructionArgs {
223 compression_proof: self
224 .compression_proof
225 .clone()
226 .expect("compression_proof is not set"),
227 };
228
229 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
230 }
231}
232
233pub struct DecompressV1CpiAccounts<'a, 'b> {
235 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
237 pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
239 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
241 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
243 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
245 pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
247}
248
249pub struct DecompressV1Cpi<'a, 'b> {
251 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
253 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
255 pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
257 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
259 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
261 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
263 pub log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
265 pub __args: DecompressV1InstructionArgs,
267}
268
269impl<'a, 'b> DecompressV1Cpi<'a, 'b> {
270 pub fn new(
271 program: &'b solana_program::account_info::AccountInfo<'a>,
272 accounts: DecompressV1CpiAccounts<'a, 'b>,
273 args: DecompressV1InstructionArgs,
274 ) -> Self {
275 Self {
276 __program: program,
277 asset: accounts.asset,
278 collection: accounts.collection,
279 payer: accounts.payer,
280 authority: accounts.authority,
281 system_program: accounts.system_program,
282 log_wrapper: accounts.log_wrapper,
283 __args: args,
284 }
285 }
286 #[inline(always)]
287 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
288 self.invoke_signed_with_remaining_accounts(&[], &[])
289 }
290 #[inline(always)]
291 pub fn invoke_with_remaining_accounts(
292 &self,
293 remaining_accounts: &[(
294 &'b solana_program::account_info::AccountInfo<'a>,
295 bool,
296 bool,
297 )],
298 ) -> solana_program::entrypoint::ProgramResult {
299 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
300 }
301 #[inline(always)]
302 pub fn invoke_signed(
303 &self,
304 signers_seeds: &[&[&[u8]]],
305 ) -> solana_program::entrypoint::ProgramResult {
306 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
307 }
308 #[allow(clippy::clone_on_copy)]
309 #[allow(clippy::vec_init_then_push)]
310 pub fn invoke_signed_with_remaining_accounts(
311 &self,
312 signers_seeds: &[&[&[u8]]],
313 remaining_accounts: &[(
314 &'b solana_program::account_info::AccountInfo<'a>,
315 bool,
316 bool,
317 )],
318 ) -> solana_program::entrypoint::ProgramResult {
319 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
320 accounts.push(solana_program::instruction::AccountMeta::new(
321 *self.asset.key,
322 false,
323 ));
324 if let Some(collection) = self.collection {
325 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
326 *collection.key,
327 false,
328 ));
329 } else {
330 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
331 crate::MPL_CORE_ID,
332 false,
333 ));
334 }
335 accounts.push(solana_program::instruction::AccountMeta::new(
336 *self.payer.key,
337 true,
338 ));
339 if let Some(authority) = self.authority {
340 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
341 *authority.key,
342 true,
343 ));
344 } else {
345 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
346 crate::MPL_CORE_ID,
347 false,
348 ));
349 }
350 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
351 *self.system_program.key,
352 false,
353 ));
354 if let Some(log_wrapper) = self.log_wrapper {
355 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
356 *log_wrapper.key,
357 false,
358 ));
359 } else {
360 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
361 crate::MPL_CORE_ID,
362 false,
363 ));
364 }
365 remaining_accounts.iter().for_each(|remaining_account| {
366 accounts.push(solana_program::instruction::AccountMeta {
367 pubkey: *remaining_account.0.key,
368 is_signer: remaining_account.1,
369 is_writable: remaining_account.2,
370 })
371 });
372 let mut data = DecompressV1InstructionData::new().try_to_vec().unwrap();
373 let mut args = self.__args.try_to_vec().unwrap();
374 data.append(&mut args);
375
376 let instruction = solana_program::instruction::Instruction {
377 program_id: crate::MPL_CORE_ID,
378 accounts,
379 data,
380 };
381 let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len());
382 account_infos.push(self.__program.clone());
383 account_infos.push(self.asset.clone());
384 if let Some(collection) = self.collection {
385 account_infos.push(collection.clone());
386 }
387 account_infos.push(self.payer.clone());
388 if let Some(authority) = self.authority {
389 account_infos.push(authority.clone());
390 }
391 account_infos.push(self.system_program.clone());
392 if let Some(log_wrapper) = self.log_wrapper {
393 account_infos.push(log_wrapper.clone());
394 }
395 remaining_accounts
396 .iter()
397 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
398
399 if signers_seeds.is_empty() {
400 solana_program::program::invoke(&instruction, &account_infos)
401 } else {
402 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
403 }
404 }
405}
406
407pub struct DecompressV1CpiBuilder<'a, 'b> {
418 instruction: Box<DecompressV1CpiBuilderInstruction<'a, 'b>>,
419}
420
421impl<'a, 'b> DecompressV1CpiBuilder<'a, 'b> {
422 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
423 let instruction = Box::new(DecompressV1CpiBuilderInstruction {
424 __program: program,
425 asset: None,
426 collection: None,
427 payer: None,
428 authority: None,
429 system_program: None,
430 log_wrapper: None,
431 compression_proof: None,
432 __remaining_accounts: Vec::new(),
433 });
434 Self { instruction }
435 }
436 #[inline(always)]
438 pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
439 self.instruction.asset = Some(asset);
440 self
441 }
442 #[inline(always)]
445 pub fn collection(
446 &mut self,
447 collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
448 ) -> &mut Self {
449 self.instruction.collection = collection;
450 self
451 }
452 #[inline(always)]
454 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
455 self.instruction.payer = Some(payer);
456 self
457 }
458 #[inline(always)]
461 pub fn authority(
462 &mut self,
463 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
464 ) -> &mut Self {
465 self.instruction.authority = authority;
466 self
467 }
468 #[inline(always)]
470 pub fn system_program(
471 &mut self,
472 system_program: &'b solana_program::account_info::AccountInfo<'a>,
473 ) -> &mut Self {
474 self.instruction.system_program = Some(system_program);
475 self
476 }
477 #[inline(always)]
480 pub fn log_wrapper(
481 &mut self,
482 log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
483 ) -> &mut Self {
484 self.instruction.log_wrapper = log_wrapper;
485 self
486 }
487 #[inline(always)]
488 pub fn compression_proof(&mut self, compression_proof: CompressionProof) -> &mut Self {
489 self.instruction.compression_proof = Some(compression_proof);
490 self
491 }
492 #[inline(always)]
494 pub fn add_remaining_account(
495 &mut self,
496 account: &'b solana_program::account_info::AccountInfo<'a>,
497 is_writable: bool,
498 is_signer: bool,
499 ) -> &mut Self {
500 self.instruction
501 .__remaining_accounts
502 .push((account, is_writable, is_signer));
503 self
504 }
505 #[inline(always)]
510 pub fn add_remaining_accounts(
511 &mut self,
512 accounts: &[(
513 &'b solana_program::account_info::AccountInfo<'a>,
514 bool,
515 bool,
516 )],
517 ) -> &mut Self {
518 self.instruction
519 .__remaining_accounts
520 .extend_from_slice(accounts);
521 self
522 }
523 #[inline(always)]
524 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
525 self.invoke_signed(&[])
526 }
527 #[allow(clippy::clone_on_copy)]
528 #[allow(clippy::vec_init_then_push)]
529 pub fn invoke_signed(
530 &self,
531 signers_seeds: &[&[&[u8]]],
532 ) -> solana_program::entrypoint::ProgramResult {
533 let args = DecompressV1InstructionArgs {
534 compression_proof: self
535 .instruction
536 .compression_proof
537 .clone()
538 .expect("compression_proof is not set"),
539 };
540 let instruction = DecompressV1Cpi {
541 __program: self.instruction.__program,
542
543 asset: self.instruction.asset.expect("asset is not set"),
544
545 collection: self.instruction.collection,
546
547 payer: self.instruction.payer.expect("payer is not set"),
548
549 authority: self.instruction.authority,
550
551 system_program: self
552 .instruction
553 .system_program
554 .expect("system_program is not set"),
555
556 log_wrapper: self.instruction.log_wrapper,
557 __args: args,
558 };
559 instruction.invoke_signed_with_remaining_accounts(
560 signers_seeds,
561 &self.instruction.__remaining_accounts,
562 )
563 }
564}
565
566struct DecompressV1CpiBuilderInstruction<'a, 'b> {
567 __program: &'b solana_program::account_info::AccountInfo<'a>,
568 asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
569 collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
570 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
571 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
572 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
573 log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
574 compression_proof: Option<CompressionProof>,
575 __remaining_accounts: Vec<(
577 &'b solana_program::account_info::AccountInfo<'a>,
578 bool,
579 bool,
580 )>,
581}