Skip to main content

mpl_token_metadata/generated/instructions/
set_token_standard.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 SetTokenStandard {
13    /// Metadata account
14    pub metadata: solana_program::pubkey::Pubkey,
15    /// Metadata update authority
16    pub update_authority: solana_program::pubkey::Pubkey,
17    /// Mint account
18    pub mint: solana_program::pubkey::Pubkey,
19    /// Edition account
20    pub edition: Option<solana_program::pubkey::Pubkey>,
21}
22
23impl SetTokenStandard {
24    pub fn instruction(&self) -> solana_program::instruction::Instruction {
25        self.instruction_with_remaining_accounts(&[])
26    }
27    #[allow(clippy::vec_init_then_push)]
28    pub fn instruction_with_remaining_accounts(
29        &self,
30        remaining_accounts: &[solana_program::instruction::AccountMeta],
31    ) -> solana_program::instruction::Instruction {
32        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
33        accounts.push(solana_program::instruction::AccountMeta::new(
34            self.metadata,
35            false,
36        ));
37        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38            self.update_authority,
39            true,
40        ));
41        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42            self.mint, false,
43        ));
44        if let Some(edition) = self.edition {
45            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
46                edition, false,
47            ));
48        }
49        accounts.extend_from_slice(remaining_accounts);
50        let data = SetTokenStandardInstructionData::new().try_to_vec().unwrap();
51
52        solana_program::instruction::Instruction {
53            program_id: crate::MPL_TOKEN_METADATA_ID,
54            accounts,
55            data,
56        }
57    }
58}
59
60#[derive(BorshDeserialize, BorshSerialize)]
61struct SetTokenStandardInstructionData {
62    discriminator: u8,
63}
64
65impl SetTokenStandardInstructionData {
66    fn new() -> Self {
67        Self { discriminator: 35 }
68    }
69}
70
71/// Instruction builder for `SetTokenStandard`.
72///
73/// ### Accounts:
74///
75///   0. `[writable]` metadata
76///   1. `[signer]` update_authority
77///   2. `[]` mint
78///   3. `[optional]` edition
79#[derive(Default)]
80pub struct SetTokenStandardBuilder {
81    metadata: Option<solana_program::pubkey::Pubkey>,
82    update_authority: Option<solana_program::pubkey::Pubkey>,
83    mint: Option<solana_program::pubkey::Pubkey>,
84    edition: Option<solana_program::pubkey::Pubkey>,
85    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
86}
87
88impl SetTokenStandardBuilder {
89    pub fn new() -> Self {
90        Self::default()
91    }
92    /// Metadata account
93    #[inline(always)]
94    pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
95        self.metadata = Some(metadata);
96        self
97    }
98    /// Metadata update authority
99    #[inline(always)]
100    pub fn update_authority(
101        &mut self,
102        update_authority: solana_program::pubkey::Pubkey,
103    ) -> &mut Self {
104        self.update_authority = Some(update_authority);
105        self
106    }
107    /// Mint account
108    #[inline(always)]
109    pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
110        self.mint = Some(mint);
111        self
112    }
113    /// `[optional account]`
114    /// Edition account
115    #[inline(always)]
116    pub fn edition(&mut self, edition: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
117        self.edition = edition;
118        self
119    }
120    /// Add an aditional account to the instruction.
121    #[inline(always)]
122    pub fn add_remaining_account(
123        &mut self,
124        account: solana_program::instruction::AccountMeta,
125    ) -> &mut Self {
126        self.__remaining_accounts.push(account);
127        self
128    }
129    /// Add additional accounts to the instruction.
130    #[inline(always)]
131    pub fn add_remaining_accounts(
132        &mut self,
133        accounts: &[solana_program::instruction::AccountMeta],
134    ) -> &mut Self {
135        self.__remaining_accounts.extend_from_slice(accounts);
136        self
137    }
138    #[allow(clippy::clone_on_copy)]
139    pub fn instruction(&self) -> solana_program::instruction::Instruction {
140        let accounts = SetTokenStandard {
141            metadata: self.metadata.expect("metadata is not set"),
142            update_authority: self.update_authority.expect("update_authority is not set"),
143            mint: self.mint.expect("mint is not set"),
144            edition: self.edition,
145        };
146
147        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
148    }
149}
150
151/// `set_token_standard` CPI accounts.
152pub struct SetTokenStandardCpiAccounts<'a, 'b> {
153    /// Metadata account
154    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
155    /// Metadata update authority
156    pub update_authority: &'b solana_program::account_info::AccountInfo<'a>,
157    /// Mint account
158    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
159    /// Edition account
160    pub edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
161}
162
163/// `set_token_standard` CPI instruction.
164pub struct SetTokenStandardCpi<'a, 'b> {
165    /// The program to invoke.
166    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
167    /// Metadata account
168    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
169    /// Metadata update authority
170    pub update_authority: &'b solana_program::account_info::AccountInfo<'a>,
171    /// Mint account
172    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
173    /// Edition account
174    pub edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
175}
176
177impl<'a, 'b> SetTokenStandardCpi<'a, 'b> {
178    pub fn new(
179        program: &'b solana_program::account_info::AccountInfo<'a>,
180        accounts: SetTokenStandardCpiAccounts<'a, 'b>,
181    ) -> Self {
182        Self {
183            __program: program,
184            metadata: accounts.metadata,
185            update_authority: accounts.update_authority,
186            mint: accounts.mint,
187            edition: accounts.edition,
188        }
189    }
190    #[inline(always)]
191    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
192        self.invoke_signed_with_remaining_accounts(&[], &[])
193    }
194    #[inline(always)]
195    pub fn invoke_with_remaining_accounts(
196        &self,
197        remaining_accounts: &[(
198            &'b solana_program::account_info::AccountInfo<'a>,
199            bool,
200            bool,
201        )],
202    ) -> solana_program::entrypoint::ProgramResult {
203        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
204    }
205    #[inline(always)]
206    pub fn invoke_signed(
207        &self,
208        signers_seeds: &[&[&[u8]]],
209    ) -> solana_program::entrypoint::ProgramResult {
210        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
211    }
212    #[allow(clippy::clone_on_copy)]
213    #[allow(clippy::vec_init_then_push)]
214    pub fn invoke_signed_with_remaining_accounts(
215        &self,
216        signers_seeds: &[&[&[u8]]],
217        remaining_accounts: &[(
218            &'b solana_program::account_info::AccountInfo<'a>,
219            bool,
220            bool,
221        )],
222    ) -> solana_program::entrypoint::ProgramResult {
223        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
224        accounts.push(solana_program::instruction::AccountMeta::new(
225            *self.metadata.key,
226            false,
227        ));
228        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
229            *self.update_authority.key,
230            true,
231        ));
232        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
233            *self.mint.key,
234            false,
235        ));
236        if let Some(edition) = self.edition {
237            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
238                *edition.key,
239                false,
240            ));
241        }
242        remaining_accounts.iter().for_each(|remaining_account| {
243            accounts.push(solana_program::instruction::AccountMeta {
244                pubkey: *remaining_account.0.key,
245                is_signer: remaining_account.1,
246                is_writable: remaining_account.2,
247            })
248        });
249        let data = SetTokenStandardInstructionData::new().try_to_vec().unwrap();
250
251        let instruction = solana_program::instruction::Instruction {
252            program_id: crate::MPL_TOKEN_METADATA_ID,
253            accounts,
254            data,
255        };
256        let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
257        account_infos.push(self.__program.clone());
258        account_infos.push(self.metadata.clone());
259        account_infos.push(self.update_authority.clone());
260        account_infos.push(self.mint.clone());
261        if let Some(edition) = self.edition {
262            account_infos.push(edition.clone());
263        }
264        remaining_accounts
265            .iter()
266            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
267
268        if signers_seeds.is_empty() {
269            solana_program::program::invoke(&instruction, &account_infos)
270        } else {
271            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
272        }
273    }
274}
275
276/// Instruction builder for `SetTokenStandard` via CPI.
277///
278/// ### Accounts:
279///
280///   0. `[writable]` metadata
281///   1. `[signer]` update_authority
282///   2. `[]` mint
283///   3. `[optional]` edition
284pub struct SetTokenStandardCpiBuilder<'a, 'b> {
285    instruction: Box<SetTokenStandardCpiBuilderInstruction<'a, 'b>>,
286}
287
288impl<'a, 'b> SetTokenStandardCpiBuilder<'a, 'b> {
289    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
290        let instruction = Box::new(SetTokenStandardCpiBuilderInstruction {
291            __program: program,
292            metadata: None,
293            update_authority: None,
294            mint: None,
295            edition: None,
296            __remaining_accounts: Vec::new(),
297        });
298        Self { instruction }
299    }
300    /// Metadata account
301    #[inline(always)]
302    pub fn metadata(
303        &mut self,
304        metadata: &'b solana_program::account_info::AccountInfo<'a>,
305    ) -> &mut Self {
306        self.instruction.metadata = Some(metadata);
307        self
308    }
309    /// Metadata update authority
310    #[inline(always)]
311    pub fn update_authority(
312        &mut self,
313        update_authority: &'b solana_program::account_info::AccountInfo<'a>,
314    ) -> &mut Self {
315        self.instruction.update_authority = Some(update_authority);
316        self
317    }
318    /// Mint account
319    #[inline(always)]
320    pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
321        self.instruction.mint = Some(mint);
322        self
323    }
324    /// `[optional account]`
325    /// Edition account
326    #[inline(always)]
327    pub fn edition(
328        &mut self,
329        edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
330    ) -> &mut Self {
331        self.instruction.edition = edition;
332        self
333    }
334    /// Add an additional account to the instruction.
335    #[inline(always)]
336    pub fn add_remaining_account(
337        &mut self,
338        account: &'b solana_program::account_info::AccountInfo<'a>,
339        is_writable: bool,
340        is_signer: bool,
341    ) -> &mut Self {
342        self.instruction
343            .__remaining_accounts
344            .push((account, is_writable, is_signer));
345        self
346    }
347    /// Add additional accounts to the instruction.
348    ///
349    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
350    /// and a `bool` indicating whether the account is a signer or not.
351    #[inline(always)]
352    pub fn add_remaining_accounts(
353        &mut self,
354        accounts: &[(
355            &'b solana_program::account_info::AccountInfo<'a>,
356            bool,
357            bool,
358        )],
359    ) -> &mut Self {
360        self.instruction
361            .__remaining_accounts
362            .extend_from_slice(accounts);
363        self
364    }
365    #[inline(always)]
366    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
367        self.invoke_signed(&[])
368    }
369    #[allow(clippy::clone_on_copy)]
370    #[allow(clippy::vec_init_then_push)]
371    pub fn invoke_signed(
372        &self,
373        signers_seeds: &[&[&[u8]]],
374    ) -> solana_program::entrypoint::ProgramResult {
375        let instruction = SetTokenStandardCpi {
376            __program: self.instruction.__program,
377
378            metadata: self.instruction.metadata.expect("metadata is not set"),
379
380            update_authority: self
381                .instruction
382                .update_authority
383                .expect("update_authority is not set"),
384
385            mint: self.instruction.mint.expect("mint is not set"),
386
387            edition: self.instruction.edition,
388        };
389        instruction.invoke_signed_with_remaining_accounts(
390            signers_seeds,
391            &self.instruction.__remaining_accounts,
392        )
393    }
394}
395
396struct SetTokenStandardCpiBuilderInstruction<'a, 'b> {
397    __program: &'b solana_program::account_info::AccountInfo<'a>,
398    metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
399    update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
400    mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
401    edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
402    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
403    __remaining_accounts: Vec<(
404        &'b solana_program::account_info::AccountInfo<'a>,
405        bool,
406        bool,
407    )>,
408}