6 namespace org { namespace ldk { namespace structs {
9 * Some information provided on receipt of payment depends on whether the payment received is a
10 * spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
12 public class PaymentPurpose : CommonBase {
13 protected PaymentPurpose(object _dummy, long ptr) : base(ptr) { }
15 if (ptr != 0) { bindings.PaymentPurpose_free(ptr); }
18 internal static PaymentPurpose constr_from_ptr(long ptr) {
19 long raw_ty = bindings.LDKPaymentPurpose_ty_from_ptr(ptr);
21 case 0: return new PaymentPurpose_InvoicePayment(ptr);
22 case 1: return new PaymentPurpose_SpontaneousPayment(ptr);
24 throw new ArgumentException("Impossible enum variant");
28 /** A PaymentPurpose of type InvoicePayment */
29 public class PaymentPurpose_InvoicePayment : PaymentPurpose {
31 * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
32 * [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
33 * [`ChannelManager::claim_funds`].
35 * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
36 * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
38 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
40 public byte[] payment_preimage;
42 * The \"payment secret\". This authenticates the sender to the recipient, preventing a
43 * number of deanonymization attacks during the routing process.
44 * It is provided here for your reference, however its accuracy is enforced directly by
45 * [`ChannelManager`] using the values you previously provided to
46 * [`ChannelManager::create_inbound_payment`] or
47 * [`ChannelManager::create_inbound_payment_for_hash`].
49 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
50 * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
51 * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
53 public byte[] payment_secret;
54 internal PaymentPurpose_InvoicePayment(long ptr) : base(null, ptr) {
55 this.payment_preimage = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_preimage(ptr);
56 this.payment_secret = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_secret(ptr);
59 /** A PaymentPurpose of type SpontaneousPayment */
60 public class PaymentPurpose_SpontaneousPayment : PaymentPurpose {
61 public byte[] spontaneous_payment;
62 internal PaymentPurpose_SpontaneousPayment(long ptr) : base(null, ptr) {
63 this.spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr);
66 internal long clone_ptr() {
67 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
73 * Creates a copy of the PaymentPurpose
75 public PaymentPurpose clone() {
76 long ret = bindings.PaymentPurpose_clone(this.ptr);
78 if (ret >= 0 && ret <= 4096) { return null; }
79 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
80 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
85 * Utility method to constructs a new InvoicePayment-variant PaymentPurpose
87 public static PaymentPurpose invoice_payment(byte[] payment_preimage, byte[] payment_secret) {
88 long ret = bindings.PaymentPurpose_invoice_payment(InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_secret, 32));
89 GC.KeepAlive(payment_preimage);
90 GC.KeepAlive(payment_secret);
91 if (ret >= 0 && ret <= 4096) { return null; }
92 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
93 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
98 * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
100 public static PaymentPurpose spontaneous_payment(byte[] a) {
101 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32));
103 if (ret >= 0 && ret <= 4096) { return null; }
104 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
105 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
110 * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
112 public byte[] write() {
113 byte[] ret = bindings.PaymentPurpose_write(this.ptr);
119 * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
121 public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
122 long ret = bindings.PaymentPurpose_read(ser);
124 if (ret >= 0 && ret <= 4096) { return null; }
125 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);