Skip to main content

satrush_client/generated/instructions/
select_epoch_winner.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 borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const SELECT_EPOCH_WINNER_DISCRIMINATOR: [u8; 8] = [222, 36, 211, 175, 4, 220, 2, 251];
12
13/// Accounts.
14#[derive(Debug)]
15pub struct SelectEpochWinner {
16      
17              
18          pub authority: solana_address::Address,
19          
20              
21          pub satrush_config: solana_address::Address,
22          
23              
24          pub epoch_vault: solana_address::Address,
25          
26              
27          pub epoch_vault_iteration: solana_address::Address,
28          
29              
30          pub epoch_vault_page: solana_address::Address,
31          
32              
33          pub event_authority: solana_address::Address,
34          
35              
36          pub program: solana_address::Address,
37      }
38
39impl SelectEpochWinner {
40  pub fn instruction(&self, args: SelectEpochWinnerInstructionArgs) -> solana_instruction::Instruction {
41    self.instruction_with_remaining_accounts(args, &[])
42  }
43  #[allow(clippy::arithmetic_side_effects)]
44  #[allow(clippy::vec_init_then_push)]
45  pub fn instruction_with_remaining_accounts(&self, args: SelectEpochWinnerInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
46    let mut accounts = Vec::with_capacity(7+ remaining_accounts.len());
47                            accounts.push(solana_instruction::AccountMeta::new_readonly(
48            self.authority,
49            true
50          ));
51                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
52            self.satrush_config,
53            false
54          ));
55                                          accounts.push(solana_instruction::AccountMeta::new(
56            self.epoch_vault,
57            false
58          ));
59                                          accounts.push(solana_instruction::AccountMeta::new(
60            self.epoch_vault_iteration,
61            false
62          ));
63                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
64            self.epoch_vault_page,
65            false
66          ));
67                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
68            self.event_authority,
69            false
70          ));
71                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
72            self.program,
73            false
74          ));
75                      accounts.extend_from_slice(remaining_accounts);
76    let mut data = SelectEpochWinnerInstructionData::new().try_to_vec().unwrap();
77          let mut args = args.try_to_vec().unwrap();
78      data.append(&mut args);
79    
80    solana_instruction::Instruction {
81      program_id: crate::SATRUSH_ID,
82      accounts,
83      data,
84    }
85  }
86}
87
88#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
89 pub struct SelectEpochWinnerInstructionData {
90            discriminator: [u8; 8],
91            }
92
93impl SelectEpochWinnerInstructionData {
94  pub fn new() -> Self {
95    Self {
96                        discriminator: [222, 36, 211, 175, 4, 220, 2, 251],
97                                }
98  }
99
100    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
101    borsh::to_vec(self)
102  }
103  }
104
105impl Default for SelectEpochWinnerInstructionData {
106  fn default() -> Self {
107    Self::new()
108  }
109}
110
111#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
112 pub struct SelectEpochWinnerInstructionArgs {
113                  pub page_index: u16,
114      }
115
116impl SelectEpochWinnerInstructionArgs {
117  pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
118    borsh::to_vec(self)
119  }
120}
121
122
123/// Instruction builder for `SelectEpochWinner`.
124///
125/// ### Accounts:
126///
127                ///   0. `[signer]` authority
128          ///   1. `[]` satrush_config
129                ///   2. `[writable]` epoch_vault
130                ///   3. `[writable]` epoch_vault_iteration
131          ///   4. `[]` epoch_vault_page
132          ///   5. `[]` event_authority
133          ///   6. `[]` program
134#[derive(Clone, Debug, Default)]
135pub struct SelectEpochWinnerBuilder {
136            authority: Option<solana_address::Address>,
137                satrush_config: Option<solana_address::Address>,
138                epoch_vault: Option<solana_address::Address>,
139                epoch_vault_iteration: Option<solana_address::Address>,
140                epoch_vault_page: Option<solana_address::Address>,
141                event_authority: Option<solana_address::Address>,
142                program: Option<solana_address::Address>,
143                        page_index: Option<u16>,
144        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
145}
146
147impl SelectEpochWinnerBuilder {
148  pub fn new() -> Self {
149    Self::default()
150  }
151            #[inline(always)]
152    pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
153                        self.authority = Some(authority);
154                    self
155    }
156            #[inline(always)]
157    pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
158                        self.satrush_config = Some(satrush_config);
159                    self
160    }
161            #[inline(always)]
162    pub fn epoch_vault(&mut self, epoch_vault: solana_address::Address) -> &mut Self {
163                        self.epoch_vault = Some(epoch_vault);
164                    self
165    }
166            #[inline(always)]
167    pub fn epoch_vault_iteration(&mut self, epoch_vault_iteration: solana_address::Address) -> &mut Self {
168                        self.epoch_vault_iteration = Some(epoch_vault_iteration);
169                    self
170    }
171            #[inline(always)]
172    pub fn epoch_vault_page(&mut self, epoch_vault_page: solana_address::Address) -> &mut Self {
173                        self.epoch_vault_page = Some(epoch_vault_page);
174                    self
175    }
176            #[inline(always)]
177    pub fn event_authority(&mut self, event_authority: solana_address::Address) -> &mut Self {
178                        self.event_authority = Some(event_authority);
179                    self
180    }
181            #[inline(always)]
182    pub fn program(&mut self, program: solana_address::Address) -> &mut Self {
183                        self.program = Some(program);
184                    self
185    }
186                    #[inline(always)]
187      pub fn page_index(&mut self, page_index: u16) -> &mut Self {
188        self.page_index = Some(page_index);
189        self
190      }
191        /// Add an additional account to the instruction.
192  #[inline(always)]
193  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
194    self.__remaining_accounts.push(account);
195    self
196  }
197  /// Add additional accounts to the instruction.
198  #[inline(always)]
199  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
200    self.__remaining_accounts.extend_from_slice(accounts);
201    self
202  }
203  #[allow(clippy::clone_on_copy)]
204  pub fn instruction(&self) -> solana_instruction::Instruction {
205    let accounts = SelectEpochWinner {
206                              authority: self.authority.expect("authority is not set"),
207                                        satrush_config: self.satrush_config.expect("satrush_config is not set"),
208                                        epoch_vault: self.epoch_vault.expect("epoch_vault is not set"),
209                                        epoch_vault_iteration: self.epoch_vault_iteration.expect("epoch_vault_iteration is not set"),
210                                        epoch_vault_page: self.epoch_vault_page.expect("epoch_vault_page is not set"),
211                                        event_authority: self.event_authority.expect("event_authority is not set"),
212                                        program: self.program.expect("program is not set"),
213                      };
214          let args = SelectEpochWinnerInstructionArgs {
215                                                              page_index: self.page_index.clone().expect("page_index is not set"),
216                                    };
217    
218    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
219  }
220}
221
222  /// `select_epoch_winner` CPI accounts.
223  pub struct SelectEpochWinnerCpiAccounts<'a, 'b> {
224          
225                    
226              pub authority: &'b solana_account_info::AccountInfo<'a>,
227                
228                    
229              pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
230                
231                    
232              pub epoch_vault: &'b solana_account_info::AccountInfo<'a>,
233                
234                    
235              pub epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>,
236                
237                    
238              pub epoch_vault_page: &'b solana_account_info::AccountInfo<'a>,
239                
240                    
241              pub event_authority: &'b solana_account_info::AccountInfo<'a>,
242                
243                    
244              pub program: &'b solana_account_info::AccountInfo<'a>,
245            }
246
247/// `select_epoch_winner` CPI instruction.
248pub struct SelectEpochWinnerCpi<'a, 'b> {
249  /// The program to invoke.
250  pub __program: &'b solana_account_info::AccountInfo<'a>,
251      
252              
253          pub authority: &'b solana_account_info::AccountInfo<'a>,
254          
255              
256          pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
257          
258              
259          pub epoch_vault: &'b solana_account_info::AccountInfo<'a>,
260          
261              
262          pub epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>,
263          
264              
265          pub epoch_vault_page: &'b solana_account_info::AccountInfo<'a>,
266          
267              
268          pub event_authority: &'b solana_account_info::AccountInfo<'a>,
269          
270              
271          pub program: &'b solana_account_info::AccountInfo<'a>,
272            /// The arguments for the instruction.
273    pub __args: SelectEpochWinnerInstructionArgs,
274  }
275
276impl<'a, 'b> SelectEpochWinnerCpi<'a, 'b> {
277  pub fn new(
278    program: &'b solana_account_info::AccountInfo<'a>,
279          accounts: SelectEpochWinnerCpiAccounts<'a, 'b>,
280              args: SelectEpochWinnerInstructionArgs,
281      ) -> Self {
282    Self {
283      __program: program,
284              authority: accounts.authority,
285              satrush_config: accounts.satrush_config,
286              epoch_vault: accounts.epoch_vault,
287              epoch_vault_iteration: accounts.epoch_vault_iteration,
288              epoch_vault_page: accounts.epoch_vault_page,
289              event_authority: accounts.event_authority,
290              program: accounts.program,
291                    __args: args,
292          }
293  }
294  #[inline(always)]
295  pub fn invoke(&self) -> solana_program_error::ProgramResult {
296    self.invoke_signed_with_remaining_accounts(&[], &[])
297  }
298  #[inline(always)]
299  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
300    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
301  }
302  #[inline(always)]
303  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
304    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
305  }
306  #[allow(clippy::arithmetic_side_effects)]
307  #[allow(clippy::clone_on_copy)]
308  #[allow(clippy::vec_init_then_push)]
309  pub fn invoke_signed_with_remaining_accounts(
310    &self,
311    signers_seeds: &[&[&[u8]]],
312    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
313  ) -> solana_program_error::ProgramResult {
314    let mut accounts = Vec::with_capacity(7+ remaining_accounts.len());
315                            accounts.push(solana_instruction::AccountMeta::new_readonly(
316            *self.authority.key,
317            true
318          ));
319                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
320            *self.satrush_config.key,
321            false
322          ));
323                                          accounts.push(solana_instruction::AccountMeta::new(
324            *self.epoch_vault.key,
325            false
326          ));
327                                          accounts.push(solana_instruction::AccountMeta::new(
328            *self.epoch_vault_iteration.key,
329            false
330          ));
331                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
332            *self.epoch_vault_page.key,
333            false
334          ));
335                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
336            *self.event_authority.key,
337            false
338          ));
339                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
340            *self.program.key,
341            false
342          ));
343                      remaining_accounts.iter().for_each(|remaining_account| {
344      accounts.push(solana_instruction::AccountMeta {
345          pubkey: *remaining_account.0.key,
346          is_signer: remaining_account.1,
347          is_writable: remaining_account.2,
348      })
349    });
350    let mut data = SelectEpochWinnerInstructionData::new().try_to_vec().unwrap();
351          let mut args = self.__args.try_to_vec().unwrap();
352      data.append(&mut args);
353    
354    let instruction = solana_instruction::Instruction {
355      program_id: crate::SATRUSH_ID,
356      accounts,
357      data,
358    };
359    let mut account_infos = Vec::with_capacity(8 + remaining_accounts.len());
360    account_infos.push(self.__program.clone());
361                  account_infos.push(self.authority.clone());
362                        account_infos.push(self.satrush_config.clone());
363                        account_infos.push(self.epoch_vault.clone());
364                        account_infos.push(self.epoch_vault_iteration.clone());
365                        account_infos.push(self.epoch_vault_page.clone());
366                        account_infos.push(self.event_authority.clone());
367                        account_infos.push(self.program.clone());
368              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
369
370    if signers_seeds.is_empty() {
371      solana_cpi::invoke(&instruction, &account_infos)
372    } else {
373      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
374    }
375  }
376}
377
378/// Instruction builder for `SelectEpochWinner` via CPI.
379///
380/// ### Accounts:
381///
382                ///   0. `[signer]` authority
383          ///   1. `[]` satrush_config
384                ///   2. `[writable]` epoch_vault
385                ///   3. `[writable]` epoch_vault_iteration
386          ///   4. `[]` epoch_vault_page
387          ///   5. `[]` event_authority
388          ///   6. `[]` program
389#[derive(Clone, Debug)]
390pub struct SelectEpochWinnerCpiBuilder<'a, 'b> {
391  instruction: Box<SelectEpochWinnerCpiBuilderInstruction<'a, 'b>>,
392}
393
394impl<'a, 'b> SelectEpochWinnerCpiBuilder<'a, 'b> {
395  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
396    let instruction = Box::new(SelectEpochWinnerCpiBuilderInstruction {
397      __program: program,
398              authority: None,
399              satrush_config: None,
400              epoch_vault: None,
401              epoch_vault_iteration: None,
402              epoch_vault_page: None,
403              event_authority: None,
404              program: None,
405                                            page_index: None,
406                    __remaining_accounts: Vec::new(),
407    });
408    Self { instruction }
409  }
410      #[inline(always)]
411    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
412                        self.instruction.authority = Some(authority);
413                    self
414    }
415      #[inline(always)]
416    pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
417                        self.instruction.satrush_config = Some(satrush_config);
418                    self
419    }
420      #[inline(always)]
421    pub fn epoch_vault(&mut self, epoch_vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
422                        self.instruction.epoch_vault = Some(epoch_vault);
423                    self
424    }
425      #[inline(always)]
426    pub fn epoch_vault_iteration(&mut self, epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
427                        self.instruction.epoch_vault_iteration = Some(epoch_vault_iteration);
428                    self
429    }
430      #[inline(always)]
431    pub fn epoch_vault_page(&mut self, epoch_vault_page: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
432                        self.instruction.epoch_vault_page = Some(epoch_vault_page);
433                    self
434    }
435      #[inline(always)]
436    pub fn event_authority(&mut self, event_authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
437                        self.instruction.event_authority = Some(event_authority);
438                    self
439    }
440      #[inline(always)]
441    pub fn program(&mut self, program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
442                        self.instruction.program = Some(program);
443                    self
444    }
445                    #[inline(always)]
446      pub fn page_index(&mut self, page_index: u16) -> &mut Self {
447        self.instruction.page_index = Some(page_index);
448        self
449      }
450        /// Add an additional account to the instruction.
451  #[inline(always)]
452  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
453    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
454    self
455  }
456  /// Add additional accounts to the instruction.
457  ///
458  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
459  /// and a `bool` indicating whether the account is a signer or not.
460  #[inline(always)]
461  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
462    self.instruction.__remaining_accounts.extend_from_slice(accounts);
463    self
464  }
465  #[inline(always)]
466  pub fn invoke(&self) -> solana_program_error::ProgramResult {
467    self.invoke_signed(&[])
468  }
469  #[allow(clippy::clone_on_copy)]
470  #[allow(clippy::vec_init_then_push)]
471  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
472          let args = SelectEpochWinnerInstructionArgs {
473                                                              page_index: self.instruction.page_index.clone().expect("page_index is not set"),
474                                    };
475        let instruction = SelectEpochWinnerCpi {
476        __program: self.instruction.__program,
477                  
478          authority: self.instruction.authority.expect("authority is not set"),
479                  
480          satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
481                  
482          epoch_vault: self.instruction.epoch_vault.expect("epoch_vault is not set"),
483                  
484          epoch_vault_iteration: self.instruction.epoch_vault_iteration.expect("epoch_vault_iteration is not set"),
485                  
486          epoch_vault_page: self.instruction.epoch_vault_page.expect("epoch_vault_page is not set"),
487                  
488          event_authority: self.instruction.event_authority.expect("event_authority is not set"),
489                  
490          program: self.instruction.program.expect("program is not set"),
491                          __args: args,
492            };
493    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
494  }
495}
496
497#[derive(Clone, Debug)]
498struct SelectEpochWinnerCpiBuilderInstruction<'a, 'b> {
499  __program: &'b solana_account_info::AccountInfo<'a>,
500            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
501                satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
502                epoch_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
503                epoch_vault_iteration: Option<&'b solana_account_info::AccountInfo<'a>>,
504                epoch_vault_page: Option<&'b solana_account_info::AccountInfo<'a>>,
505                event_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
506                program: Option<&'b solana_account_info::AccountInfo<'a>>,
507                        page_index: Option<u16>,
508        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
509  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
510}
511