Skip to main content

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