[Java] Print error stack trace when tests fail
[ldk-java] / src / main / java / org / ldk / structs / ClosureReason.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  * The reason the channel was closed. See individual variants for more details.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ClosureReason extends CommonBase {
16         private ClosureReason(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.ClosureReason_free(ptr); }
21         }
22         static ClosureReason constr_from_ptr(long ptr) {
23                 bindings.LDKClosureReason raw_val = bindings.LDKClosureReason_ref_from_ptr(ptr);
24                 if (raw_val.getClass() == bindings.LDKClosureReason.CounterpartyForceClosed.class) {
25                         return new CounterpartyForceClosed(ptr, (bindings.LDKClosureReason.CounterpartyForceClosed)raw_val);
26                 }
27                 if (raw_val.getClass() == bindings.LDKClosureReason.HolderForceClosed.class) {
28                         return new HolderForceClosed(ptr, (bindings.LDKClosureReason.HolderForceClosed)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKClosureReason.LegacyCooperativeClosure.class) {
31                         return new LegacyCooperativeClosure(ptr, (bindings.LDKClosureReason.LegacyCooperativeClosure)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKClosureReason.CounterpartyInitiatedCooperativeClosure.class) {
34                         return new CounterpartyInitiatedCooperativeClosure(ptr, (bindings.LDKClosureReason.CounterpartyInitiatedCooperativeClosure)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKClosureReason.LocallyInitiatedCooperativeClosure.class) {
37                         return new LocallyInitiatedCooperativeClosure(ptr, (bindings.LDKClosureReason.LocallyInitiatedCooperativeClosure)raw_val);
38                 }
39                 if (raw_val.getClass() == bindings.LDKClosureReason.CommitmentTxConfirmed.class) {
40                         return new CommitmentTxConfirmed(ptr, (bindings.LDKClosureReason.CommitmentTxConfirmed)raw_val);
41                 }
42                 if (raw_val.getClass() == bindings.LDKClosureReason.FundingTimedOut.class) {
43                         return new FundingTimedOut(ptr, (bindings.LDKClosureReason.FundingTimedOut)raw_val);
44                 }
45                 if (raw_val.getClass() == bindings.LDKClosureReason.ProcessingError.class) {
46                         return new ProcessingError(ptr, (bindings.LDKClosureReason.ProcessingError)raw_val);
47                 }
48                 if (raw_val.getClass() == bindings.LDKClosureReason.DisconnectedPeer.class) {
49                         return new DisconnectedPeer(ptr, (bindings.LDKClosureReason.DisconnectedPeer)raw_val);
50                 }
51                 if (raw_val.getClass() == bindings.LDKClosureReason.OutdatedChannelManager.class) {
52                         return new OutdatedChannelManager(ptr, (bindings.LDKClosureReason.OutdatedChannelManager)raw_val);
53                 }
54                 if (raw_val.getClass() == bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel.class) {
55                         return new CounterpartyCoopClosedUnfundedChannel(ptr, (bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel)raw_val);
56                 }
57                 if (raw_val.getClass() == bindings.LDKClosureReason.FundingBatchClosure.class) {
58                         return new FundingBatchClosure(ptr, (bindings.LDKClosureReason.FundingBatchClosure)raw_val);
59                 }
60                 if (raw_val.getClass() == bindings.LDKClosureReason.HTLCsTimedOut.class) {
61                         return new HTLCsTimedOut(ptr, (bindings.LDKClosureReason.HTLCsTimedOut)raw_val);
62                 }
63                 assert false; return null; // Unreachable without extending the (internal) bindings interface
64         }
65
66         /**
67          * Closure generated from receiving a peer error message.
68          * 
69          * Our counterparty may have broadcasted their latest commitment state, and we have
70          * as well.
71          */
72         public final static class CounterpartyForceClosed extends ClosureReason {
73                 /**
74                  * The error which the peer sent us.
75                  * 
76                  * Be careful about printing the peer_msg, a well-crafted message could exploit
77                  * a security vulnerability in the terminal emulator or the logging subsystem.
78                  * To be safe, use `Display` on `UntrustedString`
79                  * 
80                  * [`UntrustedString`]: crate::util::string::UntrustedString
81                 */
82                 public final org.ldk.structs.UntrustedString peer_msg;
83                 private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) {
84                         super(null, ptr);
85                         long peer_msg = obj.peer_msg;
86                         org.ldk.structs.UntrustedString peer_msg_hu_conv = null; if (peer_msg < 0 || peer_msg > 4096) { peer_msg_hu_conv = new org.ldk.structs.UntrustedString(null, peer_msg); }
87                         if (peer_msg_hu_conv != null) { peer_msg_hu_conv.ptrs_to.add(this); };
88                         this.peer_msg = peer_msg_hu_conv;
89                 }
90         }
91         /**
92          * Closure generated from [`ChannelManager::force_close_channel`], called by the user.
93          * 
94          * [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
95          */
96         public final static class HolderForceClosed extends ClosureReason {
97                 private HolderForceClosed(long ptr, bindings.LDKClosureReason.HolderForceClosed obj) {
98                         super(null, ptr);
99                 }
100         }
101         /**
102          * The channel was closed after negotiating a cooperative close and we've now broadcasted
103          * the cooperative close transaction. Note the shutdown may have been initiated by us.
104          * 
105          * This was only set in versions of LDK prior to 0.0.122.
106          */
107         public final static class LegacyCooperativeClosure extends ClosureReason {
108                 private LegacyCooperativeClosure(long ptr, bindings.LDKClosureReason.LegacyCooperativeClosure obj) {
109                         super(null, ptr);
110                 }
111         }
112         /**
113          * The channel was closed after negotiating a cooperative close and we've now broadcasted
114          * the cooperative close transaction. This indicates that the shutdown was initiated by our
115          * counterparty.
116          * 
117          * In rare cases where we initiated closure immediately prior to shutting down without
118          * persisting, this value may be provided for channels we initiated closure for.
119          */
120         public final static class CounterpartyInitiatedCooperativeClosure extends ClosureReason {
121                 private CounterpartyInitiatedCooperativeClosure(long ptr, bindings.LDKClosureReason.CounterpartyInitiatedCooperativeClosure obj) {
122                         super(null, ptr);
123                 }
124         }
125         /**
126          * The channel was closed after negotiating a cooperative close and we've now broadcasted
127          * the cooperative close transaction. This indicates that the shutdown was initiated by us.
128          */
129         public final static class LocallyInitiatedCooperativeClosure extends ClosureReason {
130                 private LocallyInitiatedCooperativeClosure(long ptr, bindings.LDKClosureReason.LocallyInitiatedCooperativeClosure obj) {
131                         super(null, ptr);
132                 }
133         }
134         /**
135          * A commitment transaction was confirmed on chain, closing the channel. Most likely this
136          * commitment transaction came from our counterparty, but it may also have come from
137          * a copy of our own `ChannelMonitor`.
138          */
139         public final static class CommitmentTxConfirmed extends ClosureReason {
140                 private CommitmentTxConfirmed(long ptr, bindings.LDKClosureReason.CommitmentTxConfirmed obj) {
141                         super(null, ptr);
142                 }
143         }
144         /**
145          * The funding transaction failed to confirm in a timely manner on an inbound channel.
146          */
147         public final static class FundingTimedOut extends ClosureReason {
148                 private FundingTimedOut(long ptr, bindings.LDKClosureReason.FundingTimedOut obj) {
149                         super(null, ptr);
150                 }
151         }
152         /**
153          * Closure generated from processing an event, likely a HTLC forward/relay/reception.
154          */
155         public final static class ProcessingError extends ClosureReason {
156                 /**
157                  * A developer-readable error message which we generated.
158                 */
159                 public final java.lang.String err;
160                 private ProcessingError(long ptr, bindings.LDKClosureReason.ProcessingError obj) {
161                         super(null, ptr);
162                         this.err = obj.err;
163                 }
164         }
165         /**
166          * The peer disconnected prior to funding completing. In this case the spec mandates that we
167          * forget the channel entirely - we can attempt again if the peer reconnects.
168          * 
169          * This includes cases where we restarted prior to funding completion, including prior to the
170          * initial [`ChannelMonitor`] persistence completing.
171          * 
172          * In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
173          * peer because of mutual incompatibility between us and our channel counterparty.
174          * 
175          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
176          */
177         public final static class DisconnectedPeer extends ClosureReason {
178                 private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) {
179                         super(null, ptr);
180                 }
181         }
182         /**
183          * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
184          * the [`ChannelManager`] deserialized.
185          * 
186          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
187          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
188          */
189         public final static class OutdatedChannelManager extends ClosureReason {
190                 private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) {
191                         super(null, ptr);
192                 }
193         }
194         /**
195          * The counterparty requested a cooperative close of a channel that had not been funded yet.
196          * The channel has been immediately closed.
197          */
198         public final static class CounterpartyCoopClosedUnfundedChannel extends ClosureReason {
199                 private CounterpartyCoopClosedUnfundedChannel(long ptr, bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel obj) {
200                         super(null, ptr);
201                 }
202         }
203         /**
204          * Another channel in the same funding batch closed before the funding transaction
205          * was ready to be broadcast.
206          */
207         public final static class FundingBatchClosure extends ClosureReason {
208                 private FundingBatchClosure(long ptr, bindings.LDKClosureReason.FundingBatchClosure obj) {
209                         super(null, ptr);
210                 }
211         }
212         /**
213          * One of our HTLCs timed out in a channel, causing us to force close the channel.
214          */
215         public final static class HTLCsTimedOut extends ClosureReason {
216                 private HTLCsTimedOut(long ptr, bindings.LDKClosureReason.HTLCsTimedOut obj) {
217                         super(null, ptr);
218                 }
219         }
220         long clone_ptr() {
221                 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
222                 Reference.reachabilityFence(this);
223                 return ret;
224         }
225
226         /**
227          * Creates a copy of the ClosureReason
228          */
229         public ClosureReason clone() {
230                 long ret = bindings.ClosureReason_clone(this.ptr);
231                 Reference.reachabilityFence(this);
232                 if (ret >= 0 && ret <= 4096) { return null; }
233                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
234                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
235                 return ret_hu_conv;
236         }
237
238         /**
239          * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
240          */
241         public static ClosureReason counterparty_force_closed(org.ldk.structs.UntrustedString peer_msg) {
242                 long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg.ptr);
243                 Reference.reachabilityFence(peer_msg);
244                 if (ret >= 0 && ret <= 4096) { return null; }
245                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
246                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
247                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(peer_msg); };
248                 return ret_hu_conv;
249         }
250
251         /**
252          * Utility method to constructs a new HolderForceClosed-variant ClosureReason
253          */
254         public static ClosureReason holder_force_closed() {
255                 long ret = bindings.ClosureReason_holder_force_closed();
256                 if (ret >= 0 && ret <= 4096) { return null; }
257                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
258                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
259                 return ret_hu_conv;
260         }
261
262         /**
263          * Utility method to constructs a new LegacyCooperativeClosure-variant ClosureReason
264          */
265         public static ClosureReason legacy_cooperative_closure() {
266                 long ret = bindings.ClosureReason_legacy_cooperative_closure();
267                 if (ret >= 0 && ret <= 4096) { return null; }
268                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
269                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
270                 return ret_hu_conv;
271         }
272
273         /**
274          * Utility method to constructs a new CounterpartyInitiatedCooperativeClosure-variant ClosureReason
275          */
276         public static ClosureReason counterparty_initiated_cooperative_closure() {
277                 long ret = bindings.ClosureReason_counterparty_initiated_cooperative_closure();
278                 if (ret >= 0 && ret <= 4096) { return null; }
279                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
280                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
281                 return ret_hu_conv;
282         }
283
284         /**
285          * Utility method to constructs a new LocallyInitiatedCooperativeClosure-variant ClosureReason
286          */
287         public static ClosureReason locally_initiated_cooperative_closure() {
288                 long ret = bindings.ClosureReason_locally_initiated_cooperative_closure();
289                 if (ret >= 0 && ret <= 4096) { return null; }
290                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
291                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
292                 return ret_hu_conv;
293         }
294
295         /**
296          * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
297          */
298         public static ClosureReason commitment_tx_confirmed() {
299                 long ret = bindings.ClosureReason_commitment_tx_confirmed();
300                 if (ret >= 0 && ret <= 4096) { return null; }
301                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
302                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
303                 return ret_hu_conv;
304         }
305
306         /**
307          * Utility method to constructs a new FundingTimedOut-variant ClosureReason
308          */
309         public static ClosureReason funding_timed_out() {
310                 long ret = bindings.ClosureReason_funding_timed_out();
311                 if (ret >= 0 && ret <= 4096) { return null; }
312                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
313                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
314                 return ret_hu_conv;
315         }
316
317         /**
318          * Utility method to constructs a new ProcessingError-variant ClosureReason
319          */
320         public static ClosureReason processing_error(java.lang.String err) {
321                 long ret = bindings.ClosureReason_processing_error(err);
322                 Reference.reachabilityFence(err);
323                 if (ret >= 0 && ret <= 4096) { return null; }
324                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
325                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
326                 return ret_hu_conv;
327         }
328
329         /**
330          * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
331          */
332         public static ClosureReason disconnected_peer() {
333                 long ret = bindings.ClosureReason_disconnected_peer();
334                 if (ret >= 0 && ret <= 4096) { return null; }
335                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
336                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
337                 return ret_hu_conv;
338         }
339
340         /**
341          * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
342          */
343         public static ClosureReason outdated_channel_manager() {
344                 long ret = bindings.ClosureReason_outdated_channel_manager();
345                 if (ret >= 0 && ret <= 4096) { return null; }
346                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
347                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
348                 return ret_hu_conv;
349         }
350
351         /**
352          * Utility method to constructs a new CounterpartyCoopClosedUnfundedChannel-variant ClosureReason
353          */
354         public static ClosureReason counterparty_coop_closed_unfunded_channel() {
355                 long ret = bindings.ClosureReason_counterparty_coop_closed_unfunded_channel();
356                 if (ret >= 0 && ret <= 4096) { return null; }
357                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
358                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
359                 return ret_hu_conv;
360         }
361
362         /**
363          * Utility method to constructs a new FundingBatchClosure-variant ClosureReason
364          */
365         public static ClosureReason funding_batch_closure() {
366                 long ret = bindings.ClosureReason_funding_batch_closure();
367                 if (ret >= 0 && ret <= 4096) { return null; }
368                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
369                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
370                 return ret_hu_conv;
371         }
372
373         /**
374          * Utility method to constructs a new HTLCsTimedOut-variant ClosureReason
375          */
376         public static ClosureReason htlcs_timed_out() {
377                 long ret = bindings.ClosureReason_htlcs_timed_out();
378                 if (ret >= 0 && ret <= 4096) { return null; }
379                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
380                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
381                 return ret_hu_conv;
382         }
383
384         /**
385          * Checks if two ClosureReasons contain equal inner contents.
386          * This ignores pointers and is_owned flags and looks at the values in fields.
387          */
388         public boolean eq(org.ldk.structs.ClosureReason b) {
389                 boolean ret = bindings.ClosureReason_eq(this.ptr, b.ptr);
390                 Reference.reachabilityFence(this);
391                 Reference.reachabilityFence(b);
392                 return ret;
393         }
394
395         @Override public boolean equals(Object o) {
396                 if (!(o instanceof ClosureReason)) return false;
397                 return this.eq((ClosureReason)o);
398         }
399         /**
400          * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
401          */
402         public byte[] write() {
403                 byte[] ret = bindings.ClosureReason_write(this.ptr);
404                 Reference.reachabilityFence(this);
405                 return ret;
406         }
407
408 }