Skip to main content

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