lighthouse_sdk/generated/instructions/
assert_upgradeable_loader_account.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! [https://github.com/metaplex-foundation/kinobi]
6//!
7
8use crate::generated::types::LogLevel;
9use crate::generated::types::UpgradeableLoaderStateAssertion;
10use borsh::BorshDeserialize;
11use borsh::BorshSerialize;
12
13/// Accounts.
14pub struct AssertUpgradeableLoaderAccount {
15    /// Target account to be asserted
16    pub target_account: solana_program::pubkey::Pubkey,
17}
18
19impl AssertUpgradeableLoaderAccount {
20    pub fn instruction(
21        &self,
22        args: AssertUpgradeableLoaderAccountInstructionArgs,
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: AssertUpgradeableLoaderAccountInstructionArgs,
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 = AssertUpgradeableLoaderAccountInstructionData::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 AssertUpgradeableLoaderAccountInstructionData {
54    discriminator: u8,
55}
56
57impl AssertUpgradeableLoaderAccountInstructionData {
58    pub fn new() -> Self {
59        Self { discriminator: 13 }
60    }
61}
62
63#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
64#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
65pub struct AssertUpgradeableLoaderAccountInstructionArgs {
66    pub log_level: LogLevel,
67    pub assertion: UpgradeableLoaderStateAssertion,
68}
69
70/// Instruction builder for `AssertUpgradeableLoaderAccount`.
71///
72/// ### Accounts:
73///
74///   0. `[]` target_account
75#[derive(Clone, Debug, Default)]
76pub struct AssertUpgradeableLoaderAccountBuilder {
77    target_account: Option<solana_program::pubkey::Pubkey>,
78    log_level: Option<LogLevel>,
79    assertion: Option<UpgradeableLoaderStateAssertion>,
80    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
81}
82
83impl AssertUpgradeableLoaderAccountBuilder {
84    pub fn new() -> Self {
85        Self::default()
86    }
87    /// Target account to be asserted
88    #[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    /// `[optional argument, defaults to 'LogLevel::Silent']`
94    #[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: UpgradeableLoaderStateAssertion) -> &mut Self {
101        self.assertion = Some(assertion);
102        self
103    }
104    /// Add an aditional account to the instruction.
105    #[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    /// Add additional accounts to the instruction.
114    #[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 = AssertUpgradeableLoaderAccount {
125            target_account: self.target_account.expect("target_account is not set"),
126        };
127        let args = AssertUpgradeableLoaderAccountInstructionArgs {
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
136/// `assert_upgradeable_loader_account` CPI accounts.
137pub struct AssertUpgradeableLoaderAccountCpiAccounts<'a, 'b> {
138    /// Target account to be asserted
139    pub target_account: &'b solana_program::account_info::AccountInfo<'a>,
140}
141
142/// `assert_upgradeable_loader_account` CPI instruction.
143pub struct AssertUpgradeableLoaderAccountCpi<'a, 'b> {
144    /// The program to invoke.
145    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
146    /// Target account to be asserted
147    pub target_account: &'b solana_program::account_info::AccountInfo<'a>,
148    /// The arguments for the instruction.
149    pub __args: AssertUpgradeableLoaderAccountInstructionArgs,
150}
151
152impl<'a, 'b> AssertUpgradeableLoaderAccountCpi<'a, 'b> {
153    pub fn new(
154        program: &'b solana_program::account_info::AccountInfo<'a>,
155        accounts: AssertUpgradeableLoaderAccountCpiAccounts<'a, 'b>,
156        args: AssertUpgradeableLoaderAccountInstructionArgs,
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 = AssertUpgradeableLoaderAccountInstructionData::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/// Instruction builder for `AssertUpgradeableLoaderAccount` via CPI.
236///
237/// ### Accounts:
238///
239///   0. `[]` target_account
240#[derive(Clone, Debug)]
241pub struct AssertUpgradeableLoaderAccountCpiBuilder<'a, 'b> {
242    instruction: Box<AssertUpgradeableLoaderAccountCpiBuilderInstruction<'a, 'b>>,
243}
244
245impl<'a, 'b> AssertUpgradeableLoaderAccountCpiBuilder<'a, 'b> {
246    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
247        let instruction = Box::new(AssertUpgradeableLoaderAccountCpiBuilderInstruction {
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    /// Target account to be asserted
257    #[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    /// `[optional argument, defaults to 'LogLevel::Silent']`
266    #[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: UpgradeableLoaderStateAssertion) -> &mut Self {
273        self.instruction.assertion = Some(assertion);
274        self
275    }
276    /// Add an additional account to the instruction.
277    #[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    /// Add additional accounts to the instruction.
290    ///
291    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
292    /// and a `bool` indicating whether the account is a signer or not.
293    #[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 = AssertUpgradeableLoaderAccountInstructionArgs {
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 = AssertUpgradeableLoaderAccountCpi {
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 AssertUpgradeableLoaderAccountCpiBuilderInstruction<'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<UpgradeableLoaderStateAssertion>,
351    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
352    __remaining_accounts: Vec<(
353        &'b solana_program::account_info::AccountInfo<'a>,
354        bool,
355        bool,
356    )>,
357}