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