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.CooperativeClosure.class) {
31 return new CooperativeClosure(ptr, (bindings.LDKClosureReason.CooperativeClosure)raw_val);
33 if (raw_val.getClass() == bindings.LDKClosureReason.CommitmentTxConfirmed.class) {
34 return new CommitmentTxConfirmed(ptr, (bindings.LDKClosureReason.CommitmentTxConfirmed)raw_val);
36 if (raw_val.getClass() == bindings.LDKClosureReason.FundingTimedOut.class) {
37 return new FundingTimedOut(ptr, (bindings.LDKClosureReason.FundingTimedOut)raw_val);
39 if (raw_val.getClass() == bindings.LDKClosureReason.ProcessingError.class) {
40 return new ProcessingError(ptr, (bindings.LDKClosureReason.ProcessingError)raw_val);
42 if (raw_val.getClass() == bindings.LDKClosureReason.DisconnectedPeer.class) {
43 return new DisconnectedPeer(ptr, (bindings.LDKClosureReason.DisconnectedPeer)raw_val);
45 if (raw_val.getClass() == bindings.LDKClosureReason.OutdatedChannelManager.class) {
46 return new OutdatedChannelManager(ptr, (bindings.LDKClosureReason.OutdatedChannelManager)raw_val);
48 if (raw_val.getClass() == bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel.class) {
49 return new CounterpartyCoopClosedUnfundedChannel(ptr, (bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel)raw_val);
51 if (raw_val.getClass() == bindings.LDKClosureReason.FundingBatchClosure.class) {
52 return new FundingBatchClosure(ptr, (bindings.LDKClosureReason.FundingBatchClosure)raw_val);
54 assert false; return null; // Unreachable without extending the (internal) bindings interface
58 * Closure generated from receiving a peer error message.
60 * Our counterparty may have broadcasted their latest commitment state, and we have
63 public final static class CounterpartyForceClosed extends ClosureReason {
65 * The error which the peer sent us.
67 * Be careful about printing the peer_msg, a well-crafted message could exploit
68 * a security vulnerability in the terminal emulator or the logging subsystem.
69 * To be safe, use `Display` on `UntrustedString`
71 * [`UntrustedString`]: crate::util::string::UntrustedString
73 public final org.ldk.structs.UntrustedString peer_msg;
74 private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) {
76 long peer_msg = obj.peer_msg;
77 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); }
78 if (peer_msg_hu_conv != null) { peer_msg_hu_conv.ptrs_to.add(this); };
79 this.peer_msg = peer_msg_hu_conv;
83 * Closure generated from [`ChannelManager::force_close_channel`], called by the user.
85 * [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
87 public final static class HolderForceClosed extends ClosureReason {
88 private HolderForceClosed(long ptr, bindings.LDKClosureReason.HolderForceClosed obj) {
93 * The channel was closed after negotiating a cooperative close and we've now broadcasted
94 * the cooperative close transaction. Note the shutdown may have been initiated by us.
96 public final static class CooperativeClosure extends ClosureReason {
97 private CooperativeClosure(long ptr, bindings.LDKClosureReason.CooperativeClosure obj) {
102 * A commitment transaction was confirmed on chain, closing the channel. Most likely this
103 * commitment transaction came from our counterparty, but it may also have come from
104 * a copy of our own `ChannelMonitor`.
106 public final static class CommitmentTxConfirmed extends ClosureReason {
107 private CommitmentTxConfirmed(long ptr, bindings.LDKClosureReason.CommitmentTxConfirmed obj) {
112 * The funding transaction failed to confirm in a timely manner on an inbound channel.
114 public final static class FundingTimedOut extends ClosureReason {
115 private FundingTimedOut(long ptr, bindings.LDKClosureReason.FundingTimedOut obj) {
120 * Closure generated from processing an event, likely a HTLC forward/relay/reception.
122 public final static class ProcessingError extends ClosureReason {
124 * A developer-readable error message which we generated.
126 public final java.lang.String err;
127 private ProcessingError(long ptr, bindings.LDKClosureReason.ProcessingError obj) {
133 * The peer disconnected prior to funding completing. In this case the spec mandates that we
134 * forget the channel entirely - we can attempt again if the peer reconnects.
136 * This includes cases where we restarted prior to funding completion, including prior to the
137 * initial [`ChannelMonitor`] persistence completing.
139 * In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
140 * peer because of mutual incompatibility between us and our channel counterparty.
142 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
144 public final static class DisconnectedPeer extends ClosureReason {
145 private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) {
150 * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
151 * the [`ChannelManager`] deserialized.
153 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
154 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
156 public final static class OutdatedChannelManager extends ClosureReason {
157 private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) {
162 * The counterparty requested a cooperative close of a channel that had not been funded yet.
163 * The channel has been immediately closed.
165 public final static class CounterpartyCoopClosedUnfundedChannel extends ClosureReason {
166 private CounterpartyCoopClosedUnfundedChannel(long ptr, bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel obj) {
171 * Another channel in the same funding batch closed before the funding transaction
172 * was ready to be broadcast.
174 public final static class FundingBatchClosure extends ClosureReason {
175 private FundingBatchClosure(long ptr, bindings.LDKClosureReason.FundingBatchClosure obj) {
180 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
181 Reference.reachabilityFence(this);
186 * Creates a copy of the ClosureReason
188 public ClosureReason clone() {
189 long ret = bindings.ClosureReason_clone(this.ptr);
190 Reference.reachabilityFence(this);
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(this); };
198 * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
200 public static ClosureReason counterparty_force_closed(org.ldk.structs.UntrustedString peer_msg) {
201 long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg == null ? 0 : peer_msg.ptr);
202 Reference.reachabilityFence(peer_msg);
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 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(peer_msg); };
211 * Utility method to constructs a new HolderForceClosed-variant ClosureReason
213 public static ClosureReason holder_force_closed() {
214 long ret = bindings.ClosureReason_holder_force_closed();
215 if (ret >= 0 && ret <= 4096) { return null; }
216 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
217 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
222 * Utility method to constructs a new CooperativeClosure-variant ClosureReason
224 public static ClosureReason cooperative_closure() {
225 long ret = bindings.ClosureReason_cooperative_closure();
226 if (ret >= 0 && ret <= 4096) { return null; }
227 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
228 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
233 * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
235 public static ClosureReason commitment_tx_confirmed() {
236 long ret = bindings.ClosureReason_commitment_tx_confirmed();
237 if (ret >= 0 && ret <= 4096) { return null; }
238 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
239 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
244 * Utility method to constructs a new FundingTimedOut-variant ClosureReason
246 public static ClosureReason funding_timed_out() {
247 long ret = bindings.ClosureReason_funding_timed_out();
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); };
255 * Utility method to constructs a new ProcessingError-variant ClosureReason
257 public static ClosureReason processing_error(java.lang.String err) {
258 long ret = bindings.ClosureReason_processing_error(err);
259 Reference.reachabilityFence(err);
260 if (ret >= 0 && ret <= 4096) { return null; }
261 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
262 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
267 * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
269 public static ClosureReason disconnected_peer() {
270 long ret = bindings.ClosureReason_disconnected_peer();
271 if (ret >= 0 && ret <= 4096) { return null; }
272 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
273 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
278 * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
280 public static ClosureReason outdated_channel_manager() {
281 long ret = bindings.ClosureReason_outdated_channel_manager();
282 if (ret >= 0 && ret <= 4096) { return null; }
283 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
284 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
289 * Utility method to constructs a new CounterpartyCoopClosedUnfundedChannel-variant ClosureReason
291 public static ClosureReason counterparty_coop_closed_unfunded_channel() {
292 long ret = bindings.ClosureReason_counterparty_coop_closed_unfunded_channel();
293 if (ret >= 0 && ret <= 4096) { return null; }
294 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
295 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
300 * Utility method to constructs a new FundingBatchClosure-variant ClosureReason
302 public static ClosureReason funding_batch_closure() {
303 long ret = bindings.ClosureReason_funding_batch_closure();
304 if (ret >= 0 && ret <= 4096) { return null; }
305 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
306 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
311 * Checks if two ClosureReasons contain equal inner contents.
312 * This ignores pointers and is_owned flags and looks at the values in fields.
314 public boolean eq(org.ldk.structs.ClosureReason b) {
315 boolean ret = bindings.ClosureReason_eq(this.ptr, b == null ? 0 : b.ptr);
316 Reference.reachabilityFence(this);
317 Reference.reachabilityFence(b);
321 @Override public boolean equals(Object o) {
322 if (!(o instanceof ClosureReason)) return false;
323 return this.eq((ClosureReason)o);
326 * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
328 public byte[] write() {
329 byte[] ret = bindings.ClosureReason_write(this.ptr);
330 Reference.reachabilityFence(this);