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 public Option_ThirtyTwoBytesZ payment_preimage;
40 * The \"payment secret\". This authenticates the sender to the recipient, preventing a
41 * number of deanonymization attacks during the routing process.
42 * It is provided here for your reference, however its accuracy is enforced directly by
43 * [`ChannelManager`] using the values you previously provided to
44 * [`ChannelManager::create_inbound_payment`] or
45 * [`ChannelManager::create_inbound_payment_for_hash`].
47 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
48 * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
49 * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
51 public byte[] payment_secret;
52 internal PaymentPurpose_InvoicePayment(long ptr) : base(null, ptr) {
53 long payment_preimage = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_preimage(ptr);
54 org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
55 if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
56 this.payment_preimage = payment_preimage_hu_conv;
57 long payment_secret = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_secret(ptr);
58 byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret);
59 this.payment_secret = payment_secret_conv;
62 /** A PaymentPurpose of type SpontaneousPayment */
63 public class PaymentPurpose_SpontaneousPayment : PaymentPurpose {
64 public byte[] spontaneous_payment;
65 internal PaymentPurpose_SpontaneousPayment(long ptr) : base(null, ptr) {
66 long spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr);
67 byte[] spontaneous_payment_conv = InternalUtils.decodeUint8Array(spontaneous_payment);
68 this.spontaneous_payment = spontaneous_payment_conv;
71 internal long clone_ptr() {
72 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
78 * Creates a copy of the PaymentPurpose
80 public PaymentPurpose clone() {
81 long ret = bindings.PaymentPurpose_clone(this.ptr);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
85 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
90 * Utility method to constructs a new InvoicePayment-variant PaymentPurpose
92 public static PaymentPurpose invoice_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret) {
93 long ret = bindings.PaymentPurpose_invoice_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)));
94 GC.KeepAlive(payment_preimage);
95 GC.KeepAlive(payment_secret);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
98 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
99 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
104 * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
106 public static PaymentPurpose spontaneous_payment(byte[] a) {
107 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a, 32)));
109 if (ret >= 0 && ret <= 4096) { return null; }
110 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
116 * Checks if two PaymentPurposes contain equal inner contents.
117 * This ignores pointers and is_owned flags and looks at the values in fields.
119 public bool eq(org.ldk.structs.PaymentPurpose b) {
120 bool ret = bindings.PaymentPurpose_eq(this.ptr, b == null ? 0 : b.ptr);
126 public override bool Equals(object o) {
127 if (!(o is PaymentPurpose)) return false;
128 return this.eq((PaymentPurpose)o);
131 * Returns the preimage for this payment, if it is known.
133 public Option_ThirtyTwoBytesZ preimage() {
134 long ret = bindings.PaymentPurpose_preimage(this.ptr);
136 if (ret >= 0 && ret <= 4096) { return null; }
137 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
138 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
143 * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
145 public byte[] write() {
146 long ret = bindings.PaymentPurpose_write(this.ptr);
148 if (ret >= 0 && ret <= 4096) { return null; }
149 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
154 * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
156 public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
157 long ret = bindings.PaymentPurpose_read(InternalUtils.encodeUint8Array(ser));
159 if (ret >= 0 && ret <= 4096) { return null; }
160 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);