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_Bolt11InvoicePayment(ptr);
22 case 1: return new PaymentPurpose_Bolt12OfferPayment(ptr);
23 case 2: return new PaymentPurpose_Bolt12RefundPayment(ptr);
24 case 3: return new PaymentPurpose_SpontaneousPayment(ptr);
26 throw new ArgumentException("Impossible enum variant");
30 /** A PaymentPurpose of type Bolt11InvoicePayment */
31 public class PaymentPurpose_Bolt11InvoicePayment : PaymentPurpose {
33 * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
34 * [`ChannelManager::create_inbound_payment`]. When handling [`Event::PaymentClaimable`],
35 * this can be passed directly to [`ChannelManager::claim_funds`] to claim the payment. No
36 * action is needed when seen in [`Event::PaymentClaimed`].
38 * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
39 * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
41 public Option_ThirtyTwoBytesZ payment_preimage;
43 * The \"payment secret\". This authenticates the sender to the recipient, preventing a
44 * number of deanonymization attacks during the routing process.
45 * It is provided here for your reference, however its accuracy is enforced directly by
46 * [`ChannelManager`] using the values you previously provided to
47 * [`ChannelManager::create_inbound_payment`] or
48 * [`ChannelManager::create_inbound_payment_for_hash`].
50 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
51 * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
52 * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
54 public byte[] payment_secret;
55 internal PaymentPurpose_Bolt11InvoicePayment(long ptr) : base(null, ptr) {
56 long payment_preimage = bindings.LDKPaymentPurpose_Bolt11InvoicePayment_get_payment_preimage(ptr);
57 org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
58 if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
59 this.payment_preimage = payment_preimage_hu_conv;
60 long payment_secret = bindings.LDKPaymentPurpose_Bolt11InvoicePayment_get_payment_secret(ptr);
61 byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret);
62 this.payment_secret = payment_secret_conv;
65 /** A PaymentPurpose of type Bolt12OfferPayment */
66 public class PaymentPurpose_Bolt12OfferPayment : PaymentPurpose {
68 * The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
69 * passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
70 * when seen in [`Event::PaymentClaimed`].
72 * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
74 public Option_ThirtyTwoBytesZ payment_preimage;
76 * The secret used to authenticate the sender to the recipient, preventing a number of
77 * de-anonymization attacks while routing a payment.
79 * See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
81 public byte[] payment_secret;
83 * The context of the payment such as information about the corresponding [`Offer`] and
86 * [`Offer`]: crate::offers::offer::Offer
87 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
89 public Bolt12OfferContext payment_context;
90 internal PaymentPurpose_Bolt12OfferPayment(long ptr) : base(null, ptr) {
91 long payment_preimage = bindings.LDKPaymentPurpose_Bolt12OfferPayment_get_payment_preimage(ptr);
92 org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
93 if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
94 this.payment_preimage = payment_preimage_hu_conv;
95 long payment_secret = bindings.LDKPaymentPurpose_Bolt12OfferPayment_get_payment_secret(ptr);
96 byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret);
97 this.payment_secret = payment_secret_conv;
98 long payment_context = bindings.LDKPaymentPurpose_Bolt12OfferPayment_get_payment_context(ptr);
99 org.ldk.structs.Bolt12OfferContext payment_context_hu_conv = null; if (payment_context < 0 || payment_context > 4096) { payment_context_hu_conv = new org.ldk.structs.Bolt12OfferContext(null, payment_context); }
100 if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.AddLast(this); };
101 this.payment_context = payment_context_hu_conv;
104 /** A PaymentPurpose of type Bolt12RefundPayment */
105 public class PaymentPurpose_Bolt12RefundPayment : PaymentPurpose {
107 * The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
108 * passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
109 * when seen in [`Event::PaymentClaimed`].
111 * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
113 public Option_ThirtyTwoBytesZ payment_preimage;
115 * The secret used to authenticate the sender to the recipient, preventing a number of
116 * de-anonymization attacks while routing a payment.
118 * See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
120 public byte[] payment_secret;
122 * The context of the payment such as information about the corresponding [`Refund`].
124 * [`Refund`]: crate::offers::refund::Refund
126 public Bolt12RefundContext payment_context;
127 internal PaymentPurpose_Bolt12RefundPayment(long ptr) : base(null, ptr) {
128 long payment_preimage = bindings.LDKPaymentPurpose_Bolt12RefundPayment_get_payment_preimage(ptr);
129 org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
130 if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); };
131 this.payment_preimage = payment_preimage_hu_conv;
132 long payment_secret = bindings.LDKPaymentPurpose_Bolt12RefundPayment_get_payment_secret(ptr);
133 byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret);
134 this.payment_secret = payment_secret_conv;
135 long payment_context = bindings.LDKPaymentPurpose_Bolt12RefundPayment_get_payment_context(ptr);
136 org.ldk.structs.Bolt12RefundContext payment_context_hu_conv = null; if (payment_context < 0 || payment_context > 4096) { payment_context_hu_conv = new org.ldk.structs.Bolt12RefundContext(null, payment_context); }
137 if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.AddLast(this); };
138 this.payment_context = payment_context_hu_conv;
141 /** A PaymentPurpose of type SpontaneousPayment */
142 public class PaymentPurpose_SpontaneousPayment : PaymentPurpose {
143 public byte[] spontaneous_payment;
144 internal PaymentPurpose_SpontaneousPayment(long ptr) : base(null, ptr) {
145 long spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr);
146 byte[] spontaneous_payment_conv = InternalUtils.decodeUint8Array(spontaneous_payment);
147 this.spontaneous_payment = spontaneous_payment_conv;
150 internal long clone_ptr() {
151 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
157 * Creates a copy of the PaymentPurpose
159 public PaymentPurpose clone() {
160 long ret = bindings.PaymentPurpose_clone(this.ptr);
162 if (ret >= 0 && ret <= 4096) { return null; }
163 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
164 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
169 * Utility method to constructs a new Bolt11InvoicePayment-variant PaymentPurpose
171 public static PaymentPurpose bolt11_invoice_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret) {
172 long ret = bindings.PaymentPurpose_bolt11_invoice_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)));
173 GC.KeepAlive(payment_preimage);
174 GC.KeepAlive(payment_secret);
175 if (ret >= 0 && ret <= 4096) { return null; }
176 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
177 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
178 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
183 * Utility method to constructs a new Bolt12OfferPayment-variant PaymentPurpose
185 public static PaymentPurpose bolt12_offer_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret, org.ldk.structs.Bolt12OfferContext payment_context) {
186 long ret = bindings.PaymentPurpose_bolt12_offer_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)), payment_context.ptr);
187 GC.KeepAlive(payment_preimage);
188 GC.KeepAlive(payment_secret);
189 GC.KeepAlive(payment_context);
190 if (ret >= 0 && ret <= 4096) { return null; }
191 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
192 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
193 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
194 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_context); };
199 * Utility method to constructs a new Bolt12RefundPayment-variant PaymentPurpose
201 public static PaymentPurpose bolt12_refund_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret, org.ldk.structs.Bolt12RefundContext payment_context) {
202 long ret = bindings.PaymentPurpose_bolt12_refund_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)), payment_context.ptr);
203 GC.KeepAlive(payment_preimage);
204 GC.KeepAlive(payment_secret);
205 GC.KeepAlive(payment_context);
206 if (ret >= 0 && ret <= 4096) { return null; }
207 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
208 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
209 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); };
210 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_context); };
215 * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
217 public static PaymentPurpose spontaneous_payment(byte[] a) {
218 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a, 32)));
220 if (ret >= 0 && ret <= 4096) { return null; }
221 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
222 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
227 * Checks if two PaymentPurposes contain equal inner contents.
228 * This ignores pointers and is_owned flags and looks at the values in fields.
230 public bool eq(org.ldk.structs.PaymentPurpose b) {
231 bool ret = bindings.PaymentPurpose_eq(this.ptr, b.ptr);
237 public override bool Equals(object o) {
238 if (!(o is PaymentPurpose)) return false;
239 return this.eq((PaymentPurpose)o);
242 * Returns the preimage for this payment, if it is known.
244 public Option_ThirtyTwoBytesZ preimage() {
245 long ret = bindings.PaymentPurpose_preimage(this.ptr);
247 if (ret >= 0 && ret <= 4096) { return null; }
248 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
249 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
254 * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
256 public byte[] write() {
257 long ret = bindings.PaymentPurpose_write(this.ptr);
259 if (ret >= 0 && ret <= 4096) { return null; }
260 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
265 * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
267 public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
268 long ret = bindings.PaymentPurpose_read(InternalUtils.encodeUint8Array(ser));
270 if (ret >= 0 && ret <= 4096) { return null; }
271 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);