lighthouse_sol/instructions/
assert_upgradeable_loader_account_multi.rs1use crate::types::LogLevel;
9use crate::types::hooked::UpgradeableLoaderStateAssertions;
10use borsh::BorshDeserialize;
11use borsh::BorshSerialize;
12
13#[derive(Debug)]
15pub struct AssertUpgradeableLoaderAccountMulti {
16 pub target_account: solana_pubkey::Pubkey,
18}
19
20impl AssertUpgradeableLoaderAccountMulti {
21 pub fn instruction(
22 &self,
23 args: AssertUpgradeableLoaderAccountMultiInstructionArgs,
24 ) -> solana_instruction::Instruction {
25 self.instruction_with_remaining_accounts(args, &[])
26 }
27 #[allow(clippy::arithmetic_side_effects)]
28 #[allow(clippy::vec_init_then_push)]
29 pub fn instruction_with_remaining_accounts(
30 &self,
31 args: AssertUpgradeableLoaderAccountMultiInstructionArgs,
32 remaining_accounts: &[solana_instruction::AccountMeta],
33 ) -> solana_instruction::Instruction {
34 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
35 accounts.push(solana_instruction::AccountMeta::new_readonly(
36 self.target_account,
37 false,
38 ));
39 accounts.extend_from_slice(remaining_accounts);
40 let mut data =
41 borsh::to_vec(&AssertUpgradeableLoaderAccountMultiInstructionData::new()).unwrap();
42 let mut args = borsh::to_vec(&args).unwrap();
43 data.append(&mut args);
44
45 solana_instruction::Instruction {
46 program_id: crate::LIGHTHOUSE_ID,
47 accounts,
48 data,
49 }
50 }
51}
52
53#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
54#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
55pub struct AssertUpgradeableLoaderAccountMultiInstructionData {
56 discriminator: u8,
57}
58
59impl AssertUpgradeableLoaderAccountMultiInstructionData {
60 pub fn new() -> Self {
61 Self { discriminator: 14 }
62 }
63}
64
65impl Default for AssertUpgradeableLoaderAccountMultiInstructionData {
66 fn default() -> Self {
67 Self::new()
68 }
69}
70
71#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
72#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
73pub struct AssertUpgradeableLoaderAccountMultiInstructionArgs {
74 pub log_level: LogLevel,
75 pub assertions: UpgradeableLoaderStateAssertions,
76}
77
78#[derive(Clone, Debug, Default)]
84pub struct AssertUpgradeableLoaderAccountMultiBuilder {
85 target_account: Option<solana_pubkey::Pubkey>,
86 log_level: Option<LogLevel>,
87 assertions: Option<UpgradeableLoaderStateAssertions>,
88 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
89}
90
91impl AssertUpgradeableLoaderAccountMultiBuilder {
92 pub fn new() -> Self {
93 Self::default()
94 }
95 #[inline(always)]
97 pub fn target_account(&mut self, target_account: solana_pubkey::Pubkey) -> &mut Self {
98 self.target_account = Some(target_account);
99 self
100 }
101 #[inline(always)]
102 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
103 self.log_level = Some(log_level);
104 self
105 }
106 #[inline(always)]
107 pub fn assertions(&mut self, assertions: UpgradeableLoaderStateAssertions) -> &mut Self {
108 self.assertions = Some(assertions);
109 self
110 }
111 #[inline(always)]
113 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
114 self.__remaining_accounts.push(account);
115 self
116 }
117 #[inline(always)]
119 pub fn add_remaining_accounts(
120 &mut self,
121 accounts: &[solana_instruction::AccountMeta],
122 ) -> &mut Self {
123 self.__remaining_accounts.extend_from_slice(accounts);
124 self
125 }
126 #[allow(clippy::clone_on_copy)]
127 pub fn instruction(&self) -> solana_instruction::Instruction {
128 let accounts = AssertUpgradeableLoaderAccountMulti {
129 target_account: self.target_account.expect("target_account is not set"),
130 };
131 let args = AssertUpgradeableLoaderAccountMultiInstructionArgs {
132 log_level: self.log_level.clone().expect("log_level is not set"),
133 assertions: self.assertions.clone().expect("assertions is not set"),
134 };
135
136 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
137 }
138}
139
140pub struct AssertUpgradeableLoaderAccountMultiCpiAccounts<'a, 'b> {
142 pub target_account: &'b solana_account_info::AccountInfo<'a>,
144}
145
146pub struct AssertUpgradeableLoaderAccountMultiCpi<'a, 'b> {
148 pub __program: &'b solana_account_info::AccountInfo<'a>,
150 pub target_account: &'b solana_account_info::AccountInfo<'a>,
152 pub __args: AssertUpgradeableLoaderAccountMultiInstructionArgs,
154}
155
156impl<'a, 'b> AssertUpgradeableLoaderAccountMultiCpi<'a, 'b> {
157 pub fn new(
158 program: &'b solana_account_info::AccountInfo<'a>,
159 accounts: AssertUpgradeableLoaderAccountMultiCpiAccounts<'a, 'b>,
160 args: AssertUpgradeableLoaderAccountMultiInstructionArgs,
161 ) -> Self {
162 Self {
163 __program: program,
164 target_account: accounts.target_account,
165 __args: args,
166 }
167 }
168 #[inline(always)]
169 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
170 self.invoke_signed_with_remaining_accounts(&[], &[])
171 }
172 #[inline(always)]
173 pub fn invoke_with_remaining_accounts(
174 &self,
175 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
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::arithmetic_side_effects)]
187 #[allow(clippy::clone_on_copy)]
188 #[allow(clippy::vec_init_then_push)]
189 pub fn invoke_signed_with_remaining_accounts(
190 &self,
191 signers_seeds: &[&[&[u8]]],
192 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
193 ) -> solana_program_entrypoint::ProgramResult {
194 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
195 accounts.push(solana_instruction::AccountMeta::new_readonly(
196 *self.target_account.key,
197 false,
198 ));
199 remaining_accounts.iter().for_each(|remaining_account| {
200 accounts.push(solana_instruction::AccountMeta {
201 pubkey: *remaining_account.0.key,
202 is_signer: remaining_account.1,
203 is_writable: remaining_account.2,
204 })
205 });
206 let mut data =
207 borsh::to_vec(&AssertUpgradeableLoaderAccountMultiInstructionData::new()).unwrap();
208 let mut args = borsh::to_vec(&self.__args).unwrap();
209 data.append(&mut args);
210
211 let instruction = solana_instruction::Instruction {
212 program_id: crate::LIGHTHOUSE_ID,
213 accounts,
214 data,
215 };
216 let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len());
217 account_infos.push(self.__program.clone());
218 account_infos.push(self.target_account.clone());
219 remaining_accounts
220 .iter()
221 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
222
223 if signers_seeds.is_empty() {
224 solana_cpi::invoke(&instruction, &account_infos)
225 } else {
226 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
227 }
228 }
229}
230
231#[derive(Clone, Debug)]
237pub struct AssertUpgradeableLoaderAccountMultiCpiBuilder<'a, 'b> {
238 instruction: Box<AssertUpgradeableLoaderAccountMultiCpiBuilderInstruction<'a, 'b>>,
239}
240
241impl<'a, 'b> AssertUpgradeableLoaderAccountMultiCpiBuilder<'a, 'b> {
242 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
243 let instruction = Box::new(AssertUpgradeableLoaderAccountMultiCpiBuilderInstruction {
244 __program: program,
245 target_account: None,
246 log_level: None,
247 assertions: None,
248 __remaining_accounts: Vec::new(),
249 });
250 Self { instruction }
251 }
252 #[inline(always)]
254 pub fn target_account(
255 &mut self,
256 target_account: &'b solana_account_info::AccountInfo<'a>,
257 ) -> &mut Self {
258 self.instruction.target_account = Some(target_account);
259 self
260 }
261 #[inline(always)]
262 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
263 self.instruction.log_level = Some(log_level);
264 self
265 }
266 #[inline(always)]
267 pub fn assertions(&mut self, assertions: UpgradeableLoaderStateAssertions) -> &mut Self {
268 self.instruction.assertions = Some(assertions);
269 self
270 }
271 #[inline(always)]
273 pub fn add_remaining_account(
274 &mut self,
275 account: &'b solana_account_info::AccountInfo<'a>,
276 is_writable: bool,
277 is_signer: bool,
278 ) -> &mut Self {
279 self.instruction
280 .__remaining_accounts
281 .push((account, is_writable, is_signer));
282 self
283 }
284 #[inline(always)]
289 pub fn add_remaining_accounts(
290 &mut self,
291 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
292 ) -> &mut Self {
293 self.instruction
294 .__remaining_accounts
295 .extend_from_slice(accounts);
296 self
297 }
298 #[inline(always)]
299 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
300 self.invoke_signed(&[])
301 }
302 #[allow(clippy::clone_on_copy)]
303 #[allow(clippy::vec_init_then_push)]
304 pub fn invoke_signed(
305 &self,
306 signers_seeds: &[&[&[u8]]],
307 ) -> solana_program_entrypoint::ProgramResult {
308 let args = AssertUpgradeableLoaderAccountMultiInstructionArgs {
309 log_level: self
310 .instruction
311 .log_level
312 .clone()
313 .expect("log_level is not set"),
314 assertions: self
315 .instruction
316 .assertions
317 .clone()
318 .expect("assertions is not set"),
319 };
320 let instruction = AssertUpgradeableLoaderAccountMultiCpi {
321 __program: self.instruction.__program,
322
323 target_account: self
324 .instruction
325 .target_account
326 .expect("target_account is not set"),
327 __args: args,
328 };
329 instruction.invoke_signed_with_remaining_accounts(
330 signers_seeds,
331 &self.instruction.__remaining_accounts,
332 )
333 }
334}
335
336#[derive(Clone, Debug)]
337struct AssertUpgradeableLoaderAccountMultiCpiBuilderInstruction<'a, 'b> {
338 __program: &'b solana_account_info::AccountInfo<'a>,
339 target_account: Option<&'b solana_account_info::AccountInfo<'a>>,
340 log_level: Option<LogLevel>,
341 assertions: Option<UpgradeableLoaderStateAssertions>,
342 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
344}