1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * The reason the channel was closed. See individual variants for more details.
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 {
20 if (ptr != 0) { bindings.ClosureReason_free(ptr); }
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);
27 if (raw_val.getClass() == bindings.LDKClosureReason.HolderForceClosed.class) {
28 return new HolderForceClosed(ptr, (bindings.LDKClosureReason.HolderForceClosed)raw_val);
30 if (raw_val.getClass() == bindings.LDKClosureReason.LegacyCooperativeClosure.class) {
31 return new LegacyCooperativeClosure(ptr, (bindings.LDKClosureReason.LegacyCooperativeClosure)raw_val);
33 if (raw_val.getClass() == bindings.LDKClosureReason.CounterpartyInitiatedCooperativeClosure.class) {
34 return new CounterpartyInitiatedCooperativeClosure(ptr, (bindings.LDKClosureReason.CounterpartyInitiatedCooperativeClosure)raw_val);
36 if (raw_val.getClass() == bindings.LDKClosureReason.LocallyInitiatedCooperativeClosure.class) {
37 return new LocallyInitiatedCooperativeClosure(ptr, (bindings.LDKClosureReason.LocallyInitiatedCooperativeClosure)raw_val);
39 if (raw_val.getClass() == bindings.LDKClosureReason.CommitmentTxConfirmed.class) {
40 return new CommitmentTxConfirmed(ptr, (bindings.LDKClosureReason.CommitmentTxConfirmed)raw_val);
42 if (raw_val.getClass() == bindings.LDKClosureReason.FundingTimedOut.class) {
43 return new FundingTimedOut(ptr, (bindings.LDKClosureReason.FundingTimedOut)raw_val);
45 if (raw_val.getClass() == bindings.LDKClosureReason.ProcessingError.class) {
46 return new ProcessingError(ptr, (bindings.LDKClosureReason.ProcessingError)raw_val);
48 if (raw_val.getClass() == bindings.LDKClosureReason.DisconnectedPeer.class) {
49 return new DisconnectedPeer(ptr, (bindings.LDKClosureReason.DisconnectedPeer)raw_val);
51 if (raw_val.getClass() == bindings.LDKClosureReason.OutdatedChannelManager.class) {
52 return new OutdatedChannelManager(ptr, (bindings.LDKClosureReason.OutdatedChannelManager)raw_val);
54 if (raw_val.getClass() == bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel.class) {
55 return new CounterpartyCoopClosedUnfundedChannel(ptr, (bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel)raw_val);
57 if (raw_val.getClass() == bindings.LDKClosureReason.FundingBatchClosure.class) {
58 return new FundingBatchClosure(ptr, (bindings.LDKClosureReason.FundingBatchClosure)raw_val);
60 if (raw_val.getClass() == bindings.LDKClosureReason.HTLCsTimedOut.class) {
61 return new HTLCsTimedOut(ptr, (bindings.LDKClosureReason.HTLCsTimedOut)raw_val);
63 assert false; return null; // Unreachable without extending the (internal) bindings interface
67 * Closure generated from receiving a peer error message.
69 * Our counterparty may have broadcasted their latest commitment state, and we have
72 public final static class CounterpartyForceClosed extends ClosureReason {
74 * The error which the peer sent us.
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`
80 * [`UntrustedString`]: crate::util::string::UntrustedString
82 public final org.ldk.structs.UntrustedString peer_msg;
83 private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) {
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;
92 * Closure generated from [`ChannelManager::force_close_channel`], called by the user.
94 * [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
96 public final static class HolderForceClosed extends ClosureReason {
97 private HolderForceClosed(long ptr, bindings.LDKClosureReason.HolderForceClosed obj) {
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.
105 * This was only set in versions of LDK prior to 0.0.122.
107 public final static class LegacyCooperativeClosure extends ClosureReason {
108 private LegacyCooperativeClosure(long ptr, bindings.LDKClosureReason.LegacyCooperativeClosure obj) {
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
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.
120 public final static class CounterpartyInitiatedCooperativeClosure extends ClosureReason {
121 private CounterpartyInitiatedCooperativeClosure(long ptr, bindings.LDKClosureReason.CounterpartyInitiatedCooperativeClosure obj) {
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.
129 public final static class LocallyInitiatedCooperativeClosure extends ClosureReason {
130 private LocallyInitiatedCooperativeClosure(long ptr, bindings.LDKClosureReason.LocallyInitiatedCooperativeClosure obj) {
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`.
139 public final static class CommitmentTxConfirmed extends ClosureReason {
140 private CommitmentTxConfirmed(long ptr, bindings.LDKClosureReason.CommitmentTxConfirmed obj) {
145 * The funding transaction failed to confirm in a timely manner on an inbound channel.
147 public final static class FundingTimedOut extends ClosureReason {
148 private FundingTimedOut(long ptr, bindings.LDKClosureReason.FundingTimedOut obj) {
153 * Closure generated from processing an event, likely a HTLC forward/relay/reception.
155 public final static class ProcessingError extends ClosureReason {
157 * A developer-readable error message which we generated.
159 public final java.lang.String err;
160 private ProcessingError(long ptr, bindings.LDKClosureReason.ProcessingError obj) {
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.
169 * This includes cases where we restarted prior to funding completion, including prior to the
170 * initial [`ChannelMonitor`] persistence completing.
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.
175 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
177 public final static class DisconnectedPeer extends ClosureReason {
178 private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) {
183 * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
184 * the [`ChannelManager`] deserialized.
186 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
187 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
189 public final static class OutdatedChannelManager extends ClosureReason {
190 private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) {
195 * The counterparty requested a cooperative close of a channel that had not been funded yet.
196 * The channel has been immediately closed.
198 public final static class CounterpartyCoopClosedUnfundedChannel extends ClosureReason {
199 private CounterpartyCoopClosedUnfundedChannel(long ptr, bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel obj) {
204 * Another channel in the same funding batch closed before the funding transaction
205 * was ready to be broadcast.
207 public final static class FundingBatchClosure extends ClosureReason {
208 private FundingBatchClosure(long ptr, bindings.LDKClosureReason.FundingBatchClosure obj) {
213 * One of our HTLCs timed out in a channel, causing us to force close the channel.
215 public final static class HTLCsTimedOut extends ClosureReason {
216 private HTLCsTimedOut(long ptr, bindings.LDKClosureReason.HTLCsTimedOut obj) {
221 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
222 Reference.reachabilityFence(this);
227 * Creates a copy of the ClosureReason
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); };
239 * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
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); };
252 * Utility method to constructs a new HolderForceClosed-variant ClosureReason
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); };
263 * Utility method to constructs a new LegacyCooperativeClosure-variant ClosureReason
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); };
274 * Utility method to constructs a new CounterpartyInitiatedCooperativeClosure-variant ClosureReason
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); };
285 * Utility method to constructs a new LocallyInitiatedCooperativeClosure-variant ClosureReason
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); };
296 * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
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); };
307 * Utility method to constructs a new FundingTimedOut-variant ClosureReason
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); };
318 * Utility method to constructs a new ProcessingError-variant ClosureReason
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); };
330 * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
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); };
341 * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
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); };
352 * Utility method to constructs a new CounterpartyCoopClosedUnfundedChannel-variant ClosureReason
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); };
363 * Utility method to constructs a new FundingBatchClosure-variant ClosureReason
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); };
374 * Utility method to constructs a new HTLCsTimedOut-variant ClosureReason
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); };
385 * Checks if two ClosureReasons contain equal inner contents.
386 * This ignores pointers and is_owned flags and looks at the values in fields.
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);
395 @Override public boolean equals(Object o) {
396 if (!(o instanceof ClosureReason)) return false;
397 return this.eq((ClosureReason)o);
400 * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
402 public byte[] write() {
403 byte[] ret = bindings.ClosureReason_write(this.ptr);
404 Reference.reachabilityFence(this);