lighthouse_sol/instructions/
assert_sysvar_clock.rs1use crate::types::{LogLevel, SysvarClockAssertion};
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12#[derive(Debug)]
14pub struct AssertSysvarClock {}
15
16impl AssertSysvarClock {
17 pub fn instruction(
18 &self,
19 args: AssertSysvarClockInstructionArgs,
20 ) -> solana_instruction::Instruction {
21 self.instruction_with_remaining_accounts(args, &[])
22 }
23 #[allow(clippy::arithmetic_side_effects)]
24 #[allow(clippy::vec_init_then_push)]
25 pub fn instruction_with_remaining_accounts(
26 &self,
27 args: AssertSysvarClockInstructionArgs,
28 remaining_accounts: &[solana_instruction::AccountMeta],
29 ) -> solana_instruction::Instruction {
30 let mut accounts = Vec::with_capacity(remaining_accounts.len());
31 accounts.extend_from_slice(remaining_accounts);
32 let mut data = borsh::to_vec(&AssertSysvarClockInstructionData::new()).unwrap();
33 let mut args = borsh::to_vec(&args).unwrap();
34 data.append(&mut args);
35
36 solana_instruction::Instruction {
37 program_id: crate::LIGHTHOUSE_ID,
38 accounts,
39 data,
40 }
41 }
42}
43
44#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
45#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
46pub struct AssertSysvarClockInstructionData {
47 discriminator: u8,
48}
49
50impl AssertSysvarClockInstructionData {
51 pub fn new() -> Self {
52 Self { discriminator: 15 }
53 }
54}
55
56impl Default for AssertSysvarClockInstructionData {
57 fn default() -> Self {
58 Self::new()
59 }
60}
61
62#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
63#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
64pub struct AssertSysvarClockInstructionArgs {
65 pub log_level: LogLevel,
66 pub assertion: SysvarClockAssertion,
67}
68
69#[derive(Clone, Debug, Default)]
74pub struct AssertSysvarClockBuilder {
75 log_level: Option<LogLevel>,
76 assertion: Option<SysvarClockAssertion>,
77 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
78}
79
80impl AssertSysvarClockBuilder {
81 pub fn new() -> Self {
82 Self::default()
83 }
84 #[inline(always)]
85 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
86 self.log_level = Some(log_level);
87 self
88 }
89 #[inline(always)]
90 pub fn assertion(&mut self, assertion: SysvarClockAssertion) -> &mut Self {
91 self.assertion = Some(assertion);
92 self
93 }
94 #[inline(always)]
96 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
97 self.__remaining_accounts.push(account);
98 self
99 }
100 #[inline(always)]
102 pub fn add_remaining_accounts(
103 &mut self,
104 accounts: &[solana_instruction::AccountMeta],
105 ) -> &mut Self {
106 self.__remaining_accounts.extend_from_slice(accounts);
107 self
108 }
109 #[allow(clippy::clone_on_copy)]
110 pub fn instruction(&self) -> solana_instruction::Instruction {
111 let accounts = AssertSysvarClock {};
112 let args = AssertSysvarClockInstructionArgs {
113 log_level: self.log_level.clone().expect("log_level is not set"),
114 assertion: self.assertion.clone().expect("assertion is not set"),
115 };
116
117 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
118 }
119}
120
121pub struct AssertSysvarClockCpi<'a, 'b> {
123 pub __program: &'b solana_account_info::AccountInfo<'a>,
125 pub __args: AssertSysvarClockInstructionArgs,
127}
128
129impl<'a, 'b> AssertSysvarClockCpi<'a, 'b> {
130 pub fn new(
131 program: &'b solana_account_info::AccountInfo<'a>,
132 args: AssertSysvarClockInstructionArgs,
133 ) -> Self {
134 Self {
135 __program: program,
136 __args: args,
137 }
138 }
139 #[inline(always)]
140 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
141 self.invoke_signed_with_remaining_accounts(&[], &[])
142 }
143 #[inline(always)]
144 pub fn invoke_with_remaining_accounts(
145 &self,
146 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
147 ) -> solana_program_entrypoint::ProgramResult {
148 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
149 }
150 #[inline(always)]
151 pub fn invoke_signed(
152 &self,
153 signers_seeds: &[&[&[u8]]],
154 ) -> solana_program_entrypoint::ProgramResult {
155 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
156 }
157 #[allow(clippy::arithmetic_side_effects)]
158 #[allow(clippy::clone_on_copy)]
159 #[allow(clippy::vec_init_then_push)]
160 pub fn invoke_signed_with_remaining_accounts(
161 &self,
162 signers_seeds: &[&[&[u8]]],
163 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
164 ) -> solana_program_entrypoint::ProgramResult {
165 let mut accounts = Vec::with_capacity(remaining_accounts.len());
166 remaining_accounts.iter().for_each(|remaining_account| {
167 accounts.push(solana_instruction::AccountMeta {
168 pubkey: *remaining_account.0.key,
169 is_signer: remaining_account.1,
170 is_writable: remaining_account.2,
171 })
172 });
173 let mut data = borsh::to_vec(&AssertSysvarClockInstructionData::new()).unwrap();
174 let mut args = borsh::to_vec(&self.__args).unwrap();
175 data.append(&mut args);
176
177 let instruction = solana_instruction::Instruction {
178 program_id: crate::LIGHTHOUSE_ID,
179 accounts,
180 data,
181 };
182 let mut account_infos = Vec::with_capacity(1 + remaining_accounts.len());
183 account_infos.push(self.__program.clone());
184 remaining_accounts
185 .iter()
186 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
187
188 if signers_seeds.is_empty() {
189 solana_cpi::invoke(&instruction, &account_infos)
190 } else {
191 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
192 }
193 }
194}
195
196#[derive(Clone, Debug)]
201pub struct AssertSysvarClockCpiBuilder<'a, 'b> {
202 instruction: Box<AssertSysvarClockCpiBuilderInstruction<'a, 'b>>,
203}
204
205impl<'a, 'b> AssertSysvarClockCpiBuilder<'a, 'b> {
206 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
207 let instruction = Box::new(AssertSysvarClockCpiBuilderInstruction {
208 __program: program,
209 log_level: None,
210 assertion: None,
211 __remaining_accounts: Vec::new(),
212 });
213 Self { instruction }
214 }
215 #[inline(always)]
216 pub fn log_level(&mut self, log_level: LogLevel) -> &mut Self {
217 self.instruction.log_level = Some(log_level);
218 self
219 }
220 #[inline(always)]
221 pub fn assertion(&mut self, assertion: SysvarClockAssertion) -> &mut Self {
222 self.instruction.assertion = Some(assertion);
223 self
224 }
225 #[inline(always)]
227 pub fn add_remaining_account(
228 &mut self,
229 account: &'b solana_account_info::AccountInfo<'a>,
230 is_writable: bool,
231 is_signer: bool,
232 ) -> &mut Self {
233 self.instruction
234 .__remaining_accounts
235 .push((account, is_writable, is_signer));
236 self
237 }
238 #[inline(always)]
243 pub fn add_remaining_accounts(
244 &mut self,
245 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
246 ) -> &mut Self {
247 self.instruction
248 .__remaining_accounts
249 .extend_from_slice(accounts);
250 self
251 }
252 #[inline(always)]
253 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
254 self.invoke_signed(&[])
255 }
256 #[allow(clippy::clone_on_copy)]
257 #[allow(clippy::vec_init_then_push)]
258 pub fn invoke_signed(
259 &self,
260 signers_seeds: &[&[&[u8]]],
261 ) -> solana_program_entrypoint::ProgramResult {
262 let args = AssertSysvarClockInstructionArgs {
263 log_level: self
264 .instruction
265 .log_level
266 .clone()
267 .expect("log_level is not set"),
268 assertion: self
269 .instruction
270 .assertion
271 .clone()
272 .expect("assertion is not set"),
273 };
274 let instruction = AssertSysvarClockCpi {
275 __program: self.instruction.__program,
276 __args: args,
277 };
278 instruction.invoke_signed_with_remaining_accounts(
279 signers_seeds,
280 &self.instruction.__remaining_accounts,
281 )
282 }
283}
284
285#[derive(Clone, Debug)]
286struct AssertSysvarClockCpiBuilderInstruction<'a, 'b> {
287 __program: &'b solana_account_info::AccountInfo<'a>,
288 log_level: Option<LogLevel>,
289 assertion: Option<SysvarClockAssertion>,
290 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
292}