lighthouse_sol/instructions/
assert_stake_account_multi.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;
9use crate::types::hooked::StakeAccountAssertions;
10use borsh::BorshDeserialize;
11use borsh::BorshSerialize;
12
13/// Accounts.
14#[derive(Debug)]
15pub struct AssertStakeAccountMulti {
16    /// Target account to be asserted
17    pub target_account: solana_pubkey::Pubkey,
18}
19
20impl AssertStakeAccountMulti {
21    pub fn instruction(
22        &self,
23        args: AssertStakeAccountMultiInstructionArgs,
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: AssertStakeAccountMultiInstructionArgs,
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 = borsh::to_vec(&AssertStakeAccountMultiInstructionData::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 AssertStakeAccountMultiInstructionData {
55    discriminator: u8,
56}
57
58impl AssertStakeAccountMultiInstructionData {
59    pub fn new() -> Self {
60        Self { discriminator: 12 }
61    }
62}
63
64impl Default for AssertStakeAccountMultiInstructionData {
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 AssertStakeAccountMultiInstructionArgs {
73    pub log_level: LogLevel,
74    pub assertions: StakeAccountAssertions,
75}
76
77/// Instruction builder for `AssertStakeAccountMulti`.
78///
79/// ### Accounts:
80///
81///   0. `[]` target_account
82#[derive(Clone, Debug, Default)]
83pub struct AssertStakeAccountMultiBuilder {
84    target_account: Option<solana_pubkey::Pubkey>,
85    log_level: Option<LogLevel>,
86    assertions: Option<StakeAccountAssertions>,
87    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
88}
89
90impl AssertStakeAccountMultiBuilder {
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 assertions(&mut self, assertions: StakeAccountAssertions) -> &mut Self {
107        self.assertions = Some(assertions);
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 = AssertStakeAccountMulti {
128            target_account: self.target_account.expect("target_account is not set"),
129        };
130        let args = AssertStakeAccountMultiInstructionArgs {
131            log_level: self.log_level.clone().expect("log_level is not set"),
132            assertions: self.assertions.clone().expect("assertions is not set"),
133        };
134
135        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
136    }
137}
138
139/// `assert_stake_account_multi` CPI accounts.
140pub struct AssertStakeAccountMultiCpiAccounts<'a, 'b> {
141    /// Target account to be asserted
142    pub target_account: &'b solana_account_info::AccountInfo<'a>,
143}
144
145/// `assert_stake_account_multi` CPI instruction.
146pub struct AssertStakeAccountMultiCpi<'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: AssertStakeAccountMultiInstructionArgs,
153}
154
155impl<'a, 'b> AssertStakeAccountMultiCpi<'a, 'b> {
156    pub fn new(
157        program: &'b solana_account_info::AccountInfo<'a>,
158        accounts: AssertStakeAccountMultiCpiAccounts<'a, 'b>,
159        args: AssertStakeAccountMultiInstructionArgs,
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 = borsh::to_vec(&AssertStakeAccountMultiInstructionData::new()).unwrap();
206        let mut args = borsh::to_vec(&self.__args).unwrap();
207        data.append(&mut args);
208
209        let instruction = solana_instruction::Instruction {
210            program_id: crate::LIGHTHOUSE_ID,
211            accounts,
212            data,
213        };
214        let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len());
215        account_infos.push(self.__program.clone());
216        account_infos.push(self.target_account.clone());
217        remaining_accounts
218            .iter()
219            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
220
221        if signers_seeds.is_empty() {
222            solana_cpi::invoke(&instruction, &account_infos)
223        } else {
224            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
225        }
226    }
227}
228
229/// Instruction builder for `AssertStakeAccountMulti` via CPI.
230///
231/// ### Accounts:
232///
233///   0. `[]` target_account
234#[derive(Clone, Debug)]
235pub struct AssertStakeAccountMultiCpiBuilder<'a, 'b> {
236    instruction: Box<AssertStakeAccountMultiCpiBuilderInstruction<'a, 'b>>,
237}
238
239impl<'a, 'b> AssertStakeAccountMultiCpiBuilder<'a, 'b> {
240    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
241        let instruction = Box::new(AssertStakeAccountMultiCpiBuilderInstruction {
242            __program: program,
243            target_account: None,
244            log_level: None,
245            assertions: None,
246            __remaining_accounts: Vec::new(),
247        });
248        Self { instruction }
249    }
250    /// Target account to be asserted
251    #[inline(always)]
252    pub fn target_account(
253        &mut self,
254        target_account: &'b solana_account_info::AccountInfo<'a>,
255    ) -> &mut Self {
256        self.instruction.target_account = Some(target_account);
257        self
258    }
259    #[inline(always)]
260    pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
261        self.instruction.log_level = Some(log_level);
262        self
263    }
264    #[inline(always)]
265    pub fn assertions(&mut self, assertions: StakeAccountAssertions) -> &mut Self {
266        self.instruction.assertions = Some(assertions);
267        self
268    }
269    /// Add an additional account to the instruction.
270    #[inline(always)]
271    pub fn add_remaining_account(
272        &mut self,
273        account: &'b solana_account_info::AccountInfo<'a>,
274        is_writable: bool,
275        is_signer: bool,
276    ) -> &mut Self {
277        self.instruction
278            .__remaining_accounts
279            .push((account, is_writable, is_signer));
280        self
281    }
282    /// Add additional accounts to the instruction.
283    ///
284    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
285    /// and a `bool` indicating whether the account is a signer or not.
286    #[inline(always)]
287    pub fn add_remaining_accounts(
288        &mut self,
289        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
290    ) -> &mut Self {
291        self.instruction
292            .__remaining_accounts
293            .extend_from_slice(accounts);
294        self
295    }
296    #[inline(always)]
297    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
298        self.invoke_signed(&[])
299    }
300    #[allow(clippy::clone_on_copy)]
301    #[allow(clippy::vec_init_then_push)]
302    pub fn invoke_signed(
303        &self,
304        signers_seeds: &[&[&[u8]]],
305    ) -> solana_program_entrypoint::ProgramResult {
306        let args = AssertStakeAccountMultiInstructionArgs {
307            log_level: self
308                .instruction
309                .log_level
310                .clone()
311                .expect("log_level is not set"),
312            assertions: self
313                .instruction
314                .assertions
315                .clone()
316                .expect("assertions is not set"),
317        };
318        let instruction = AssertStakeAccountMultiCpi {
319            __program: self.instruction.__program,
320
321            target_account: self
322                .instruction
323                .target_account
324                .expect("target_account is not set"),
325            __args: args,
326        };
327        instruction.invoke_signed_with_remaining_accounts(
328            signers_seeds,
329            &self.instruction.__remaining_accounts,
330        )
331    }
332}
333
334#[derive(Clone, Debug)]
335struct AssertStakeAccountMultiCpiBuilderInstruction<'a, 'b> {
336    __program: &'b solana_account_info::AccountInfo<'a>,
337    target_account: Option<&'b solana_account_info::AccountInfo<'a>>,
338    log_level: Option<LogLevel>,
339    assertions: Option<StakeAccountAssertions>,
340    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
341    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
342}