lighthouse_sol/instructions/
assert_upgradeable_loader_account.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use crate::types::{LogLevel, UpgradeableLoaderStateAssertion};
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct AssertUpgradeableLoaderAccount {
15    /// Target account to be asserted
16    pub target_account: solana_pubkey::Pubkey,
17}
18
19impl AssertUpgradeableLoaderAccount {
20    pub fn instruction(
21        &self,
22        args: AssertUpgradeableLoaderAccountInstructionArgs,
23    ) -> solana_instruction::Instruction {
24        self.instruction_with_remaining_accounts(args, &[])
25    }
26    #[allow(clippy::arithmetic_side_effects)]
27    #[allow(clippy::vec_init_then_push)]
28    pub fn instruction_with_remaining_accounts(
29        &self,
30        args: AssertUpgradeableLoaderAccountInstructionArgs,
31        remaining_accounts: &[solana_instruction::AccountMeta],
32    ) -> solana_instruction::Instruction {
33        let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
34        accounts.push(solana_instruction::AccountMeta::new_readonly(
35            self.target_account,
36            false,
37        ));
38        accounts.extend_from_slice(remaining_accounts);
39        let mut data =
40            borsh::to_vec(&AssertUpgradeableLoaderAccountInstructionData::new()).unwrap();
41        let mut args = borsh::to_vec(&args).unwrap();
42        data.append(&mut args);
43
44        solana_instruction::Instruction {
45            program_id: crate::LIGHTHOUSE_ID,
46            accounts,
47            data,
48        }
49    }
50}
51
52#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
53#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
54pub struct AssertUpgradeableLoaderAccountInstructionData {
55    discriminator: u8,
56}
57
58impl AssertUpgradeableLoaderAccountInstructionData {
59    pub fn new() -> Self {
60        Self { discriminator: 13 }
61    }
62}
63
64impl Default for AssertUpgradeableLoaderAccountInstructionData {
65    fn default() -> Self {
66        Self::new()
67    }
68}
69
70#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72pub struct AssertUpgradeableLoaderAccountInstructionArgs {
73    pub log_level: LogLevel,
74    pub assertion: UpgradeableLoaderStateAssertion,
75}
76
77/// Instruction builder for `AssertUpgradeableLoaderAccount`.
78///
79/// ### Accounts:
80///
81///   0. `[]` target_account
82#[derive(Clone, Debug, Default)]
83pub struct AssertUpgradeableLoaderAccountBuilder {
84    target_account: Option<solana_pubkey::Pubkey>,
85    log_level: Option<LogLevel>,
86    assertion: Option<UpgradeableLoaderStateAssertion>,
87    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
88}
89
90impl AssertUpgradeableLoaderAccountBuilder {
91    pub fn new() -> Self {
92        Self::default()
93    }
94    /// Target account to be asserted
95    #[inline(always)]
96    pub fn target_account(&mut self, target_account: solana_pubkey::Pubkey) -> &mut Self {
97        self.target_account = Some(target_account);
98        self
99    }
100    #[inline(always)]
101    pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
102        self.log_level = Some(log_level);
103        self
104    }
105    #[inline(always)]
106    pub fn assertion(&mut self, assertion: UpgradeableLoaderStateAssertion) -> &mut Self {
107        self.assertion = Some(assertion);
108        self
109    }
110    /// Add an additional account to the instruction.
111    #[inline(always)]
112    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
113        self.__remaining_accounts.push(account);
114        self
115    }
116    /// Add additional accounts to the instruction.
117    #[inline(always)]
118    pub fn add_remaining_accounts(
119        &mut self,
120        accounts: &[solana_instruction::AccountMeta],
121    ) -> &mut Self {
122        self.__remaining_accounts.extend_from_slice(accounts);
123        self
124    }
125    #[allow(clippy::clone_on_copy)]
126    pub fn instruction(&self) -> solana_instruction::Instruction {
127        let accounts = AssertUpgradeableLoaderAccount {
128            target_account: self.target_account.expect("target_account is not set"),
129        };
130        let args = AssertUpgradeableLoaderAccountInstructionArgs {
131            log_level: self.log_level.clone().expect("log_level is not set"),
132            assertion: self.assertion.clone().expect("assertion is not set"),
133        };
134
135        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
136    }
137}
138
139/// `assert_upgradeable_loader_account` CPI accounts.
140pub struct AssertUpgradeableLoaderAccountCpiAccounts<'a, 'b> {
141    /// Target account to be asserted
142    pub target_account: &'b solana_account_info::AccountInfo<'a>,
143}
144
145/// `assert_upgradeable_loader_account` CPI instruction.
146pub struct AssertUpgradeableLoaderAccountCpi<'a, 'b> {
147    /// The program to invoke.
148    pub __program: &'b solana_account_info::AccountInfo<'a>,
149    /// Target account to be asserted
150    pub target_account: &'b solana_account_info::AccountInfo<'a>,
151    /// The arguments for the instruction.
152    pub __args: AssertUpgradeableLoaderAccountInstructionArgs,
153}
154
155impl<'a, 'b> AssertUpgradeableLoaderAccountCpi<'a, 'b> {
156    pub fn new(
157        program: &'b solana_account_info::AccountInfo<'a>,
158        accounts: AssertUpgradeableLoaderAccountCpiAccounts<'a, 'b>,
159        args: AssertUpgradeableLoaderAccountInstructionArgs,
160    ) -> Self {
161        Self {
162            __program: program,
163            target_account: accounts.target_account,
164            __args: args,
165        }
166    }
167    #[inline(always)]
168    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
169        self.invoke_signed_with_remaining_accounts(&[], &[])
170    }
171    #[inline(always)]
172    pub fn invoke_with_remaining_accounts(
173        &self,
174        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
175    ) -> solana_program_entrypoint::ProgramResult {
176        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
177    }
178    #[inline(always)]
179    pub fn invoke_signed(
180        &self,
181        signers_seeds: &[&[&[u8]]],
182    ) -> solana_program_entrypoint::ProgramResult {
183        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
184    }
185    #[allow(clippy::arithmetic_side_effects)]
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: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
192    ) -> solana_program_entrypoint::ProgramResult {
193        let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
194        accounts.push(solana_instruction::AccountMeta::new_readonly(
195            *self.target_account.key,
196            false,
197        ));
198        remaining_accounts.iter().for_each(|remaining_account| {
199            accounts.push(solana_instruction::AccountMeta {
200                pubkey: *remaining_account.0.key,
201                is_signer: remaining_account.1,
202                is_writable: remaining_account.2,
203            })
204        });
205        let mut data =
206            borsh::to_vec(&AssertUpgradeableLoaderAccountInstructionData::new()).unwrap();
207        let mut args = borsh::to_vec(&self.__args).unwrap();
208        data.append(&mut args);
209
210        let instruction = solana_instruction::Instruction {
211            program_id: crate::LIGHTHOUSE_ID,
212            accounts,
213            data,
214        };
215        let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len());
216        account_infos.push(self.__program.clone());
217        account_infos.push(self.target_account.clone());
218        remaining_accounts
219            .iter()
220            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
221
222        if signers_seeds.is_empty() {
223            solana_cpi::invoke(&instruction, &account_infos)
224        } else {
225            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
226        }
227    }
228}
229
230/// Instruction builder for `AssertUpgradeableLoaderAccount` via CPI.
231///
232/// ### Accounts:
233///
234///   0. `[]` target_account
235#[derive(Clone, Debug)]
236pub struct AssertUpgradeableLoaderAccountCpiBuilder<'a, 'b> {
237    instruction: Box<AssertUpgradeableLoaderAccountCpiBuilderInstruction<'a, 'b>>,
238}
239
240impl<'a, 'b> AssertUpgradeableLoaderAccountCpiBuilder<'a, 'b> {
241    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
242        let instruction = Box::new(AssertUpgradeableLoaderAccountCpiBuilderInstruction {
243            __program: program,
244            target_account: None,
245            log_level: None,
246            assertion: None,
247            __remaining_accounts: Vec::new(),
248        });
249        Self { instruction }
250    }
251    /// Target account to be asserted
252    #[inline(always)]
253    pub fn target_account(
254        &mut self,
255        target_account: &'b solana_account_info::AccountInfo<'a>,
256    ) -> &mut Self {
257        self.instruction.target_account = Some(target_account);
258        self
259    }
260    #[inline(always)]
261    pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
262        self.instruction.log_level = Some(log_level);
263        self
264    }
265    #[inline(always)]
266    pub fn assertion(&mut self, assertion: UpgradeableLoaderStateAssertion) -> &mut Self {
267        self.instruction.assertion = Some(assertion);
268        self
269    }
270    /// Add an additional account to the instruction.
271    #[inline(always)]
272    pub fn add_remaining_account(
273        &mut self,
274        account: &'b solana_account_info::AccountInfo<'a>,
275        is_writable: bool,
276        is_signer: bool,
277    ) -> &mut Self {
278        self.instruction
279            .__remaining_accounts
280            .push((account, is_writable, is_signer));
281        self
282    }
283    /// Add additional accounts to the instruction.
284    ///
285    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
286    /// and a `bool` indicating whether the account is a signer or not.
287    #[inline(always)]
288    pub fn add_remaining_accounts(
289        &mut self,
290        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
291    ) -> &mut Self {
292        self.instruction
293            .__remaining_accounts
294            .extend_from_slice(accounts);
295        self
296    }
297    #[inline(always)]
298    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
299        self.invoke_signed(&[])
300    }
301    #[allow(clippy::clone_on_copy)]
302    #[allow(clippy::vec_init_then_push)]
303    pub fn invoke_signed(
304        &self,
305        signers_seeds: &[&[&[u8]]],
306    ) -> solana_program_entrypoint::ProgramResult {
307        let args = AssertUpgradeableLoaderAccountInstructionArgs {
308            log_level: self
309                .instruction
310                .log_level
311                .clone()
312                .expect("log_level is not set"),
313            assertion: self
314                .instruction
315                .assertion
316                .clone()
317                .expect("assertion is not set"),
318        };
319        let instruction = AssertUpgradeableLoaderAccountCpi {
320            __program: self.instruction.__program,
321
322            target_account: self
323                .instruction
324                .target_account
325                .expect("target_account is not set"),
326            __args: args,
327        };
328        instruction.invoke_signed_with_remaining_accounts(
329            signers_seeds,
330            &self.instruction.__remaining_accounts,
331        )
332    }
333}
334
335#[derive(Clone, Debug)]
336struct AssertUpgradeableLoaderAccountCpiBuilderInstruction<'a, 'b> {
337    __program: &'b solana_account_info::AccountInfo<'a>,
338    target_account: Option<&'b solana_account_info::AccountInfo<'a>>,
339    log_level: Option<LogLevel>,
340    assertion: Option<UpgradeableLoaderStateAssertion>,
341    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
342    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
343}