1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const FREEZE_PROGRAM_DISCRIMINATOR: [u8; 8] = [197, 134, 244, 37, 49, 38, 23, 79];
12
13#[derive(Debug)]
15pub struct FreezeProgram {
16
17
18 pub main: solana_pubkey::Pubkey,
19
20
21 pub admin: solana_pubkey::Pubkey,
22
23
24 pub system_program: solana_pubkey::Pubkey,
25
26
27 pub admin_permissions: solana_pubkey::Pubkey,
28 }
29
30impl FreezeProgram {
31 pub fn instruction(&self, args: FreezeProgramInstructionArgs) -> solana_instruction::Instruction {
32 self.instruction_with_remaining_accounts(args, &[])
33 }
34 #[allow(clippy::arithmetic_side_effects)]
35 #[allow(clippy::vec_init_then_push)]
36 pub fn instruction_with_remaining_accounts(&self, args: FreezeProgramInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
37 let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
38 accounts.push(solana_instruction::AccountMeta::new(
39 self.main,
40 false
41 ));
42 accounts.push(solana_instruction::AccountMeta::new(
43 self.admin,
44 true
45 ));
46 accounts.push(solana_instruction::AccountMeta::new_readonly(
47 self.system_program,
48 false
49 ));
50 accounts.push(solana_instruction::AccountMeta::new(
51 self.admin_permissions,
52 false
53 ));
54 accounts.extend_from_slice(remaining_accounts);
55 let mut data = FreezeProgramInstructionData::new().try_to_vec().unwrap();
56 let mut args = args.try_to_vec().unwrap();
57 data.append(&mut args);
58
59 solana_instruction::Instruction {
60 program_id: crate::REFLECT_MAIN_ID,
61 accounts,
62 data,
63 }
64 }
65}
66
67#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
68#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
69 pub struct FreezeProgramInstructionData {
70 discriminator: [u8; 8],
71 }
72
73impl FreezeProgramInstructionData {
74 pub fn new() -> Self {
75 Self {
76 discriminator: [197, 134, 244, 37, 49, 38, 23, 79],
77 }
78 }
79
80 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
81 borsh::to_vec(self)
82 }
83 }
84
85impl Default for FreezeProgramInstructionData {
86 fn default() -> Self {
87 Self::new()
88 }
89}
90
91#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93 pub struct FreezeProgramInstructionArgs {
94 pub freeze: bool,
95 pub program_index: u8,
96 }
97
98impl FreezeProgramInstructionArgs {
99 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
100 borsh::to_vec(self)
101 }
102}
103
104
105#[derive(Clone, Debug, Default)]
114pub struct FreezeProgramBuilder {
115 main: Option<solana_pubkey::Pubkey>,
116 admin: Option<solana_pubkey::Pubkey>,
117 system_program: Option<solana_pubkey::Pubkey>,
118 admin_permissions: Option<solana_pubkey::Pubkey>,
119 freeze: Option<bool>,
120 program_index: Option<u8>,
121 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
122}
123
124impl FreezeProgramBuilder {
125 pub fn new() -> Self {
126 Self::default()
127 }
128 #[inline(always)]
129 pub fn main(&mut self, main: solana_pubkey::Pubkey) -> &mut Self {
130 self.main = Some(main);
131 self
132 }
133 #[inline(always)]
134 pub fn admin(&mut self, admin: solana_pubkey::Pubkey) -> &mut Self {
135 self.admin = Some(admin);
136 self
137 }
138 #[inline(always)]
140 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
141 self.system_program = Some(system_program);
142 self
143 }
144 #[inline(always)]
145 pub fn admin_permissions(&mut self, admin_permissions: solana_pubkey::Pubkey) -> &mut Self {
146 self.admin_permissions = Some(admin_permissions);
147 self
148 }
149 #[inline(always)]
150 pub fn freeze(&mut self, freeze: bool) -> &mut Self {
151 self.freeze = Some(freeze);
152 self
153 }
154 #[inline(always)]
155 pub fn program_index(&mut self, program_index: u8) -> &mut Self {
156 self.program_index = Some(program_index);
157 self
158 }
159 #[inline(always)]
161 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
162 self.__remaining_accounts.push(account);
163 self
164 }
165 #[inline(always)]
167 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
168 self.__remaining_accounts.extend_from_slice(accounts);
169 self
170 }
171 #[allow(clippy::clone_on_copy)]
172 pub fn instruction(&self) -> solana_instruction::Instruction {
173 let accounts = FreezeProgram {
174 main: self.main.expect("main is not set"),
175 admin: self.admin.expect("admin is not set"),
176 system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
177 admin_permissions: self.admin_permissions.expect("admin_permissions is not set"),
178 };
179 let args = FreezeProgramInstructionArgs {
180 freeze: self.freeze.clone().expect("freeze is not set"),
181 program_index: self.program_index.clone().expect("program_index is not set"),
182 };
183
184 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
185 }
186}
187
188 pub struct FreezeProgramCpiAccounts<'a, 'b> {
190
191
192 pub main: &'b solana_account_info::AccountInfo<'a>,
193
194
195 pub admin: &'b solana_account_info::AccountInfo<'a>,
196
197
198 pub system_program: &'b solana_account_info::AccountInfo<'a>,
199
200
201 pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
202 }
203
204pub struct FreezeProgramCpi<'a, 'b> {
206 pub __program: &'b solana_account_info::AccountInfo<'a>,
208
209
210 pub main: &'b solana_account_info::AccountInfo<'a>,
211
212
213 pub admin: &'b solana_account_info::AccountInfo<'a>,
214
215
216 pub system_program: &'b solana_account_info::AccountInfo<'a>,
217
218
219 pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
220 pub __args: FreezeProgramInstructionArgs,
222 }
223
224impl<'a, 'b> FreezeProgramCpi<'a, 'b> {
225 pub fn new(
226 program: &'b solana_account_info::AccountInfo<'a>,
227 accounts: FreezeProgramCpiAccounts<'a, 'b>,
228 args: FreezeProgramInstructionArgs,
229 ) -> Self {
230 Self {
231 __program: program,
232 main: accounts.main,
233 admin: accounts.admin,
234 system_program: accounts.system_program,
235 admin_permissions: accounts.admin_permissions,
236 __args: args,
237 }
238 }
239 #[inline(always)]
240 pub fn invoke(&self) -> solana_program_error::ProgramResult {
241 self.invoke_signed_with_remaining_accounts(&[], &[])
242 }
243 #[inline(always)]
244 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
245 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
246 }
247 #[inline(always)]
248 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
249 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
250 }
251 #[allow(clippy::arithmetic_side_effects)]
252 #[allow(clippy::clone_on_copy)]
253 #[allow(clippy::vec_init_then_push)]
254 pub fn invoke_signed_with_remaining_accounts(
255 &self,
256 signers_seeds: &[&[&[u8]]],
257 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
258 ) -> solana_program_error::ProgramResult {
259 let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
260 accounts.push(solana_instruction::AccountMeta::new(
261 *self.main.key,
262 false
263 ));
264 accounts.push(solana_instruction::AccountMeta::new(
265 *self.admin.key,
266 true
267 ));
268 accounts.push(solana_instruction::AccountMeta::new_readonly(
269 *self.system_program.key,
270 false
271 ));
272 accounts.push(solana_instruction::AccountMeta::new(
273 *self.admin_permissions.key,
274 false
275 ));
276 remaining_accounts.iter().for_each(|remaining_account| {
277 accounts.push(solana_instruction::AccountMeta {
278 pubkey: *remaining_account.0.key,
279 is_signer: remaining_account.1,
280 is_writable: remaining_account.2,
281 })
282 });
283 let mut data = FreezeProgramInstructionData::new().try_to_vec().unwrap();
284 let mut args = self.__args.try_to_vec().unwrap();
285 data.append(&mut args);
286
287 let instruction = solana_instruction::Instruction {
288 program_id: crate::REFLECT_MAIN_ID,
289 accounts,
290 data,
291 };
292 let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
293 account_infos.push(self.__program.clone());
294 account_infos.push(self.main.clone());
295 account_infos.push(self.admin.clone());
296 account_infos.push(self.system_program.clone());
297 account_infos.push(self.admin_permissions.clone());
298 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
299
300 if signers_seeds.is_empty() {
301 solana_cpi::invoke(&instruction, &account_infos)
302 } else {
303 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
304 }
305 }
306}
307
308#[derive(Clone, Debug)]
317pub struct FreezeProgramCpiBuilder<'a, 'b> {
318 instruction: Box<FreezeProgramCpiBuilderInstruction<'a, 'b>>,
319}
320
321impl<'a, 'b> FreezeProgramCpiBuilder<'a, 'b> {
322 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
323 let instruction = Box::new(FreezeProgramCpiBuilderInstruction {
324 __program: program,
325 main: None,
326 admin: None,
327 system_program: None,
328 admin_permissions: None,
329 freeze: None,
330 program_index: None,
331 __remaining_accounts: Vec::new(),
332 });
333 Self { instruction }
334 }
335 #[inline(always)]
336 pub fn main(&mut self, main: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
337 self.instruction.main = Some(main);
338 self
339 }
340 #[inline(always)]
341 pub fn admin(&mut self, admin: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
342 self.instruction.admin = Some(admin);
343 self
344 }
345 #[inline(always)]
346 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
347 self.instruction.system_program = Some(system_program);
348 self
349 }
350 #[inline(always)]
351 pub fn admin_permissions(&mut self, admin_permissions: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
352 self.instruction.admin_permissions = Some(admin_permissions);
353 self
354 }
355 #[inline(always)]
356 pub fn freeze(&mut self, freeze: bool) -> &mut Self {
357 self.instruction.freeze = Some(freeze);
358 self
359 }
360 #[inline(always)]
361 pub fn program_index(&mut self, program_index: u8) -> &mut Self {
362 self.instruction.program_index = Some(program_index);
363 self
364 }
365 #[inline(always)]
367 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
368 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
369 self
370 }
371 #[inline(always)]
376 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
377 self.instruction.__remaining_accounts.extend_from_slice(accounts);
378 self
379 }
380 #[inline(always)]
381 pub fn invoke(&self) -> solana_program_error::ProgramResult {
382 self.invoke_signed(&[])
383 }
384 #[allow(clippy::clone_on_copy)]
385 #[allow(clippy::vec_init_then_push)]
386 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
387 let args = FreezeProgramInstructionArgs {
388 freeze: self.instruction.freeze.clone().expect("freeze is not set"),
389 program_index: self.instruction.program_index.clone().expect("program_index is not set"),
390 };
391 let instruction = FreezeProgramCpi {
392 __program: self.instruction.__program,
393
394 main: self.instruction.main.expect("main is not set"),
395
396 admin: self.instruction.admin.expect("admin is not set"),
397
398 system_program: self.instruction.system_program.expect("system_program is not set"),
399
400 admin_permissions: self.instruction.admin_permissions.expect("admin_permissions is not set"),
401 __args: args,
402 };
403 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
404 }
405}
406
407#[derive(Clone, Debug)]
408struct FreezeProgramCpiBuilderInstruction<'a, 'b> {
409 __program: &'b solana_account_info::AccountInfo<'a>,
410 main: Option<&'b solana_account_info::AccountInfo<'a>>,
411 admin: Option<&'b solana_account_info::AccountInfo<'a>>,
412 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
413 admin_permissions: Option<&'b solana_account_info::AccountInfo<'a>>,
414 freeze: Option<bool>,
415 program_index: Option<u8>,
416 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
418}
419