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 assert false; return null; // Unreachable without extending the (internal) bindings interface
55 * Closure generated from receiving a peer error message.
57 * Our counterparty may have broadcasted their latest commitment state, and we have
60 public final static class CounterpartyForceClosed extends ClosureReason {
62 * The error which the peer sent us.
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`
68 * [`UntrustedString`]: crate::util::string::UntrustedString
70 public final org.ldk.structs.UntrustedString peer_msg;
71 private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) {
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;
80 * Closure generated from [`ChannelManager::force_close_channel`], called by the user.
82 * [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
84 public final static class HolderForceClosed extends ClosureReason {
85 private HolderForceClosed(long ptr, bindings.LDKClosureReason.HolderForceClosed obj) {
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.
93 public final static class CooperativeClosure extends ClosureReason {
94 private CooperativeClosure(long ptr, bindings.LDKClosureReason.CooperativeClosure obj) {
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`.
103 public final static class CommitmentTxConfirmed extends ClosureReason {
104 private CommitmentTxConfirmed(long ptr, bindings.LDKClosureReason.CommitmentTxConfirmed obj) {
109 * The funding transaction failed to confirm in a timely manner on an inbound channel.
111 public final static class FundingTimedOut extends ClosureReason {
112 private FundingTimedOut(long ptr, bindings.LDKClosureReason.FundingTimedOut obj) {
117 * Closure generated from processing an event, likely a HTLC forward/relay/reception.
119 public final static class ProcessingError extends ClosureReason {
121 * A developer-readable error message which we generated.
123 public final java.lang.String err;
124 private ProcessingError(long ptr, bindings.LDKClosureReason.ProcessingError obj) {
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.
133 * This includes cases where we restarted prior to funding completion, including prior to the
134 * initial [`ChannelMonitor`] persistence completing.
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.
139 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
141 public final static class DisconnectedPeer extends ClosureReason {
142 private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) {
147 * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
148 * the [`ChannelManager`] deserialized.
150 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
151 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
153 public final static class OutdatedChannelManager extends ClosureReason {
154 private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) {
159 * The counterparty requested a cooperative close of a channel that had not been funded yet.
160 * The channel has been immediately closed.
162 public final static class CounterpartyCoopClosedUnfundedChannel extends ClosureReason {
163 private CounterpartyCoopClosedUnfundedChannel(long ptr, bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel obj) {
168 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
169 Reference.reachabilityFence(this);
174 * Creates a copy of the ClosureReason
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); };
186 * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
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); };
199 * Utility method to constructs a new HolderForceClosed-variant ClosureReason
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); };
210 * Utility method to constructs a new CooperativeClosure-variant ClosureReason
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); };
221 * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
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); };
232 * Utility method to constructs a new FundingTimedOut-variant ClosureReason
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); };
243 * Utility method to constructs a new ProcessingError-variant ClosureReason
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); };
255 * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
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); };
266 * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
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); };
277 * Utility method to constructs a new CounterpartyCoopClosedUnfundedChannel-variant ClosureReason
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); };
288 * Checks if two ClosureReasons contain equal inner contents.
289 * This ignores pointers and is_owned flags and looks at the values in fields.
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);
298 @Override public boolean equals(Object o) {
299 if (!(o instanceof ClosureReason)) return false;
300 return this.eq((ClosureReason)o);
303 * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
305 public byte[] write() {
306 byte[] ret = bindings.ClosureReason_write(this.ptr);
307 Reference.reachabilityFence(this);