[Java] Print error stack trace when tests fail
[ldk-java] / src / main / java / org / ldk / structs / PaymentPurpose.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Some information provided on receipt of payment depends on whether the payment received is a
13  * spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class PaymentPurpose extends CommonBase {
17         private PaymentPurpose(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.PaymentPurpose_free(ptr); }
22         }
23         static PaymentPurpose constr_from_ptr(long ptr) {
24                 bindings.LDKPaymentPurpose raw_val = bindings.LDKPaymentPurpose_ref_from_ptr(ptr);
25                 if (raw_val.getClass() == bindings.LDKPaymentPurpose.Bolt11InvoicePayment.class) {
26                         return new Bolt11InvoicePayment(ptr, (bindings.LDKPaymentPurpose.Bolt11InvoicePayment)raw_val);
27                 }
28                 if (raw_val.getClass() == bindings.LDKPaymentPurpose.Bolt12OfferPayment.class) {
29                         return new Bolt12OfferPayment(ptr, (bindings.LDKPaymentPurpose.Bolt12OfferPayment)raw_val);
30                 }
31                 if (raw_val.getClass() == bindings.LDKPaymentPurpose.Bolt12RefundPayment.class) {
32                         return new Bolt12RefundPayment(ptr, (bindings.LDKPaymentPurpose.Bolt12RefundPayment)raw_val);
33                 }
34                 if (raw_val.getClass() == bindings.LDKPaymentPurpose.SpontaneousPayment.class) {
35                         return new SpontaneousPayment(ptr, (bindings.LDKPaymentPurpose.SpontaneousPayment)raw_val);
36                 }
37                 assert false; return null; // Unreachable without extending the (internal) bindings interface
38         }
39
40         /**
41          * A payment for a BOLT 11 invoice.
42          */
43         public final static class Bolt11InvoicePayment extends PaymentPurpose {
44                 /**
45                  * The preimage to the payment_hash, if the payment hash (and secret) were fetched via
46                  * [`ChannelManager::create_inbound_payment`]. When handling [`Event::PaymentClaimable`],
47                  * this can be passed directly to [`ChannelManager::claim_funds`] to claim the payment. No
48                  * action is needed when seen in [`Event::PaymentClaimed`].
49                  * 
50                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
51                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
52                 */
53                 public final org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage;
54                 /**
55                  * The \"payment secret\". This authenticates the sender to the recipient, preventing a
56                  * number of deanonymization attacks during the routing process.
57                  * It is provided here for your reference, however its accuracy is enforced directly by
58                  * [`ChannelManager`] using the values you previously provided to
59                  * [`ChannelManager::create_inbound_payment`] or
60                  * [`ChannelManager::create_inbound_payment_for_hash`].
61                  * 
62                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
63                  * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
64                  * [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
65                 */
66                 public final byte[] payment_secret;
67                 private Bolt11InvoicePayment(long ptr, bindings.LDKPaymentPurpose.Bolt11InvoicePayment obj) {
68                         super(null, ptr);
69                         long payment_preimage = obj.payment_preimage;
70                         org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
71                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.add(this); };
72                         this.payment_preimage = payment_preimage_hu_conv;
73                         this.payment_secret = obj.payment_secret;
74                 }
75         }
76         /**
77          * A payment for a BOLT 12 [`Offer`].
78          * 
79          * [`Offer`]: crate::offers::offer::Offer
80          */
81         public final static class Bolt12OfferPayment extends PaymentPurpose {
82                 /**
83                  * The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
84                  * passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
85                  * when seen in [`Event::PaymentClaimed`].
86                  * 
87                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
88                 */
89                 public final org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage;
90                 /**
91                  * The secret used to authenticate the sender to the recipient, preventing a number of
92                  * de-anonymization attacks while routing a payment.
93                  * 
94                  * See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
95                 */
96                 public final byte[] payment_secret;
97                 /**
98                  * The context of the payment such as information about the corresponding [`Offer`] and
99                  * [`InvoiceRequest`].
100                  * 
101                  * [`Offer`]: crate::offers::offer::Offer
102                  * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
103                 */
104                 public final org.ldk.structs.Bolt12OfferContext payment_context;
105                 private Bolt12OfferPayment(long ptr, bindings.LDKPaymentPurpose.Bolt12OfferPayment obj) {
106                         super(null, ptr);
107                         long payment_preimage = obj.payment_preimage;
108                         org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
109                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.add(this); };
110                         this.payment_preimage = payment_preimage_hu_conv;
111                         this.payment_secret = obj.payment_secret;
112                         long payment_context = obj.payment_context;
113                         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); }
114                         if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.add(this); };
115                         this.payment_context = payment_context_hu_conv;
116                 }
117         }
118         /**
119          * A payment for a BOLT 12 [`Refund`].
120          * 
121          * [`Refund`]: crate::offers::refund::Refund
122          */
123         public final static class Bolt12RefundPayment extends PaymentPurpose {
124                 /**
125                  * The preimage to the payment hash. When handling [`Event::PaymentClaimable`], this can be
126                  * passed directly to [`ChannelManager::claim_funds`], if provided. No action is needed
127                  * when seen in [`Event::PaymentClaimed`].
128                  * 
129                  * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
130                 */
131                 public final org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage;
132                 /**
133                  * The secret used to authenticate the sender to the recipient, preventing a number of
134                  * de-anonymization attacks while routing a payment.
135                  * 
136                  * See [`PaymentPurpose::Bolt11InvoicePayment::payment_secret`] for further details.
137                 */
138                 public final byte[] payment_secret;
139                 /**
140                  * The context of the payment such as information about the corresponding [`Refund`].
141                  * 
142                  * [`Refund`]: crate::offers::refund::Refund
143                 */
144                 public final org.ldk.structs.Bolt12RefundContext payment_context;
145                 private Bolt12RefundPayment(long ptr, bindings.LDKPaymentPurpose.Bolt12RefundPayment obj) {
146                         super(null, ptr);
147                         long payment_preimage = obj.payment_preimage;
148                         org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage);
149                         if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.add(this); };
150                         this.payment_preimage = payment_preimage_hu_conv;
151                         this.payment_secret = obj.payment_secret;
152                         long payment_context = obj.payment_context;
153                         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); }
154                         if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.add(this); };
155                         this.payment_context = payment_context_hu_conv;
156                 }
157         }
158         /**
159          * Because this is a spontaneous payment, the payer generated their own preimage rather than us
160          * (the payee) providing a preimage.
161          */
162         public final static class SpontaneousPayment extends PaymentPurpose {
163                 public final byte[] spontaneous_payment;
164                 private SpontaneousPayment(long ptr, bindings.LDKPaymentPurpose.SpontaneousPayment obj) {
165                         super(null, ptr);
166                         this.spontaneous_payment = obj.spontaneous_payment;
167                 }
168         }
169         long clone_ptr() {
170                 long ret = bindings.PaymentPurpose_clone_ptr(this.ptr);
171                 Reference.reachabilityFence(this);
172                 return ret;
173         }
174
175         /**
176          * Creates a copy of the PaymentPurpose
177          */
178         public PaymentPurpose clone() {
179                 long ret = bindings.PaymentPurpose_clone(this.ptr);
180                 Reference.reachabilityFence(this);
181                 if (ret >= 0 && ret <= 4096) { return null; }
182                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
183                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
184                 return ret_hu_conv;
185         }
186
187         /**
188          * Utility method to constructs a new Bolt11InvoicePayment-variant PaymentPurpose
189          */
190         public static PaymentPurpose bolt11_invoice_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret) {
191                 long ret = bindings.PaymentPurpose_bolt11_invoice_payment(payment_preimage.ptr, InternalUtils.check_arr_len(payment_secret, 32));
192                 Reference.reachabilityFence(payment_preimage);
193                 Reference.reachabilityFence(payment_secret);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
196                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
197                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_preimage); };
198                 return ret_hu_conv;
199         }
200
201         /**
202          * Utility method to constructs a new Bolt12OfferPayment-variant PaymentPurpose
203          */
204         public static PaymentPurpose bolt12_offer_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret, org.ldk.structs.Bolt12OfferContext payment_context) {
205                 long ret = bindings.PaymentPurpose_bolt12_offer_payment(payment_preimage.ptr, InternalUtils.check_arr_len(payment_secret, 32), payment_context.ptr);
206                 Reference.reachabilityFence(payment_preimage);
207                 Reference.reachabilityFence(payment_secret);
208                 Reference.reachabilityFence(payment_context);
209                 if (ret >= 0 && ret <= 4096) { return null; }
210                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
211                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
212                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_preimage); };
213                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_context); };
214                 return ret_hu_conv;
215         }
216
217         /**
218          * Utility method to constructs a new Bolt12RefundPayment-variant PaymentPurpose
219          */
220         public static PaymentPurpose bolt12_refund_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret, org.ldk.structs.Bolt12RefundContext payment_context) {
221                 long ret = bindings.PaymentPurpose_bolt12_refund_payment(payment_preimage.ptr, InternalUtils.check_arr_len(payment_secret, 32), payment_context.ptr);
222                 Reference.reachabilityFence(payment_preimage);
223                 Reference.reachabilityFence(payment_secret);
224                 Reference.reachabilityFence(payment_context);
225                 if (ret >= 0 && ret <= 4096) { return null; }
226                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
227                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
228                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_preimage); };
229                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_context); };
230                 return ret_hu_conv;
231         }
232
233         /**
234          * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
235          */
236         public static PaymentPurpose spontaneous_payment(byte[] a) {
237                 long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32));
238                 Reference.reachabilityFence(a);
239                 if (ret >= 0 && ret <= 4096) { return null; }
240                 org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
241                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
242                 return ret_hu_conv;
243         }
244
245         /**
246          * Checks if two PaymentPurposes contain equal inner contents.
247          * This ignores pointers and is_owned flags and looks at the values in fields.
248          */
249         public boolean eq(org.ldk.structs.PaymentPurpose b) {
250                 boolean ret = bindings.PaymentPurpose_eq(this.ptr, b.ptr);
251                 Reference.reachabilityFence(this);
252                 Reference.reachabilityFence(b);
253                 return ret;
254         }
255
256         @Override public boolean equals(Object o) {
257                 if (!(o instanceof PaymentPurpose)) return false;
258                 return this.eq((PaymentPurpose)o);
259         }
260         /**
261          * Returns the preimage for this payment, if it is known.
262          */
263         public Option_ThirtyTwoBytesZ preimage() {
264                 long ret = bindings.PaymentPurpose_preimage(this.ptr);
265                 Reference.reachabilityFence(this);
266                 if (ret >= 0 && ret <= 4096) { return null; }
267                 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
268                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
269                 return ret_hu_conv;
270         }
271
272         /**
273          * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
274          */
275         public byte[] write() {
276                 byte[] ret = bindings.PaymentPurpose_write(this.ptr);
277                 Reference.reachabilityFence(this);
278                 return ret;
279         }
280
281         /**
282          * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
283          */
284         public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
285                 long ret = bindings.PaymentPurpose_read(ser);
286                 Reference.reachabilityFence(ser);
287                 if (ret >= 0 && ret <= 4096) { return null; }
288                 Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);
289                 return ret_hu_conv;
290         }
291
292 }