2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class PaymentPurpose extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.PaymentPurpose_free(this.ptr); }
11 static constr_from_ptr(ptr: number): PaymentPurpose {
12 const raw_val: bindings.LDKPaymentPurpose = bindings.LDKPaymentPurpose_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKPaymentPurpose.InvoicePayment) {
14 return new InvoicePayment(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKPaymentPurpose.SpontaneousPayment) {
17 return new SpontaneousPayment(this.ptr, raw_val);
19 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
23 export class InvoicePayment extends PaymentPurpose {
24 public payment_preimage: Uint8Array;
25 public payment_secret: Uint8Array;
26 public user_payment_id: number;
27 private constructor(ptr: number, obj: bindings.LDKPaymentPurpose.InvoicePayment) {
29 this.payment_preimage = obj.payment_preimage;
30 this.payment_secret = obj.payment_secret;
31 this.user_payment_id = obj.user_payment_id;
34 export class SpontaneousPayment extends PaymentPurpose {
35 public spontaneous_payment: Uint8Array;
36 private constructor(ptr: number, obj: bindings.LDKPaymentPurpose.SpontaneousPayment) {
38 this.spontaneous_payment = obj.spontaneous_payment;
41 public PaymentPurpose clone() {
42 number ret = bindings.PaymentPurpose_clone(this.ptr);
43 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
44 ret_hu_conv.ptrs_to.add(this);
48 public static PaymentPurpose constructor_invoice_payment(Uint8Array payment_preimage, Uint8Array payment_secret, number user_payment_id) {
49 number ret = bindings.PaymentPurpose_invoice_payment(payment_preimage, payment_secret, user_payment_id);
50 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
51 ret_hu_conv.ptrs_to.add(ret_hu_conv);
55 public static PaymentPurpose constructor_spontaneous_payment(Uint8Array a) {
56 number ret = bindings.PaymentPurpose_spontaneous_payment(a);
57 PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
58 ret_hu_conv.ptrs_to.add(ret_hu_conv);