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