Skip to main content

reflect_sdk/generated/instructions/
init_main.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 INIT_MAIN_DISCRIMINATOR: [u8; 8] = [204, 192, 140, 8, 71, 243, 223, 39];
12
13/// Accounts.
14#[derive(Debug)]
15pub struct InitMain {
16      
17              
18          pub main: solana_pubkey::Pubkey,
19          
20              
21          pub creds: solana_pubkey::Pubkey,
22          
23              
24          pub admin: solana_pubkey::Pubkey,
25          
26              
27          pub system_program: solana_pubkey::Pubkey,
28      }
29
30impl InitMain {
31  pub fn instruction(&self) -> solana_instruction::Instruction {
32    self.instruction_with_remaining_accounts(&[])
33  }
34  #[allow(clippy::arithmetic_side_effects)]
35  #[allow(clippy::vec_init_then_push)]
36  pub fn instruction_with_remaining_accounts(&self, 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.creds,
44            false
45          ));
46                                          accounts.push(solana_instruction::AccountMeta::new(
47            self.admin,
48            true
49          ));
50                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
51            self.system_program,
52            false
53          ));
54                      accounts.extend_from_slice(remaining_accounts);
55    let data = InitMainInstructionData::new().try_to_vec().unwrap();
56    
57    solana_instruction::Instruction {
58      program_id: crate::REFLECT_MAIN_ID,
59      accounts,
60      data,
61    }
62  }
63}
64
65#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67 pub struct InitMainInstructionData {
68            discriminator: [u8; 8],
69      }
70
71impl InitMainInstructionData {
72  pub fn new() -> Self {
73    Self {
74                        discriminator: [204, 192, 140, 8, 71, 243, 223, 39],
75                  }
76  }
77
78    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
79    borsh::to_vec(self)
80  }
81  }
82
83impl Default for InitMainInstructionData {
84  fn default() -> Self {
85    Self::new()
86  }
87}
88
89
90
91/// Instruction builder for `InitMain`.
92///
93/// ### Accounts:
94///
95                ///   0. `[writable]` main
96                ///   1. `[writable]` creds
97                      ///   2. `[writable, signer]` admin
98                ///   3. `[optional]` system_program (default to `11111111111111111111111111111111`)
99#[derive(Clone, Debug, Default)]
100pub struct InitMainBuilder {
101            main: Option<solana_pubkey::Pubkey>,
102                creds: Option<solana_pubkey::Pubkey>,
103                admin: Option<solana_pubkey::Pubkey>,
104                system_program: Option<solana_pubkey::Pubkey>,
105                __remaining_accounts: Vec<solana_instruction::AccountMeta>,
106}
107
108impl InitMainBuilder {
109  pub fn new() -> Self {
110    Self::default()
111  }
112            #[inline(always)]
113    pub fn main(&mut self, main: solana_pubkey::Pubkey) -> &mut Self {
114                        self.main = Some(main);
115                    self
116    }
117            #[inline(always)]
118    pub fn creds(&mut self, creds: solana_pubkey::Pubkey) -> &mut Self {
119                        self.creds = Some(creds);
120                    self
121    }
122            #[inline(always)]
123    pub fn admin(&mut self, admin: solana_pubkey::Pubkey) -> &mut Self {
124                        self.admin = Some(admin);
125                    self
126    }
127            /// `[optional account, default to '11111111111111111111111111111111']`
128#[inline(always)]
129    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
130                        self.system_program = Some(system_program);
131                    self
132    }
133            /// Add an additional account to the instruction.
134  #[inline(always)]
135  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
136    self.__remaining_accounts.push(account);
137    self
138  }
139  /// Add additional accounts to the instruction.
140  #[inline(always)]
141  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
142    self.__remaining_accounts.extend_from_slice(accounts);
143    self
144  }
145  #[allow(clippy::clone_on_copy)]
146  pub fn instruction(&self) -> solana_instruction::Instruction {
147    let accounts = InitMain {
148                              main: self.main.expect("main is not set"),
149                                        creds: self.creds.expect("creds is not set"),
150                                        admin: self.admin.expect("admin is not set"),
151                                        system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
152                      };
153    
154    accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
155  }
156}
157
158  /// `init_main` CPI accounts.
159  pub struct InitMainCpiAccounts<'a, 'b> {
160          
161                    
162              pub main: &'b solana_account_info::AccountInfo<'a>,
163                
164                    
165              pub creds: &'b solana_account_info::AccountInfo<'a>,
166                
167                    
168              pub admin: &'b solana_account_info::AccountInfo<'a>,
169                
170                    
171              pub system_program: &'b solana_account_info::AccountInfo<'a>,
172            }
173
174/// `init_main` CPI instruction.
175pub struct InitMainCpi<'a, 'b> {
176  /// The program to invoke.
177  pub __program: &'b solana_account_info::AccountInfo<'a>,
178      
179              
180          pub main: &'b solana_account_info::AccountInfo<'a>,
181          
182              
183          pub creds: &'b solana_account_info::AccountInfo<'a>,
184          
185              
186          pub admin: &'b solana_account_info::AccountInfo<'a>,
187          
188              
189          pub system_program: &'b solana_account_info::AccountInfo<'a>,
190        }
191
192impl<'a, 'b> InitMainCpi<'a, 'b> {
193  pub fn new(
194    program: &'b solana_account_info::AccountInfo<'a>,
195          accounts: InitMainCpiAccounts<'a, 'b>,
196          ) -> Self {
197    Self {
198      __program: program,
199              main: accounts.main,
200              creds: accounts.creds,
201              admin: accounts.admin,
202              system_program: accounts.system_program,
203                }
204  }
205  #[inline(always)]
206  pub fn invoke(&self) -> solana_program_error::ProgramResult {
207    self.invoke_signed_with_remaining_accounts(&[], &[])
208  }
209  #[inline(always)]
210  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
211    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
212  }
213  #[inline(always)]
214  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
215    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
216  }
217  #[allow(clippy::arithmetic_side_effects)]
218  #[allow(clippy::clone_on_copy)]
219  #[allow(clippy::vec_init_then_push)]
220  pub fn invoke_signed_with_remaining_accounts(
221    &self,
222    signers_seeds: &[&[&[u8]]],
223    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
224  ) -> solana_program_error::ProgramResult {
225    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
226                            accounts.push(solana_instruction::AccountMeta::new(
227            *self.main.key,
228            false
229          ));
230                                          accounts.push(solana_instruction::AccountMeta::new(
231            *self.creds.key,
232            false
233          ));
234                                          accounts.push(solana_instruction::AccountMeta::new(
235            *self.admin.key,
236            true
237          ));
238                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
239            *self.system_program.key,
240            false
241          ));
242                      remaining_accounts.iter().for_each(|remaining_account| {
243      accounts.push(solana_instruction::AccountMeta {
244          pubkey: *remaining_account.0.key,
245          is_signer: remaining_account.1,
246          is_writable: remaining_account.2,
247      })
248    });
249    let data = InitMainInstructionData::new().try_to_vec().unwrap();
250    
251    let instruction = solana_instruction::Instruction {
252      program_id: crate::REFLECT_MAIN_ID,
253      accounts,
254      data,
255    };
256    let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
257    account_infos.push(self.__program.clone());
258                  account_infos.push(self.main.clone());
259                        account_infos.push(self.creds.clone());
260                        account_infos.push(self.admin.clone());
261                        account_infos.push(self.system_program.clone());
262              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
263
264    if signers_seeds.is_empty() {
265      solana_cpi::invoke(&instruction, &account_infos)
266    } else {
267      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
268    }
269  }
270}
271
272/// Instruction builder for `InitMain` via CPI.
273///
274/// ### Accounts:
275///
276                ///   0. `[writable]` main
277                ///   1. `[writable]` creds
278                      ///   2. `[writable, signer]` admin
279          ///   3. `[]` system_program
280#[derive(Clone, Debug)]
281pub struct InitMainCpiBuilder<'a, 'b> {
282  instruction: Box<InitMainCpiBuilderInstruction<'a, 'b>>,
283}
284
285impl<'a, 'b> InitMainCpiBuilder<'a, 'b> {
286  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
287    let instruction = Box::new(InitMainCpiBuilderInstruction {
288      __program: program,
289              main: None,
290              creds: None,
291              admin: None,
292              system_program: None,
293                                __remaining_accounts: Vec::new(),
294    });
295    Self { instruction }
296  }
297      #[inline(always)]
298    pub fn main(&mut self, main: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
299                        self.instruction.main = Some(main);
300                    self
301    }
302      #[inline(always)]
303    pub fn creds(&mut self, creds: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
304                        self.instruction.creds = Some(creds);
305                    self
306    }
307      #[inline(always)]
308    pub fn admin(&mut self, admin: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
309                        self.instruction.admin = Some(admin);
310                    self
311    }
312      #[inline(always)]
313    pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
314                        self.instruction.system_program = Some(system_program);
315                    self
316    }
317            /// Add an additional account to the instruction.
318  #[inline(always)]
319  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
320    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
321    self
322  }
323  /// Add additional accounts to the instruction.
324  ///
325  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
326  /// and a `bool` indicating whether the account is a signer or not.
327  #[inline(always)]
328  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
329    self.instruction.__remaining_accounts.extend_from_slice(accounts);
330    self
331  }
332  #[inline(always)]
333  pub fn invoke(&self) -> solana_program_error::ProgramResult {
334    self.invoke_signed(&[])
335  }
336  #[allow(clippy::clone_on_copy)]
337  #[allow(clippy::vec_init_then_push)]
338  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
339        let instruction = InitMainCpi {
340        __program: self.instruction.__program,
341                  
342          main: self.instruction.main.expect("main is not set"),
343                  
344          creds: self.instruction.creds.expect("creds is not set"),
345                  
346          admin: self.instruction.admin.expect("admin is not set"),
347                  
348          system_program: self.instruction.system_program.expect("system_program is not set"),
349                    };
350    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
351  }
352}
353
354#[derive(Clone, Debug)]
355struct InitMainCpiBuilderInstruction<'a, 'b> {
356  __program: &'b solana_account_info::AccountInfo<'a>,
357            main: Option<&'b solana_account_info::AccountInfo<'a>>,
358                creds: Option<&'b solana_account_info::AccountInfo<'a>>,
359                admin: Option<&'b solana_account_info::AccountInfo<'a>>,
360                system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
361                /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
362  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
363}
364