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