7c95760323ef93e4c840981b5ce75e8d4137e9bf
[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 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.CooperativeClosure.class) {
31                         return new CooperativeClosure(ptr, (bindings.LDKClosureReason.CooperativeClosure)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKClosureReason.CommitmentTxConfirmed.class) {
34                         return new CommitmentTxConfirmed(ptr, (bindings.LDKClosureReason.CommitmentTxConfirmed)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKClosureReason.FundingTimedOut.class) {
37                         return new FundingTimedOut(ptr, (bindings.LDKClosureReason.FundingTimedOut)raw_val);
38                 }
39                 if (raw_val.getClass() == bindings.LDKClosureReason.ProcessingError.class) {
40                         return new ProcessingError(ptr, (bindings.LDKClosureReason.ProcessingError)raw_val);
41                 }
42                 if (raw_val.getClass() == bindings.LDKClosureReason.DisconnectedPeer.class) {
43                         return new DisconnectedPeer(ptr, (bindings.LDKClosureReason.DisconnectedPeer)raw_val);
44                 }
45                 if (raw_val.getClass() == bindings.LDKClosureReason.OutdatedChannelManager.class) {
46                         return new OutdatedChannelManager(ptr, (bindings.LDKClosureReason.OutdatedChannelManager)raw_val);
47                 }
48                 assert false; return null; // Unreachable without extending the (internal) bindings interface
49         }
50
51         /**
52          * Closure generated from receiving a peer error message.
53          * 
54          * Our counterparty may have broadcasted their latest commitment state, and we have
55          * as well.
56          */
57         public final static class CounterpartyForceClosed extends ClosureReason {
58                 /**
59                  * The error which the peer sent us.
60                  * 
61                  * The string should be sanitized before it is used (e.g emitted to logs
62                  * or printed to stdout). Otherwise, a well crafted error message may exploit
63                  * a security vulnerability in the terminal emulator or the logging subsystem.
64                 */
65                 public final java.lang.String peer_msg;
66                 private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) {
67                         super(null, ptr);
68                         this.peer_msg = obj.peer_msg;
69                 }
70         }
71         /**
72          * Closure generated from [`ChannelManager::force_close_channel`], called by the user.
73          * 
74          * [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
75          */
76         public final static class HolderForceClosed extends ClosureReason {
77                 private HolderForceClosed(long ptr, bindings.LDKClosureReason.HolderForceClosed obj) {
78                         super(null, ptr);
79                 }
80         }
81         /**
82          * The channel was closed after negotiating a cooperative close and we've now broadcasted
83          * the cooperative close transaction. Note the shutdown may have been initiated by us.
84          */
85         public final static class CooperativeClosure extends ClosureReason {
86                 private CooperativeClosure(long ptr, bindings.LDKClosureReason.CooperativeClosure obj) {
87                         super(null, ptr);
88                 }
89         }
90         /**
91          * A commitment transaction was confirmed on chain, closing the channel. Most likely this
92          * commitment transaction came from our counterparty, but it may also have come from
93          * a copy of our own `ChannelMonitor`.
94          */
95         public final static class CommitmentTxConfirmed extends ClosureReason {
96                 private CommitmentTxConfirmed(long ptr, bindings.LDKClosureReason.CommitmentTxConfirmed obj) {
97                         super(null, ptr);
98                 }
99         }
100         /**
101          * The funding transaction failed to confirm in a timely manner on an inbound channel.
102          */
103         public final static class FundingTimedOut extends ClosureReason {
104                 private FundingTimedOut(long ptr, bindings.LDKClosureReason.FundingTimedOut obj) {
105                         super(null, ptr);
106                 }
107         }
108         /**
109          * Closure generated from processing an event, likely a HTLC forward/relay/reception.
110          */
111         public final static class ProcessingError extends ClosureReason {
112                 /**
113                  * A developer-readable error message which we generated.
114                 */
115                 public final java.lang.String err;
116                 private ProcessingError(long ptr, bindings.LDKClosureReason.ProcessingError obj) {
117                         super(null, ptr);
118                         this.err = obj.err;
119                 }
120         }
121         /**
122          * The peer disconnected prior to funding completing. In this case the spec mandates that we
123          * forget the channel entirely - we can attempt again if the peer reconnects.
124          * 
125          * This includes cases where we restarted prior to funding completion, including prior to the
126          * initial [`ChannelMonitor`] persistence completing.
127          * 
128          * In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
129          * peer because of mutual incompatibility between us and our channel counterparty.
130          * 
131          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
132          */
133         public final static class DisconnectedPeer extends ClosureReason {
134                 private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) {
135                         super(null, ptr);
136                 }
137         }
138         /**
139          * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
140          * the [`ChannelManager`] deserialized.
141          * 
142          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
143          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
144          */
145         public final static class OutdatedChannelManager extends ClosureReason {
146                 private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) {
147                         super(null, ptr);
148                 }
149         }
150         long clone_ptr() {
151                 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
152                 Reference.reachabilityFence(this);
153                 return ret;
154         }
155
156         /**
157          * Creates a copy of the ClosureReason
158          */
159         public ClosureReason clone() {
160                 long ret = bindings.ClosureReason_clone(this.ptr);
161                 Reference.reachabilityFence(this);
162                 if (ret >= 0 && ret <= 4096) { return null; }
163                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
164                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
165                 return ret_hu_conv;
166         }
167
168         /**
169          * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
170          */
171         public static ClosureReason counterparty_force_closed(java.lang.String peer_msg) {
172                 long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg);
173                 Reference.reachabilityFence(peer_msg);
174                 if (ret >= 0 && ret <= 4096) { return null; }
175                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
176                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
177                 return ret_hu_conv;
178         }
179
180         /**
181          * Utility method to constructs a new HolderForceClosed-variant ClosureReason
182          */
183         public static ClosureReason holder_force_closed() {
184                 long ret = bindings.ClosureReason_holder_force_closed();
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
187                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
188                 return ret_hu_conv;
189         }
190
191         /**
192          * Utility method to constructs a new CooperativeClosure-variant ClosureReason
193          */
194         public static ClosureReason cooperative_closure() {
195                 long ret = bindings.ClosureReason_cooperative_closure();
196                 if (ret >= 0 && ret <= 4096) { return null; }
197                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
198                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
199                 return ret_hu_conv;
200         }
201
202         /**
203          * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
204          */
205         public static ClosureReason commitment_tx_confirmed() {
206                 long ret = bindings.ClosureReason_commitment_tx_confirmed();
207                 if (ret >= 0 && ret <= 4096) { return null; }
208                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
209                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
210                 return ret_hu_conv;
211         }
212
213         /**
214          * Utility method to constructs a new FundingTimedOut-variant ClosureReason
215          */
216         public static ClosureReason funding_timed_out() {
217                 long ret = bindings.ClosureReason_funding_timed_out();
218                 if (ret >= 0 && ret <= 4096) { return null; }
219                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
220                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
221                 return ret_hu_conv;
222         }
223
224         /**
225          * Utility method to constructs a new ProcessingError-variant ClosureReason
226          */
227         public static ClosureReason processing_error(java.lang.String err) {
228                 long ret = bindings.ClosureReason_processing_error(err);
229                 Reference.reachabilityFence(err);
230                 if (ret >= 0 && ret <= 4096) { return null; }
231                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
232                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
233                 return ret_hu_conv;
234         }
235
236         /**
237          * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
238          */
239         public static ClosureReason disconnected_peer() {
240                 long ret = bindings.ClosureReason_disconnected_peer();
241                 if (ret >= 0 && ret <= 4096) { return null; }
242                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
243                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
244                 return ret_hu_conv;
245         }
246
247         /**
248          * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
249          */
250         public static ClosureReason outdated_channel_manager() {
251                 long ret = bindings.ClosureReason_outdated_channel_manager();
252                 if (ret >= 0 && ret <= 4096) { return null; }
253                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
254                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
255                 return ret_hu_conv;
256         }
257
258         /**
259          * Checks if two ClosureReasons contain equal inner contents.
260          * This ignores pointers and is_owned flags and looks at the values in fields.
261          */
262         public boolean eq(ClosureReason b) {
263                 boolean ret = bindings.ClosureReason_eq(this.ptr, b == null ? 0 : b.ptr);
264                 Reference.reachabilityFence(this);
265                 Reference.reachabilityFence(b);
266                 return ret;
267         }
268
269         @Override public boolean equals(Object o) {
270                 if (!(o instanceof ClosureReason)) return false;
271                 return this.eq((ClosureReason)o);
272         }
273         /**
274          * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
275          */
276         public byte[] write() {
277                 byte[] ret = bindings.ClosureReason_write(this.ptr);
278                 Reference.reachabilityFence(this);
279                 return ret;
280         }
281
282 }