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