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