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