Skip to main content

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