[Java] Print error stack trace when tests fail
[ldk-java] / src / main / java / org / ldk / structs / PendingHTLCRouting.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  * Information about where a received HTLC('s onion) has indicated the HTLC should go.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class PendingHTLCRouting extends CommonBase {
16         private PendingHTLCRouting(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.PendingHTLCRouting_free(ptr); }
21         }
22         static PendingHTLCRouting constr_from_ptr(long ptr) {
23                 bindings.LDKPendingHTLCRouting raw_val = bindings.LDKPendingHTLCRouting_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKPendingHTLCRouting.Forward.class) {
25                         return new Forward(ptr, (bindings.LDKPendingHTLCRouting.Forward)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKPendingHTLCRouting.Receive.class) {
28                         return new Receive(ptr, (bindings.LDKPendingHTLCRouting.Receive)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKPendingHTLCRouting.ReceiveKeysend.class) {
31                         return new ReceiveKeysend(ptr, (bindings.LDKPendingHTLCRouting.ReceiveKeysend)raw_val);
32                 }
33                 assert false; return null; // Unreachable without extending the (internal) bindings interface
34         }
35
36         /**
37          * An HTLC which should be forwarded on to another node.
38          */
39         public final static class Forward extends PendingHTLCRouting {
40                 /**
41                  * The onion which should be included in the forwarded HTLC, telling the next hop what to
42                  * do with the HTLC.
43                 */
44                 public final org.ldk.structs.OnionPacket onion_packet;
45                 /**
46                  * The short channel ID of the channel which we were instructed to forward this HTLC to.
47                  * 
48                  * This could be a real on-chain SCID, an SCID alias, or some other SCID which has meaning
49                  * to the receiving node, such as one returned from
50                  * [`ChannelManager::get_intercept_scid`] or [`ChannelManager::get_phantom_scid`].
51                 */
52                 public final long short_channel_id;
53                 /**
54                  * Set if this HTLC is being forwarded within a blinded path.
55                  * 
56                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
57                 */
58                 @Nullable public final org.ldk.structs.BlindedForward blinded;
59                 private Forward(long ptr, bindings.LDKPendingHTLCRouting.Forward obj) {
60                         super(null, ptr);
61                         long onion_packet = obj.onion_packet;
62                         org.ldk.structs.OnionPacket onion_packet_hu_conv = null; if (onion_packet < 0 || onion_packet > 4096) { onion_packet_hu_conv = new org.ldk.structs.OnionPacket(null, onion_packet); }
63                         if (onion_packet_hu_conv != null) { onion_packet_hu_conv.ptrs_to.add(this); };
64                         this.onion_packet = onion_packet_hu_conv;
65                         this.short_channel_id = obj.short_channel_id;
66                         long blinded = obj.blinded;
67                         org.ldk.structs.BlindedForward blinded_hu_conv = null; if (blinded < 0 || blinded > 4096) { blinded_hu_conv = new org.ldk.structs.BlindedForward(null, blinded); }
68                         if (blinded_hu_conv != null) { blinded_hu_conv.ptrs_to.add(this); };
69                         this.blinded = blinded_hu_conv;
70                 }
71         }
72         /**
73          * The onion indicates that this is a payment for an invoice (supposedly) generated by us.
74          * 
75          * Note that at this point, we have not checked that the invoice being paid was actually
76          * generated by us, but rather it's claiming to pay an invoice of ours.
77          */
78         public final static class Receive extends PendingHTLCRouting {
79                 /**
80                  * Information about the amount the sender intended to pay and (potential) proof that this
81                  * is a payment for an invoice we generated. This proof of payment is is also used for
82                  * linking MPP parts of a larger payment.
83                 */
84                 public final org.ldk.structs.FinalOnionHopData payment_data;
85                 /**
86                  * Additional data which we (allegedly) instructed the sender to include in the onion.
87                  * 
88                  * For HTLCs received by LDK, this will ultimately be exposed in
89                  * [`Event::PaymentClaimable::onion_fields`] as
90                  * [`RecipientOnionFields::payment_metadata`].
91                 */
92                 public final org.ldk.structs.Option_CVec_u8ZZ payment_metadata;
93                 /**
94                  * The context of the payment included by the recipient in a blinded path, or `None` if a
95                  * blinded path was not used.
96                  * 
97                  * Used in part to determine the [`events::PaymentPurpose`].
98                 */
99                 public final org.ldk.structs.Option_PaymentContextZ payment_context;
100                 /**
101                  * CLTV expiry of the received HTLC.
102                  * 
103                  * Used to track when we should expire pending HTLCs that go unclaimed.
104                 */
105                 public final int incoming_cltv_expiry;
106                 /**
107                  * If the onion had forwarding instructions to one of our phantom node SCIDs, this will
108                  * provide the onion shared secret used to decrypt the next level of forwarding
109                  * instructions.
110                  * 
111                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
112                 */
113                 @Nullable public final byte[] phantom_shared_secret;
114                 /**
115                  * Custom TLVs which were set by the sender.
116                  * 
117                  * For HTLCs received by LDK, this will ultimately be exposed in
118                  * [`Event::PaymentClaimable::onion_fields`] as
119                  * [`RecipientOnionFields::custom_tlvs`].
120                 */
121                 public final TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
122                 /**
123                  * Set if this HTLC is the final hop in a multi-hop blinded path.
124                 */
125                 public final boolean requires_blinded_error;
126                 private Receive(long ptr, bindings.LDKPendingHTLCRouting.Receive obj) {
127                         super(null, ptr);
128                         long payment_data = obj.payment_data;
129                         org.ldk.structs.FinalOnionHopData payment_data_hu_conv = null; if (payment_data < 0 || payment_data > 4096) { payment_data_hu_conv = new org.ldk.structs.FinalOnionHopData(null, payment_data); }
130                         if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.add(this); };
131                         this.payment_data = payment_data_hu_conv;
132                         long payment_metadata = obj.payment_metadata;
133                         org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
134                         if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.add(this); };
135                         this.payment_metadata = payment_metadata_hu_conv;
136                         long payment_context = obj.payment_context;
137                         org.ldk.structs.Option_PaymentContextZ payment_context_hu_conv = org.ldk.structs.Option_PaymentContextZ.constr_from_ptr(payment_context);
138                         if (payment_context_hu_conv != null) { payment_context_hu_conv.ptrs_to.add(this); };
139                         this.payment_context = payment_context_hu_conv;
140                         this.incoming_cltv_expiry = obj.incoming_cltv_expiry;
141                         this.phantom_shared_secret = obj.phantom_shared_secret;
142                         long[] custom_tlvs = obj.custom_tlvs;
143                         int custom_tlvs_conv_23_len = custom_tlvs.length;
144                         TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
145                         for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
146                                 long custom_tlvs_conv_23 = custom_tlvs[x];
147                                 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
148                                 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.add(this); };
149                                 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
150                         }
151                         this.custom_tlvs = custom_tlvs_conv_23_arr;
152                         this.requires_blinded_error = obj.requires_blinded_error;
153                 }
154         }
155         /**
156          * The onion indicates that this is for payment to us but which contains the preimage for
157          * claiming included, and is unrelated to any invoice we'd previously generated (aka a
158          * \"keysend\" or \"spontaneous\" payment).
159          */
160         public final static class ReceiveKeysend extends PendingHTLCRouting {
161                 /**
162                  * Information about the amount the sender intended to pay and possibly a token to
163                  * associate MPP parts of a larger payment.
164                  * 
165                  * This will only be filled in if receiving MPP keysend payments is enabled, and it being
166                  * present will cause deserialization to fail on versions of LDK prior to 0.0.116.
167                  * 
168                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
169                 */
170                 @Nullable public final org.ldk.structs.FinalOnionHopData payment_data;
171                 /**
172                  * Preimage for this onion payment. This preimage is provided by the sender and will be
173                  * used to settle the spontaneous payment.
174                 */
175                 public final byte[] payment_preimage;
176                 /**
177                  * Additional data which we (allegedly) instructed the sender to include in the onion.
178                  * 
179                  * For HTLCs received by LDK, this will ultimately bubble back up as
180                  * [`RecipientOnionFields::payment_metadata`].
181                 */
182                 public final org.ldk.structs.Option_CVec_u8ZZ payment_metadata;
183                 /**
184                  * CLTV expiry of the received HTLC.
185                  * 
186                  * Used to track when we should expire pending HTLCs that go unclaimed.
187                 */
188                 public final int incoming_cltv_expiry;
189                 /**
190                  * Custom TLVs which were set by the sender.
191                  * 
192                  * For HTLCs received by LDK, these will ultimately bubble back up as
193                  * [`RecipientOnionFields::custom_tlvs`].
194                 */
195                 public final TwoTuple_u64CVec_u8ZZ[] custom_tlvs;
196                 /**
197                  * Set if this HTLC is the final hop in a multi-hop blinded path.
198                 */
199                 public final boolean requires_blinded_error;
200                 private ReceiveKeysend(long ptr, bindings.LDKPendingHTLCRouting.ReceiveKeysend obj) {
201                         super(null, ptr);
202                         long payment_data = obj.payment_data;
203                         org.ldk.structs.FinalOnionHopData payment_data_hu_conv = null; if (payment_data < 0 || payment_data > 4096) { payment_data_hu_conv = new org.ldk.structs.FinalOnionHopData(null, payment_data); }
204                         if (payment_data_hu_conv != null) { payment_data_hu_conv.ptrs_to.add(this); };
205                         this.payment_data = payment_data_hu_conv;
206                         this.payment_preimage = obj.payment_preimage;
207                         long payment_metadata = obj.payment_metadata;
208                         org.ldk.structs.Option_CVec_u8ZZ payment_metadata_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(payment_metadata);
209                         if (payment_metadata_hu_conv != null) { payment_metadata_hu_conv.ptrs_to.add(this); };
210                         this.payment_metadata = payment_metadata_hu_conv;
211                         this.incoming_cltv_expiry = obj.incoming_cltv_expiry;
212                         long[] custom_tlvs = obj.custom_tlvs;
213                         int custom_tlvs_conv_23_len = custom_tlvs.length;
214                         TwoTuple_u64CVec_u8ZZ[] custom_tlvs_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[custom_tlvs_conv_23_len];
215                         for (int x = 0; x < custom_tlvs_conv_23_len; x++) {
216                                 long custom_tlvs_conv_23 = custom_tlvs[x];
217                                 TwoTuple_u64CVec_u8ZZ custom_tlvs_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, custom_tlvs_conv_23);
218                                 if (custom_tlvs_conv_23_hu_conv != null) { custom_tlvs_conv_23_hu_conv.ptrs_to.add(this); };
219                                 custom_tlvs_conv_23_arr[x] = custom_tlvs_conv_23_hu_conv;
220                         }
221                         this.custom_tlvs = custom_tlvs_conv_23_arr;
222                         this.requires_blinded_error = obj.requires_blinded_error;
223                 }
224         }
225         long clone_ptr() {
226                 long ret = bindings.PendingHTLCRouting_clone_ptr(this.ptr);
227                 Reference.reachabilityFence(this);
228                 return ret;
229         }
230
231         /**
232          * Creates a copy of the PendingHTLCRouting
233          */
234         public PendingHTLCRouting clone() {
235                 long ret = bindings.PendingHTLCRouting_clone(this.ptr);
236                 Reference.reachabilityFence(this);
237                 if (ret >= 0 && ret <= 4096) { return null; }
238                 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
239                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
240                 return ret_hu_conv;
241         }
242
243         /**
244          * Utility method to constructs a new Forward-variant PendingHTLCRouting
245          */
246         public static PendingHTLCRouting forward(org.ldk.structs.OnionPacket onion_packet, long short_channel_id, org.ldk.structs.BlindedForward blinded) {
247                 long ret = bindings.PendingHTLCRouting_forward(onion_packet.ptr, short_channel_id, blinded.ptr);
248                 Reference.reachabilityFence(onion_packet);
249                 Reference.reachabilityFence(short_channel_id);
250                 Reference.reachabilityFence(blinded);
251                 if (ret >= 0 && ret <= 4096) { return null; }
252                 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
253                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
254                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(onion_packet); };
255                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(blinded); };
256                 return ret_hu_conv;
257         }
258
259         /**
260          * Utility method to constructs a new Receive-variant PendingHTLCRouting
261          */
262         public static PendingHTLCRouting receive(org.ldk.structs.FinalOnionHopData payment_data, org.ldk.structs.Option_CVec_u8ZZ payment_metadata, org.ldk.structs.Option_PaymentContextZ payment_context, int incoming_cltv_expiry, byte[] phantom_shared_secret, TwoTuple_u64CVec_u8ZZ[] custom_tlvs, boolean requires_blinded_error) {
263                 long ret = bindings.PendingHTLCRouting_receive(payment_data.ptr, payment_metadata.ptr, payment_context.ptr, incoming_cltv_expiry, InternalUtils.check_arr_len(phantom_shared_secret, 32), custom_tlvs != null ? Arrays.stream(custom_tlvs).mapToLong(custom_tlvs_conv_23 -> custom_tlvs_conv_23.ptr).toArray() : null, requires_blinded_error);
264                 Reference.reachabilityFence(payment_data);
265                 Reference.reachabilityFence(payment_metadata);
266                 Reference.reachabilityFence(payment_context);
267                 Reference.reachabilityFence(incoming_cltv_expiry);
268                 Reference.reachabilityFence(phantom_shared_secret);
269                 Reference.reachabilityFence(custom_tlvs);
270                 Reference.reachabilityFence(requires_blinded_error);
271                 if (ret >= 0 && ret <= 4096) { return null; }
272                 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
273                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
274                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_data); };
275                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_metadata); };
276                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_context); };
277                 return ret_hu_conv;
278         }
279
280         /**
281          * Utility method to constructs a new ReceiveKeysend-variant PendingHTLCRouting
282          */
283         public static PendingHTLCRouting receive_keysend(org.ldk.structs.FinalOnionHopData payment_data, byte[] payment_preimage, org.ldk.structs.Option_CVec_u8ZZ payment_metadata, int incoming_cltv_expiry, TwoTuple_u64CVec_u8ZZ[] custom_tlvs, boolean requires_blinded_error) {
284                 long ret = bindings.PendingHTLCRouting_receive_keysend(payment_data.ptr, InternalUtils.check_arr_len(payment_preimage, 32), payment_metadata.ptr, incoming_cltv_expiry, custom_tlvs != null ? Arrays.stream(custom_tlvs).mapToLong(custom_tlvs_conv_23 -> custom_tlvs_conv_23.ptr).toArray() : null, requires_blinded_error);
285                 Reference.reachabilityFence(payment_data);
286                 Reference.reachabilityFence(payment_preimage);
287                 Reference.reachabilityFence(payment_metadata);
288                 Reference.reachabilityFence(incoming_cltv_expiry);
289                 Reference.reachabilityFence(custom_tlvs);
290                 Reference.reachabilityFence(requires_blinded_error);
291                 if (ret >= 0 && ret <= 4096) { return null; }
292                 org.ldk.structs.PendingHTLCRouting ret_hu_conv = org.ldk.structs.PendingHTLCRouting.constr_from_ptr(ret);
293                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
294                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_data); };
295                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_metadata); };
296                 return ret_hu_conv;
297         }
298
299         /**
300          * Serialize the PendingHTLCRouting object into a byte array which can be read by PendingHTLCRouting_read
301          */
302         public byte[] write() {
303                 byte[] ret = bindings.PendingHTLCRouting_write(this.ptr);
304                 Reference.reachabilityFence(this);
305                 return ret;
306         }
307
308         /**
309          * Read a PendingHTLCRouting from a byte array, created by PendingHTLCRouting_write
310          */
311         public static Result_PendingHTLCRoutingDecodeErrorZ read(byte[] ser) {
312                 long ret = bindings.PendingHTLCRouting_read(ser);
313                 Reference.reachabilityFence(ser);
314                 if (ret >= 0 && ret <= 4096) { return null; }
315                 Result_PendingHTLCRoutingDecodeErrorZ ret_hu_conv = Result_PendingHTLCRoutingDecodeErrorZ.constr_from_ptr(ret);
316                 return ret_hu_conv;
317         }
318
319 }