lighthouse_sdk/generated/instructions/
assert_account_data.rs1use crate::generated::types::DataValueAssertion;
9use crate::generated::types::LogLevel;
10use crate::hooked::CompactU64;
11use borsh::BorshDeserialize;
12use borsh::BorshSerialize;
13
14pub struct AssertAccountData {
16 pub target_account: solana_program::pubkey::Pubkey,
18}
19
20impl AssertAccountData {
21 pub fn instruction(
22 &self,
23 args: AssertAccountDataInstructionArgs,
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: AssertAccountDataInstructionArgs,
31 remaining_accounts: &[solana_program::instruction::AccountMeta],
32 ) -> solana_program::instruction::Instruction {
33 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
34 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
35 self.target_account,
36 false,
37 ));
38 accounts.extend_from_slice(remaining_accounts);
39 let mut data = AssertAccountDataInstructionData::new()
40 .try_to_vec()
41 .unwrap();
42 let mut args = args.try_to_vec().unwrap();
43 data.append(&mut args);
44
45 solana_program::instruction::Instruction {
46 program_id: crate::LIGHTHOUSE_ID,
47 accounts,
48 data,
49 }
50 }
51}
52
53#[derive(BorshDeserialize, BorshSerialize)]
54pub struct AssertAccountDataInstructionData {
55 discriminator: u8,
56}
57
58impl AssertAccountDataInstructionData {
59 pub fn new() -> Self {
60 Self { discriminator: 2 }
61 }
62}
63
64#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
65#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
66pub struct AssertAccountDataInstructionArgs {
67 pub log_level: LogLevel,
68 pub offset: CompactU64,
69 pub assertion: DataValueAssertion,
70}
71
72#[derive(Clone, Debug, Default)]
78pub struct AssertAccountDataBuilder {
79 target_account: Option<solana_program::pubkey::Pubkey>,
80 log_level: Option<LogLevel>,
81 offset: Option<CompactU64>,
82 assertion: Option<DataValueAssertion>,
83 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
84}
85
86impl AssertAccountDataBuilder {
87 pub fn new() -> Self {
88 Self::default()
89 }
90 #[inline(always)]
92 pub fn target_account(&mut self, target_account: solana_program::pubkey::Pubkey) -> &mut Self {
93 self.target_account = Some(target_account);
94 self
95 }
96 #[inline(always)]
98 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
99 self.log_level = Some(log_level);
100 self
101 }
102 #[inline(always)]
103 pub fn offset(&mut self, offset: CompactU64) -> &mut Self {
104 self.offset = Some(offset);
105 self
106 }
107 #[inline(always)]
108 pub fn assertion(&mut self, assertion: DataValueAssertion) -> &mut Self {
109 self.assertion = Some(assertion);
110 self
111 }
112 #[inline(always)]
114 pub fn add_remaining_account(
115 &mut self,
116 account: solana_program::instruction::AccountMeta,
117 ) -> &mut Self {
118 self.__remaining_accounts.push(account);
119 self
120 }
121 #[inline(always)]
123 pub fn add_remaining_accounts(
124 &mut self,
125 accounts: &[solana_program::instruction::AccountMeta],
126 ) -> &mut Self {
127 self.__remaining_accounts.extend_from_slice(accounts);
128 self
129 }
130 #[allow(clippy::clone_on_copy)]
131 pub fn instruction(&self) -> solana_program::instruction::Instruction {
132 let accounts = AssertAccountData {
133 target_account: self.target_account.expect("target_account is not set"),
134 };
135 let args = AssertAccountDataInstructionArgs {
136 log_level: self.log_level.clone().unwrap_or(LogLevel::Silent),
137 offset: self.offset.clone().expect("offset is not set"),
138 assertion: self.assertion.clone().expect("assertion is not set"),
139 };
140
141 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
142 }
143}
144
145pub struct AssertAccountDataCpiAccounts<'a, 'b> {
147 pub target_account: &'b solana_program::account_info::AccountInfo<'a>,
149}
150
151pub struct AssertAccountDataCpi<'a, 'b> {
153 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
155 pub target_account: &'b solana_program::account_info::AccountInfo<'a>,
157 pub __args: AssertAccountDataInstructionArgs,
159}
160
161impl<'a, 'b> AssertAccountDataCpi<'a, 'b> {
162 pub fn new(
163 program: &'b solana_program::account_info::AccountInfo<'a>,
164 accounts: AssertAccountDataCpiAccounts<'a, 'b>,
165 args: AssertAccountDataInstructionArgs,
166 ) -> Self {
167 Self {
168 __program: program,
169 target_account: accounts.target_account,
170 __args: args,
171 }
172 }
173 #[inline(always)]
174 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
175 self.invoke_signed_with_remaining_accounts(&[], &[])
176 }
177 #[inline(always)]
178 pub fn invoke_with_remaining_accounts(
179 &self,
180 remaining_accounts: &[(
181 &'b solana_program::account_info::AccountInfo<'a>,
182 bool,
183 bool,
184 )],
185 ) -> solana_program::entrypoint::ProgramResult {
186 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
187 }
188 #[inline(always)]
189 pub fn invoke_signed(
190 &self,
191 signers_seeds: &[&[&[u8]]],
192 ) -> solana_program::entrypoint::ProgramResult {
193 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
194 }
195 #[allow(clippy::clone_on_copy)]
196 #[allow(clippy::vec_init_then_push)]
197 pub fn invoke_signed_with_remaining_accounts(
198 &self,
199 signers_seeds: &[&[&[u8]]],
200 remaining_accounts: &[(
201 &'b solana_program::account_info::AccountInfo<'a>,
202 bool,
203 bool,
204 )],
205 ) -> solana_program::entrypoint::ProgramResult {
206 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
207 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
208 *self.target_account.key,
209 false,
210 ));
211 remaining_accounts.iter().for_each(|remaining_account| {
212 accounts.push(solana_program::instruction::AccountMeta {
213 pubkey: *remaining_account.0.key,
214 is_signer: remaining_account.1,
215 is_writable: remaining_account.2,
216 })
217 });
218 let mut data = AssertAccountDataInstructionData::new()
219 .try_to_vec()
220 .unwrap();
221 let mut args = self.__args.try_to_vec().unwrap();
222 data.append(&mut args);
223
224 let instruction = solana_program::instruction::Instruction {
225 program_id: crate::LIGHTHOUSE_ID,
226 accounts,
227 data,
228 };
229 let mut account_infos = Vec::with_capacity(1 + 1 + remaining_accounts.len());
230 account_infos.push(self.__program.clone());
231 account_infos.push(self.target_account.clone());
232 remaining_accounts
233 .iter()
234 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
235
236 if signers_seeds.is_empty() {
237 solana_program::program::invoke(&instruction, &account_infos)
238 } else {
239 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
240 }
241 }
242}
243
244#[derive(Clone, Debug)]
250pub struct AssertAccountDataCpiBuilder<'a, 'b> {
251 instruction: Box<AssertAccountDataCpiBuilderInstruction<'a, 'b>>,
252}
253
254impl<'a, 'b> AssertAccountDataCpiBuilder<'a, 'b> {
255 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
256 let instruction = Box::new(AssertAccountDataCpiBuilderInstruction {
257 __program: program,
258 target_account: None,
259 log_level: None,
260 offset: None,
261 assertion: None,
262 __remaining_accounts: Vec::new(),
263 });
264 Self { instruction }
265 }
266 #[inline(always)]
268 pub fn target_account(
269 &mut self,
270 target_account: &'b solana_program::account_info::AccountInfo<'a>,
271 ) -> &mut Self {
272 self.instruction.target_account = Some(target_account);
273 self
274 }
275 #[inline(always)]
277 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
278 self.instruction.log_level = Some(log_level);
279 self
280 }
281 #[inline(always)]
282 pub fn offset(&mut self, offset: CompactU64) -> &mut Self {
283 self.instruction.offset = Some(offset);
284 self
285 }
286 #[inline(always)]
287 pub fn assertion(&mut self, assertion: DataValueAssertion) -> &mut Self {
288 self.instruction.assertion = Some(assertion);
289 self
290 }
291 #[inline(always)]
293 pub fn add_remaining_account(
294 &mut self,
295 account: &'b solana_program::account_info::AccountInfo<'a>,
296 is_writable: bool,
297 is_signer: bool,
298 ) -> &mut Self {
299 self.instruction
300 .__remaining_accounts
301 .push((account, is_writable, is_signer));
302 self
303 }
304 #[inline(always)]
309 pub fn add_remaining_accounts(
310 &mut self,
311 accounts: &[(
312 &'b solana_program::account_info::AccountInfo<'a>,
313 bool,
314 bool,
315 )],
316 ) -> &mut Self {
317 self.instruction
318 .__remaining_accounts
319 .extend_from_slice(accounts);
320 self
321 }
322 #[inline(always)]
323 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
324 self.invoke_signed(&[])
325 }
326 #[allow(clippy::clone_on_copy)]
327 #[allow(clippy::vec_init_then_push)]
328 pub fn invoke_signed(
329 &self,
330 signers_seeds: &[&[&[u8]]],
331 ) -> solana_program::entrypoint::ProgramResult {
332 let args = AssertAccountDataInstructionArgs {
333 log_level: self
334 .instruction
335 .log_level
336 .clone()
337 .unwrap_or(LogLevel::Silent),
338 offset: self.instruction.offset.clone().expect("offset is not set"),
339 assertion: self
340 .instruction
341 .assertion
342 .clone()
343 .expect("assertion is not set"),
344 };
345 let instruction = AssertAccountDataCpi {
346 __program: self.instruction.__program,
347
348 target_account: self
349 .instruction
350 .target_account
351 .expect("target_account is not set"),
352 __args: args,
353 };
354 instruction.invoke_signed_with_remaining_accounts(
355 signers_seeds,
356 &self.instruction.__remaining_accounts,
357 )
358 }
359}
360
361#[derive(Clone, Debug)]
362struct AssertAccountDataCpiBuilderInstruction<'a, 'b> {
363 __program: &'b solana_program::account_info::AccountInfo<'a>,
364 target_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
365 log_level: Option<LogLevel>,
366 offset: Option<CompactU64>,
367 assertion: Option<DataValueAssertion>,
368 __remaining_accounts: Vec<(
370 &'b solana_program::account_info::AccountInfo<'a>,
371 bool,
372 bool,
373 )>,
374}