Skip to main content

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