security_token_client/generated/instructions/
verify.rs1use crate::generated::types::VerifyArgs;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12pub const VERIFY_DISCRIMINATOR: u8 = 5;
13
14#[derive(Debug)]
16pub struct Verify {
17 pub mint: solana_pubkey::Pubkey,
18
19 pub verification_config: solana_pubkey::Pubkey,
20
21 pub instructions_sysvar: solana_pubkey::Pubkey,
22}
23
24impl Verify {
25 pub fn instruction(&self, args: VerifyInstructionArgs) -> solana_instruction::Instruction {
26 self.instruction_with_remaining_accounts(args, &[])
27 }
28 #[allow(clippy::arithmetic_side_effects)]
29 #[allow(clippy::vec_init_then_push)]
30 pub fn instruction_with_remaining_accounts(
31 &self,
32 args: VerifyInstructionArgs,
33 remaining_accounts: &[solana_instruction::AccountMeta],
34 ) -> solana_instruction::Instruction {
35 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
36 accounts.push(solana_instruction::AccountMeta::new_readonly(
37 self.mint, false,
38 ));
39 accounts.push(solana_instruction::AccountMeta::new_readonly(
40 self.verification_config,
41 false,
42 ));
43 accounts.push(solana_instruction::AccountMeta::new_readonly(
44 self.instructions_sysvar,
45 false,
46 ));
47 accounts.extend_from_slice(remaining_accounts);
48 let mut data = borsh::to_vec(&VerifyInstructionData::new()).unwrap();
49 let mut args = borsh::to_vec(&args).unwrap();
50 data.append(&mut args);
51
52 solana_instruction::Instruction {
53 program_id: crate::SECURITY_TOKEN_PROGRAM_ID,
54 accounts,
55 data,
56 }
57 }
58}
59
60#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
61#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
62pub struct VerifyInstructionData {
63 discriminator: u8,
64}
65
66impl VerifyInstructionData {
67 pub fn new() -> Self {
68 Self { discriminator: 5 }
69 }
70}
71
72impl Default for VerifyInstructionData {
73 fn default() -> Self {
74 Self::new()
75 }
76}
77
78#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub struct VerifyInstructionArgs {
81 pub verify_args: VerifyArgs,
82}
83
84#[derive(Clone, Debug, Default)]
92pub struct VerifyBuilder {
93 mint: Option<solana_pubkey::Pubkey>,
94 verification_config: Option<solana_pubkey::Pubkey>,
95 instructions_sysvar: Option<solana_pubkey::Pubkey>,
96 verify_args: Option<VerifyArgs>,
97 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
98}
99
100impl VerifyBuilder {
101 pub fn new() -> Self {
102 Self::default()
103 }
104 #[inline(always)]
105 pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self {
106 self.mint = Some(mint);
107 self
108 }
109 #[inline(always)]
110 pub fn verification_config(&mut self, verification_config: solana_pubkey::Pubkey) -> &mut Self {
111 self.verification_config = Some(verification_config);
112 self
113 }
114 #[inline(always)]
116 pub fn instructions_sysvar(&mut self, instructions_sysvar: solana_pubkey::Pubkey) -> &mut Self {
117 self.instructions_sysvar = Some(instructions_sysvar);
118 self
119 }
120 #[inline(always)]
121 pub fn verify_args(&mut self, verify_args: VerifyArgs) -> &mut Self {
122 self.verify_args = Some(verify_args);
123 self
124 }
125 #[inline(always)]
127 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
128 self.__remaining_accounts.push(account);
129 self
130 }
131 #[inline(always)]
133 pub fn add_remaining_accounts(
134 &mut self,
135 accounts: &[solana_instruction::AccountMeta],
136 ) -> &mut Self {
137 self.__remaining_accounts.extend_from_slice(accounts);
138 self
139 }
140 #[allow(clippy::clone_on_copy)]
141 pub fn instruction(&self) -> solana_instruction::Instruction {
142 let accounts = Verify {
143 mint: self.mint.expect("mint is not set"),
144 verification_config: self
145 .verification_config
146 .expect("verification_config is not set"),
147 instructions_sysvar: self.instructions_sysvar.unwrap_or(solana_pubkey::pubkey!(
148 "Sysvar1nstructions1111111111111111111111111"
149 )),
150 };
151 let args = VerifyInstructionArgs {
152 verify_args: self.verify_args.clone().expect("verify_args is not set"),
153 };
154
155 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
156 }
157}
158
159pub struct VerifyCpiAccounts<'a, 'b> {
161 pub mint: &'b solana_account_info::AccountInfo<'a>,
162
163 pub verification_config: &'b solana_account_info::AccountInfo<'a>,
164
165 pub instructions_sysvar: &'b solana_account_info::AccountInfo<'a>,
166}
167
168pub struct VerifyCpi<'a, 'b> {
170 pub __program: &'b solana_account_info::AccountInfo<'a>,
172
173 pub mint: &'b solana_account_info::AccountInfo<'a>,
174
175 pub verification_config: &'b solana_account_info::AccountInfo<'a>,
176
177 pub instructions_sysvar: &'b solana_account_info::AccountInfo<'a>,
178 pub __args: VerifyInstructionArgs,
180}
181
182impl<'a, 'b> VerifyCpi<'a, 'b> {
183 pub fn new(
184 program: &'b solana_account_info::AccountInfo<'a>,
185 accounts: VerifyCpiAccounts<'a, 'b>,
186 args: VerifyInstructionArgs,
187 ) -> Self {
188 Self {
189 __program: program,
190 mint: accounts.mint,
191 verification_config: accounts.verification_config,
192 instructions_sysvar: accounts.instructions_sysvar,
193 __args: args,
194 }
195 }
196 #[inline(always)]
197 pub fn invoke(&self) -> solana_program_error::ProgramResult {
198 self.invoke_signed_with_remaining_accounts(&[], &[])
199 }
200 #[inline(always)]
201 pub fn invoke_with_remaining_accounts(
202 &self,
203 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
204 ) -> solana_program_error::ProgramResult {
205 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
206 }
207 #[inline(always)]
208 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
209 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
210 }
211 #[allow(clippy::arithmetic_side_effects)]
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: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
218 ) -> solana_program_error::ProgramResult {
219 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
220 accounts.push(solana_instruction::AccountMeta::new_readonly(
221 *self.mint.key,
222 false,
223 ));
224 accounts.push(solana_instruction::AccountMeta::new_readonly(
225 *self.verification_config.key,
226 false,
227 ));
228 accounts.push(solana_instruction::AccountMeta::new_readonly(
229 *self.instructions_sysvar.key,
230 false,
231 ));
232 remaining_accounts.iter().for_each(|remaining_account| {
233 accounts.push(solana_instruction::AccountMeta {
234 pubkey: *remaining_account.0.key,
235 is_signer: remaining_account.1,
236 is_writable: remaining_account.2,
237 })
238 });
239 let mut data = borsh::to_vec(&VerifyInstructionData::new()).unwrap();
240 let mut args = borsh::to_vec(&self.__args).unwrap();
241 data.append(&mut args);
242
243 let instruction = solana_instruction::Instruction {
244 program_id: crate::SECURITY_TOKEN_PROGRAM_ID,
245 accounts,
246 data,
247 };
248 let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
249 account_infos.push(self.__program.clone());
250 account_infos.push(self.mint.clone());
251 account_infos.push(self.verification_config.clone());
252 account_infos.push(self.instructions_sysvar.clone());
253 remaining_accounts
254 .iter()
255 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
256
257 if signers_seeds.is_empty() {
258 solana_cpi::invoke(&instruction, &account_infos)
259 } else {
260 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
261 }
262 }
263}
264
265#[derive(Clone, Debug)]
273pub struct VerifyCpiBuilder<'a, 'b> {
274 instruction: Box<VerifyCpiBuilderInstruction<'a, 'b>>,
275}
276
277impl<'a, 'b> VerifyCpiBuilder<'a, 'b> {
278 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
279 let instruction = Box::new(VerifyCpiBuilderInstruction {
280 __program: program,
281 mint: None,
282 verification_config: None,
283 instructions_sysvar: None,
284 verify_args: None,
285 __remaining_accounts: Vec::new(),
286 });
287 Self { instruction }
288 }
289 #[inline(always)]
290 pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
291 self.instruction.mint = Some(mint);
292 self
293 }
294 #[inline(always)]
295 pub fn verification_config(
296 &mut self,
297 verification_config: &'b solana_account_info::AccountInfo<'a>,
298 ) -> &mut Self {
299 self.instruction.verification_config = Some(verification_config);
300 self
301 }
302 #[inline(always)]
303 pub fn instructions_sysvar(
304 &mut self,
305 instructions_sysvar: &'b solana_account_info::AccountInfo<'a>,
306 ) -> &mut Self {
307 self.instruction.instructions_sysvar = Some(instructions_sysvar);
308 self
309 }
310 #[inline(always)]
311 pub fn verify_args(&mut self, verify_args: VerifyArgs) -> &mut Self {
312 self.instruction.verify_args = Some(verify_args);
313 self
314 }
315 #[inline(always)]
317 pub fn add_remaining_account(
318 &mut self,
319 account: &'b solana_account_info::AccountInfo<'a>,
320 is_writable: bool,
321 is_signer: bool,
322 ) -> &mut Self {
323 self.instruction
324 .__remaining_accounts
325 .push((account, is_writable, is_signer));
326 self
327 }
328 #[inline(always)]
333 pub fn add_remaining_accounts(
334 &mut self,
335 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
336 ) -> &mut Self {
337 self.instruction
338 .__remaining_accounts
339 .extend_from_slice(accounts);
340 self
341 }
342 #[inline(always)]
343 pub fn invoke(&self) -> solana_program_error::ProgramResult {
344 self.invoke_signed(&[])
345 }
346 #[allow(clippy::clone_on_copy)]
347 #[allow(clippy::vec_init_then_push)]
348 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
349 let args = VerifyInstructionArgs {
350 verify_args: self
351 .instruction
352 .verify_args
353 .clone()
354 .expect("verify_args is not set"),
355 };
356 let instruction = VerifyCpi {
357 __program: self.instruction.__program,
358
359 mint: self.instruction.mint.expect("mint is not set"),
360
361 verification_config: self
362 .instruction
363 .verification_config
364 .expect("verification_config is not set"),
365
366 instructions_sysvar: self
367 .instruction
368 .instructions_sysvar
369 .expect("instructions_sysvar is not set"),
370 __args: args,
371 };
372 instruction.invoke_signed_with_remaining_accounts(
373 signers_seeds,
374 &self.instruction.__remaining_accounts,
375 )
376 }
377}
378
379#[derive(Clone, Debug)]
380struct VerifyCpiBuilderInstruction<'a, 'b> {
381 __program: &'b solana_account_info::AccountInfo<'a>,
382 mint: Option<&'b solana_account_info::AccountInfo<'a>>,
383 verification_config: Option<&'b solana_account_info::AccountInfo<'a>>,
384 instructions_sysvar: Option<&'b solana_account_info::AccountInfo<'a>>,
385 verify_args: Option<VerifyArgs>,
386 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
388}