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