1use 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_PROTOCOL_DISCRIMINATOR: [u8; 8] = [48, 71, 125, 156, 34, 88, 138, 156];
15
16#[derive(Debug)]
18pub struct UpdateActionRoleProtocol {
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 admin_permissions: solana_pubkey::Pubkey,
31 }
32
33impl UpdateActionRoleProtocol {
34 pub fn instruction(&self, args: UpdateActionRoleProtocolInstructionArgs) -> solana_instruction::Instruction {
35 self.instruction_with_remaining_accounts(args, &[])
36 }
37 #[allow(clippy::arithmetic_side_effects)]
38 #[allow(clippy::vec_init_then_push)]
39 pub fn instruction_with_remaining_accounts(&self, args: UpdateActionRoleProtocolInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
40 let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
41 accounts.push(solana_instruction::AccountMeta::new(
42 self.main,
43 false
44 ));
45 accounts.push(solana_instruction::AccountMeta::new(
46 self.admin,
47 true
48 ));
49 accounts.push(solana_instruction::AccountMeta::new_readonly(
50 self.system_program,
51 false
52 ));
53 accounts.push(solana_instruction::AccountMeta::new(
54 self.admin_permissions,
55 false
56 ));
57 accounts.extend_from_slice(remaining_accounts);
58 let mut data = UpdateActionRoleProtocolInstructionData::new().try_to_vec().unwrap();
59 let mut args = args.try_to_vec().unwrap();
60 data.append(&mut args);
61
62 solana_instruction::Instruction {
63 program_id: crate::REFLECT_MAIN_ID,
64 accounts,
65 data,
66 }
67 }
68}
69
70#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72 pub struct UpdateActionRoleProtocolInstructionData {
73 discriminator: [u8; 8],
74 }
75
76impl UpdateActionRoleProtocolInstructionData {
77 pub fn new() -> Self {
78 Self {
79 discriminator: [48, 71, 125, 156, 34, 88, 138, 156],
80 }
81 }
82
83 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
84 borsh::to_vec(self)
85 }
86 }
87
88impl Default for UpdateActionRoleProtocolInstructionData {
89 fn default() -> Self {
90 Self::new()
91 }
92}
93
94#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
95#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
96 pub struct UpdateActionRoleProtocolInstructionArgs {
97 pub action: Action,
98 pub role: Role,
99 pub update: Update,
100 }
101
102impl UpdateActionRoleProtocolInstructionArgs {
103 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
104 borsh::to_vec(self)
105 }
106}
107
108
109#[derive(Clone, Debug, Default)]
118pub struct UpdateActionRoleProtocolBuilder {
119 main: Option<solana_pubkey::Pubkey>,
120 admin: Option<solana_pubkey::Pubkey>,
121 system_program: Option<solana_pubkey::Pubkey>,
122 admin_permissions: Option<solana_pubkey::Pubkey>,
123 action: Option<Action>,
124 role: Option<Role>,
125 update: Option<Update>,
126 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
127}
128
129impl UpdateActionRoleProtocolBuilder {
130 pub fn new() -> Self {
131 Self::default()
132 }
133 #[inline(always)]
134 pub fn main(&mut self, main: solana_pubkey::Pubkey) -> &mut Self {
135 self.main = Some(main);
136 self
137 }
138 #[inline(always)]
139 pub fn admin(&mut self, admin: solana_pubkey::Pubkey) -> &mut Self {
140 self.admin = Some(admin);
141 self
142 }
143 #[inline(always)]
145 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
146 self.system_program = Some(system_program);
147 self
148 }
149 #[inline(always)]
150 pub fn admin_permissions(&mut self, admin_permissions: solana_pubkey::Pubkey) -> &mut Self {
151 self.admin_permissions = Some(admin_permissions);
152 self
153 }
154 #[inline(always)]
155 pub fn action(&mut self, action: Action) -> &mut Self {
156 self.action = Some(action);
157 self
158 }
159 #[inline(always)]
160 pub fn role(&mut self, role: Role) -> &mut Self {
161 self.role = Some(role);
162 self
163 }
164 #[inline(always)]
165 pub fn update(&mut self, update: Update) -> &mut Self {
166 self.update = Some(update);
167 self
168 }
169 #[inline(always)]
171 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
172 self.__remaining_accounts.push(account);
173 self
174 }
175 #[inline(always)]
177 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
178 self.__remaining_accounts.extend_from_slice(accounts);
179 self
180 }
181 #[allow(clippy::clone_on_copy)]
182 pub fn instruction(&self) -> solana_instruction::Instruction {
183 let accounts = UpdateActionRoleProtocol {
184 main: self.main.expect("main is not set"),
185 admin: self.admin.expect("admin is not set"),
186 system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
187 admin_permissions: self.admin_permissions.expect("admin_permissions is not set"),
188 };
189 let args = UpdateActionRoleProtocolInstructionArgs {
190 action: self.action.clone().expect("action is not set"),
191 role: self.role.clone().expect("role is not set"),
192 update: self.update.clone().expect("update is not set"),
193 };
194
195 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
196 }
197}
198
199 pub struct UpdateActionRoleProtocolCpiAccounts<'a, 'b> {
201
202
203 pub main: &'b solana_account_info::AccountInfo<'a>,
204
205
206 pub admin: &'b solana_account_info::AccountInfo<'a>,
207
208
209 pub system_program: &'b solana_account_info::AccountInfo<'a>,
210
211
212 pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
213 }
214
215pub struct UpdateActionRoleProtocolCpi<'a, 'b> {
217 pub __program: &'b solana_account_info::AccountInfo<'a>,
219
220
221 pub main: &'b solana_account_info::AccountInfo<'a>,
222
223
224 pub admin: &'b solana_account_info::AccountInfo<'a>,
225
226
227 pub system_program: &'b solana_account_info::AccountInfo<'a>,
228
229
230 pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
231 pub __args: UpdateActionRoleProtocolInstructionArgs,
233 }
234
235impl<'a, 'b> UpdateActionRoleProtocolCpi<'a, 'b> {
236 pub fn new(
237 program: &'b solana_account_info::AccountInfo<'a>,
238 accounts: UpdateActionRoleProtocolCpiAccounts<'a, 'b>,
239 args: UpdateActionRoleProtocolInstructionArgs,
240 ) -> Self {
241 Self {
242 __program: program,
243 main: accounts.main,
244 admin: accounts.admin,
245 system_program: accounts.system_program,
246 admin_permissions: accounts.admin_permissions,
247 __args: args,
248 }
249 }
250 #[inline(always)]
251 pub fn invoke(&self) -> solana_program_error::ProgramResult {
252 self.invoke_signed_with_remaining_accounts(&[], &[])
253 }
254 #[inline(always)]
255 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
256 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
257 }
258 #[inline(always)]
259 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
260 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
261 }
262 #[allow(clippy::arithmetic_side_effects)]
263 #[allow(clippy::clone_on_copy)]
264 #[allow(clippy::vec_init_then_push)]
265 pub fn invoke_signed_with_remaining_accounts(
266 &self,
267 signers_seeds: &[&[&[u8]]],
268 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
269 ) -> solana_program_error::ProgramResult {
270 let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
271 accounts.push(solana_instruction::AccountMeta::new(
272 *self.main.key,
273 false
274 ));
275 accounts.push(solana_instruction::AccountMeta::new(
276 *self.admin.key,
277 true
278 ));
279 accounts.push(solana_instruction::AccountMeta::new_readonly(
280 *self.system_program.key,
281 false
282 ));
283 accounts.push(solana_instruction::AccountMeta::new(
284 *self.admin_permissions.key,
285 false
286 ));
287 remaining_accounts.iter().for_each(|remaining_account| {
288 accounts.push(solana_instruction::AccountMeta {
289 pubkey: *remaining_account.0.key,
290 is_signer: remaining_account.1,
291 is_writable: remaining_account.2,
292 })
293 });
294 let mut data = UpdateActionRoleProtocolInstructionData::new().try_to_vec().unwrap();
295 let mut args = self.__args.try_to_vec().unwrap();
296 data.append(&mut args);
297
298 let instruction = solana_instruction::Instruction {
299 program_id: crate::REFLECT_MAIN_ID,
300 accounts,
301 data,
302 };
303 let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
304 account_infos.push(self.__program.clone());
305 account_infos.push(self.main.clone());
306 account_infos.push(self.admin.clone());
307 account_infos.push(self.system_program.clone());
308 account_infos.push(self.admin_permissions.clone());
309 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
310
311 if signers_seeds.is_empty() {
312 solana_cpi::invoke(&instruction, &account_infos)
313 } else {
314 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
315 }
316 }
317}
318
319#[derive(Clone, Debug)]
328pub struct UpdateActionRoleProtocolCpiBuilder<'a, 'b> {
329 instruction: Box<UpdateActionRoleProtocolCpiBuilderInstruction<'a, 'b>>,
330}
331
332impl<'a, 'b> UpdateActionRoleProtocolCpiBuilder<'a, 'b> {
333 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
334 let instruction = Box::new(UpdateActionRoleProtocolCpiBuilderInstruction {
335 __program: program,
336 main: None,
337 admin: None,
338 system_program: None,
339 admin_permissions: None,
340 action: None,
341 role: None,
342 update: None,
343 __remaining_accounts: Vec::new(),
344 });
345 Self { instruction }
346 }
347 #[inline(always)]
348 pub fn main(&mut self, main: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
349 self.instruction.main = Some(main);
350 self
351 }
352 #[inline(always)]
353 pub fn admin(&mut self, admin: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
354 self.instruction.admin = Some(admin);
355 self
356 }
357 #[inline(always)]
358 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
359 self.instruction.system_program = Some(system_program);
360 self
361 }
362 #[inline(always)]
363 pub fn admin_permissions(&mut self, admin_permissions: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
364 self.instruction.admin_permissions = Some(admin_permissions);
365 self
366 }
367 #[inline(always)]
368 pub fn action(&mut self, action: Action) -> &mut Self {
369 self.instruction.action = Some(action);
370 self
371 }
372 #[inline(always)]
373 pub fn role(&mut self, role: Role) -> &mut Self {
374 self.instruction.role = Some(role);
375 self
376 }
377 #[inline(always)]
378 pub fn update(&mut self, update: Update) -> &mut Self {
379 self.instruction.update = Some(update);
380 self
381 }
382 #[inline(always)]
384 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
385 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
386 self
387 }
388 #[inline(always)]
393 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
394 self.instruction.__remaining_accounts.extend_from_slice(accounts);
395 self
396 }
397 #[inline(always)]
398 pub fn invoke(&self) -> solana_program_error::ProgramResult {
399 self.invoke_signed(&[])
400 }
401 #[allow(clippy::clone_on_copy)]
402 #[allow(clippy::vec_init_then_push)]
403 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
404 let args = UpdateActionRoleProtocolInstructionArgs {
405 action: self.instruction.action.clone().expect("action is not set"),
406 role: self.instruction.role.clone().expect("role is not set"),
407 update: self.instruction.update.clone().expect("update is not set"),
408 };
409 let instruction = UpdateActionRoleProtocolCpi {
410 __program: self.instruction.__program,
411
412 main: self.instruction.main.expect("main is not set"),
413
414 admin: self.instruction.admin.expect("admin is not set"),
415
416 system_program: self.instruction.system_program.expect("system_program is not set"),
417
418 admin_permissions: self.instruction.admin_permissions.expect("admin_permissions is not set"),
419 __args: args,
420 };
421 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
422 }
423}
424
425#[derive(Clone, Debug)]
426struct UpdateActionRoleProtocolCpiBuilderInstruction<'a, 'b> {
427 __program: &'b solana_account_info::AccountInfo<'a>,
428 main: Option<&'b solana_account_info::AccountInfo<'a>>,
429 admin: Option<&'b solana_account_info::AccountInfo<'a>>,
430 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
431 admin_permissions: Option<&'b solana_account_info::AccountInfo<'a>>,
432 action: Option<Action>,
433 role: Option<Role>,
434 update: Option<Update>,
435 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
437}
438