Skip to main content

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