1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const CLOSE_PAYMENT_DISCRIMINATOR: u8 = 9;
12
13#[derive(Debug)]
15pub struct ClosePayment {
16
17
18 pub payer: solana_pubkey::Pubkey,
19 pub payment: solana_pubkey::Pubkey,
24
25
26 pub operator_authority: solana_pubkey::Pubkey,
27 pub operator: solana_pubkey::Pubkey,
32 pub merchant: solana_pubkey::Pubkey,
37 pub buyer: solana_pubkey::Pubkey,
42 pub merchant_operator_config: solana_pubkey::Pubkey,
47 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#[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 #[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 #[inline(always)]
183 pub fn operator(&mut self, operator: solana_pubkey::Pubkey) -> &mut Self {
184 self.operator = Some(operator);
185 self
186 }
187 #[inline(always)]
189 pub fn merchant(&mut self, merchant: solana_pubkey::Pubkey) -> &mut Self {
190 self.merchant = Some(merchant);
191 self
192 }
193 #[inline(always)]
195 pub fn buyer(&mut self, buyer: solana_pubkey::Pubkey) -> &mut Self {
196 self.buyer = Some(buyer);
197 self
198 }
199 #[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 #[inline(always)]
207 pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self {
208 self.mint = Some(mint);
209 self
210 }
211 #[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 #[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 #[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 pub struct ClosePaymentCpiAccounts<'a, 'b> {
249
250
251 pub payer: &'b solana_account_info::AccountInfo<'a>,
252 pub payment: &'b solana_account_info::AccountInfo<'a>,
257
258
259 pub operator_authority: &'b solana_account_info::AccountInfo<'a>,
260 pub operator: &'b solana_account_info::AccountInfo<'a>,
265 pub merchant: &'b solana_account_info::AccountInfo<'a>,
270 pub buyer: &'b solana_account_info::AccountInfo<'a>,
275 pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>,
280 pub mint: &'b solana_account_info::AccountInfo<'a>,
285
286
287 pub system_program: &'b solana_account_info::AccountInfo<'a>,
288 }
289
290pub struct ClosePaymentCpi<'a, 'b> {
292 pub __program: &'b solana_account_info::AccountInfo<'a>,
294
295
296 pub payer: &'b solana_account_info::AccountInfo<'a>,
297 pub payment: &'b solana_account_info::AccountInfo<'a>,
302
303
304 pub operator_authority: &'b solana_account_info::AccountInfo<'a>,
305 pub operator: &'b solana_account_info::AccountInfo<'a>,
310 pub merchant: &'b solana_account_info::AccountInfo<'a>,
315 pub buyer: &'b solana_account_info::AccountInfo<'a>,
320 pub merchant_operator_config: &'b solana_account_info::AccountInfo<'a>,
325 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#[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
592}
593