lighthouse_sdk/generated/instructions/
assert_merkle_tree_account.rs1use crate::generated::types::LogLevel;
9use crate::generated::types::MerkleTreeAssertion;
10use borsh::BorshDeserialize;
11use borsh::BorshSerialize;
12
13pub struct AssertMerkleTreeAccount {
15 pub target_merkle_tree: solana_program::pubkey::Pubkey,
17 pub root: solana_program::pubkey::Pubkey,
19 pub spl_account_compression: solana_program::pubkey::Pubkey,
21}
22
23impl AssertMerkleTreeAccount {
24 pub fn instruction(
25 &self,
26 args: AssertMerkleTreeAccountInstructionArgs,
27 ) -> solana_program::instruction::Instruction {
28 self.instruction_with_remaining_accounts(args, &[])
29 }
30 #[allow(clippy::vec_init_then_push)]
31 pub fn instruction_with_remaining_accounts(
32 &self,
33 args: AssertMerkleTreeAccountInstructionArgs,
34 remaining_accounts: &[solana_program::instruction::AccountMeta],
35 ) -> solana_program::instruction::Instruction {
36 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
37 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38 self.target_merkle_tree,
39 false,
40 ));
41 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42 self.root, false,
43 ));
44 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
45 self.spl_account_compression,
46 false,
47 ));
48 accounts.extend_from_slice(remaining_accounts);
49 let mut data = AssertMerkleTreeAccountInstructionData::new()
50 .try_to_vec()
51 .unwrap();
52 let mut args = args.try_to_vec().unwrap();
53 data.append(&mut args);
54
55 solana_program::instruction::Instruction {
56 program_id: crate::LIGHTHOUSE_ID,
57 accounts,
58 data,
59 }
60 }
61}
62
63#[derive(BorshDeserialize, BorshSerialize)]
64pub struct AssertMerkleTreeAccountInstructionData {
65 discriminator: u8,
66}
67
68impl AssertMerkleTreeAccountInstructionData {
69 pub fn new() -> Self {
70 Self { discriminator: 16 }
71 }
72}
73
74#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
75#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
76pub struct AssertMerkleTreeAccountInstructionArgs {
77 pub log_level: LogLevel,
78 pub assertion: MerkleTreeAssertion,
79}
80
81#[derive(Clone, Debug, Default)]
89pub struct AssertMerkleTreeAccountBuilder {
90 target_merkle_tree: Option<solana_program::pubkey::Pubkey>,
91 root: Option<solana_program::pubkey::Pubkey>,
92 spl_account_compression: Option<solana_program::pubkey::Pubkey>,
93 log_level: Option<LogLevel>,
94 assertion: Option<MerkleTreeAssertion>,
95 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
96}
97
98impl AssertMerkleTreeAccountBuilder {
99 pub fn new() -> Self {
100 Self::default()
101 }
102 #[inline(always)]
104 pub fn target_merkle_tree(
105 &mut self,
106 target_merkle_tree: solana_program::pubkey::Pubkey,
107 ) -> &mut Self {
108 self.target_merkle_tree = Some(target_merkle_tree);
109 self
110 }
111 #[inline(always)]
113 pub fn root(&mut self, root: solana_program::pubkey::Pubkey) -> &mut Self {
114 self.root = Some(root);
115 self
116 }
117 #[inline(always)]
119 pub fn spl_account_compression(
120 &mut self,
121 spl_account_compression: solana_program::pubkey::Pubkey,
122 ) -> &mut Self {
123 self.spl_account_compression = Some(spl_account_compression);
124 self
125 }
126 #[inline(always)]
128 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
129 self.log_level = Some(log_level);
130 self
131 }
132 #[inline(always)]
133 pub fn assertion(&mut self, assertion: MerkleTreeAssertion) -> &mut Self {
134 self.assertion = Some(assertion);
135 self
136 }
137 #[inline(always)]
139 pub fn add_remaining_account(
140 &mut self,
141 account: solana_program::instruction::AccountMeta,
142 ) -> &mut Self {
143 self.__remaining_accounts.push(account);
144 self
145 }
146 #[inline(always)]
148 pub fn add_remaining_accounts(
149 &mut self,
150 accounts: &[solana_program::instruction::AccountMeta],
151 ) -> &mut Self {
152 self.__remaining_accounts.extend_from_slice(accounts);
153 self
154 }
155 #[allow(clippy::clone_on_copy)]
156 pub fn instruction(&self) -> solana_program::instruction::Instruction {
157 let accounts = AssertMerkleTreeAccount {
158 target_merkle_tree: self
159 .target_merkle_tree
160 .expect("target_merkle_tree is not set"),
161 root: self.root.expect("root is not set"),
162 spl_account_compression: self
163 .spl_account_compression
164 .expect("spl_account_compression is not set"),
165 };
166 let args = AssertMerkleTreeAccountInstructionArgs {
167 log_level: self.log_level.clone().unwrap_or(LogLevel::Silent),
168 assertion: self.assertion.clone().expect("assertion is not set"),
169 };
170
171 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
172 }
173}
174
175pub struct AssertMerkleTreeAccountCpiAccounts<'a, 'b> {
177 pub target_merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
179 pub root: &'b solana_program::account_info::AccountInfo<'a>,
181 pub spl_account_compression: &'b solana_program::account_info::AccountInfo<'a>,
183}
184
185pub struct AssertMerkleTreeAccountCpi<'a, 'b> {
187 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
189 pub target_merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
191 pub root: &'b solana_program::account_info::AccountInfo<'a>,
193 pub spl_account_compression: &'b solana_program::account_info::AccountInfo<'a>,
195 pub __args: AssertMerkleTreeAccountInstructionArgs,
197}
198
199impl<'a, 'b> AssertMerkleTreeAccountCpi<'a, 'b> {
200 pub fn new(
201 program: &'b solana_program::account_info::AccountInfo<'a>,
202 accounts: AssertMerkleTreeAccountCpiAccounts<'a, 'b>,
203 args: AssertMerkleTreeAccountInstructionArgs,
204 ) -> Self {
205 Self {
206 __program: program,
207 target_merkle_tree: accounts.target_merkle_tree,
208 root: accounts.root,
209 spl_account_compression: accounts.spl_account_compression,
210 __args: args,
211 }
212 }
213 #[inline(always)]
214 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
215 self.invoke_signed_with_remaining_accounts(&[], &[])
216 }
217 #[inline(always)]
218 pub fn invoke_with_remaining_accounts(
219 &self,
220 remaining_accounts: &[(
221 &'b solana_program::account_info::AccountInfo<'a>,
222 bool,
223 bool,
224 )],
225 ) -> solana_program::entrypoint::ProgramResult {
226 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
227 }
228 #[inline(always)]
229 pub fn invoke_signed(
230 &self,
231 signers_seeds: &[&[&[u8]]],
232 ) -> solana_program::entrypoint::ProgramResult {
233 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
234 }
235 #[allow(clippy::clone_on_copy)]
236 #[allow(clippy::vec_init_then_push)]
237 pub fn invoke_signed_with_remaining_accounts(
238 &self,
239 signers_seeds: &[&[&[u8]]],
240 remaining_accounts: &[(
241 &'b solana_program::account_info::AccountInfo<'a>,
242 bool,
243 bool,
244 )],
245 ) -> solana_program::entrypoint::ProgramResult {
246 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
247 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
248 *self.target_merkle_tree.key,
249 false,
250 ));
251 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
252 *self.root.key,
253 false,
254 ));
255 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
256 *self.spl_account_compression.key,
257 false,
258 ));
259 remaining_accounts.iter().for_each(|remaining_account| {
260 accounts.push(solana_program::instruction::AccountMeta {
261 pubkey: *remaining_account.0.key,
262 is_signer: remaining_account.1,
263 is_writable: remaining_account.2,
264 })
265 });
266 let mut data = AssertMerkleTreeAccountInstructionData::new()
267 .try_to_vec()
268 .unwrap();
269 let mut args = self.__args.try_to_vec().unwrap();
270 data.append(&mut args);
271
272 let instruction = solana_program::instruction::Instruction {
273 program_id: crate::LIGHTHOUSE_ID,
274 accounts,
275 data,
276 };
277 let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
278 account_infos.push(self.__program.clone());
279 account_infos.push(self.target_merkle_tree.clone());
280 account_infos.push(self.root.clone());
281 account_infos.push(self.spl_account_compression.clone());
282 remaining_accounts
283 .iter()
284 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
285
286 if signers_seeds.is_empty() {
287 solana_program::program::invoke(&instruction, &account_infos)
288 } else {
289 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
290 }
291 }
292}
293
294#[derive(Clone, Debug)]
302pub struct AssertMerkleTreeAccountCpiBuilder<'a, 'b> {
303 instruction: Box<AssertMerkleTreeAccountCpiBuilderInstruction<'a, 'b>>,
304}
305
306impl<'a, 'b> AssertMerkleTreeAccountCpiBuilder<'a, 'b> {
307 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
308 let instruction = Box::new(AssertMerkleTreeAccountCpiBuilderInstruction {
309 __program: program,
310 target_merkle_tree: None,
311 root: None,
312 spl_account_compression: None,
313 log_level: None,
314 assertion: None,
315 __remaining_accounts: Vec::new(),
316 });
317 Self { instruction }
318 }
319 #[inline(always)]
321 pub fn target_merkle_tree(
322 &mut self,
323 target_merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
324 ) -> &mut Self {
325 self.instruction.target_merkle_tree = Some(target_merkle_tree);
326 self
327 }
328 #[inline(always)]
330 pub fn root(&mut self, root: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
331 self.instruction.root = Some(root);
332 self
333 }
334 #[inline(always)]
336 pub fn spl_account_compression(
337 &mut self,
338 spl_account_compression: &'b solana_program::account_info::AccountInfo<'a>,
339 ) -> &mut Self {
340 self.instruction.spl_account_compression = Some(spl_account_compression);
341 self
342 }
343 #[inline(always)]
345 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
346 self.instruction.log_level = Some(log_level);
347 self
348 }
349 #[inline(always)]
350 pub fn assertion(&mut self, assertion: MerkleTreeAssertion) -> &mut Self {
351 self.instruction.assertion = Some(assertion);
352 self
353 }
354 #[inline(always)]
356 pub fn add_remaining_account(
357 &mut self,
358 account: &'b solana_program::account_info::AccountInfo<'a>,
359 is_writable: bool,
360 is_signer: bool,
361 ) -> &mut Self {
362 self.instruction
363 .__remaining_accounts
364 .push((account, is_writable, is_signer));
365 self
366 }
367 #[inline(always)]
372 pub fn add_remaining_accounts(
373 &mut self,
374 accounts: &[(
375 &'b solana_program::account_info::AccountInfo<'a>,
376 bool,
377 bool,
378 )],
379 ) -> &mut Self {
380 self.instruction
381 .__remaining_accounts
382 .extend_from_slice(accounts);
383 self
384 }
385 #[inline(always)]
386 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
387 self.invoke_signed(&[])
388 }
389 #[allow(clippy::clone_on_copy)]
390 #[allow(clippy::vec_init_then_push)]
391 pub fn invoke_signed(
392 &self,
393 signers_seeds: &[&[&[u8]]],
394 ) -> solana_program::entrypoint::ProgramResult {
395 let args = AssertMerkleTreeAccountInstructionArgs {
396 log_level: self
397 .instruction
398 .log_level
399 .clone()
400 .unwrap_or(LogLevel::Silent),
401 assertion: self
402 .instruction
403 .assertion
404 .clone()
405 .expect("assertion is not set"),
406 };
407 let instruction = AssertMerkleTreeAccountCpi {
408 __program: self.instruction.__program,
409
410 target_merkle_tree: self
411 .instruction
412 .target_merkle_tree
413 .expect("target_merkle_tree is not set"),
414
415 root: self.instruction.root.expect("root is not set"),
416
417 spl_account_compression: self
418 .instruction
419 .spl_account_compression
420 .expect("spl_account_compression is not set"),
421 __args: args,
422 };
423 instruction.invoke_signed_with_remaining_accounts(
424 signers_seeds,
425 &self.instruction.__remaining_accounts,
426 )
427 }
428}
429
430#[derive(Clone, Debug)]
431struct AssertMerkleTreeAccountCpiBuilderInstruction<'a, 'b> {
432 __program: &'b solana_program::account_info::AccountInfo<'a>,
433 target_merkle_tree: Option<&'b solana_program::account_info::AccountInfo<'a>>,
434 root: Option<&'b solana_program::account_info::AccountInfo<'a>>,
435 spl_account_compression: Option<&'b solana_program::account_info::AccountInfo<'a>>,
436 log_level: Option<LogLevel>,
437 assertion: Option<MerkleTreeAssertion>,
438 __remaining_accounts: Vec<(
440 &'b solana_program::account_info::AccountInfo<'a>,
441 bool,
442 bool,
443 )>,
444}