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