Skip to main content

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