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 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 assert false; return null; // Unreachable without extending the (internal) bindings interface
52 * Closure generated from receiving a peer error message.
54 * Our counterparty may have broadcasted their latest commitment state, and we have
57 public final static class CounterpartyForceClosed extends ClosureReason {
59 * The error which the peer sent us.
61 * The string should be sanitized before it is used (e.g emitted to logs
62 * or printed to stdout). Otherwise, a well crafted error message may exploit
63 * a security vulnerability in the terminal emulator or the logging subsystem.
65 public final java.lang.String peer_msg;
66 private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) {
68 this.peer_msg = obj.peer_msg;
72 * Closure generated from [`ChannelManager::force_close_channel`], called by the user.
74 * [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
76 public final static class HolderForceClosed extends ClosureReason {
77 private HolderForceClosed(long ptr, bindings.LDKClosureReason.HolderForceClosed obj) {
82 * The channel was closed after negotiating a cooperative close and we've now broadcasted
83 * the cooperative close transaction. Note the shutdown may have been initiated by us.
85 public final static class CooperativeClosure extends ClosureReason {
86 private CooperativeClosure(long ptr, bindings.LDKClosureReason.CooperativeClosure obj) {
91 * A commitment transaction was confirmed on chain, closing the channel. Most likely this
92 * commitment transaction came from our counterparty, but it may also have come from
93 * a copy of our own `ChannelMonitor`.
95 public final static class CommitmentTxConfirmed extends ClosureReason {
96 private CommitmentTxConfirmed(long ptr, bindings.LDKClosureReason.CommitmentTxConfirmed obj) {
101 * The funding transaction failed to confirm in a timely manner on an inbound channel.
103 public final static class FundingTimedOut extends ClosureReason {
104 private FundingTimedOut(long ptr, bindings.LDKClosureReason.FundingTimedOut obj) {
109 * Closure generated from processing an event, likely a HTLC forward/relay/reception.
111 public final static class ProcessingError extends ClosureReason {
113 * A developer-readable error message which we generated.
115 public final java.lang.String err;
116 private ProcessingError(long ptr, bindings.LDKClosureReason.ProcessingError obj) {
122 * The peer disconnected prior to funding completing. In this case the spec mandates that we
123 * forget the channel entirely - we can attempt again if the peer reconnects.
125 * This includes cases where we restarted prior to funding completion, including prior to the
126 * initial [`ChannelMonitor`] persistence completing.
128 * In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
129 * peer because of mutual incompatibility between us and our channel counterparty.
131 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
133 public final static class DisconnectedPeer extends ClosureReason {
134 private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) {
139 * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
140 * the [`ChannelManager`] deserialized.
142 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
143 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
145 public final static class OutdatedChannelManager extends ClosureReason {
146 private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) {
151 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
152 Reference.reachabilityFence(this);
157 * Creates a copy of the ClosureReason
159 public ClosureReason clone() {
160 long ret = bindings.ClosureReason_clone(this.ptr);
161 Reference.reachabilityFence(this);
162 if (ret >= 0 && ret <= 4096) { return null; }
163 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
164 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
169 * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
171 public static ClosureReason counterparty_force_closed(java.lang.String peer_msg) {
172 long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg);
173 Reference.reachabilityFence(peer_msg);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
176 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
181 * Utility method to constructs a new HolderForceClosed-variant ClosureReason
183 public static ClosureReason holder_force_closed() {
184 long ret = bindings.ClosureReason_holder_force_closed();
185 if (ret >= 0 && ret <= 4096) { return null; }
186 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
187 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
192 * Utility method to constructs a new CooperativeClosure-variant ClosureReason
194 public static ClosureReason cooperative_closure() {
195 long ret = bindings.ClosureReason_cooperative_closure();
196 if (ret >= 0 && ret <= 4096) { return null; }
197 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
198 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
203 * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
205 public static ClosureReason commitment_tx_confirmed() {
206 long ret = bindings.ClosureReason_commitment_tx_confirmed();
207 if (ret >= 0 && ret <= 4096) { return null; }
208 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
209 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
214 * Utility method to constructs a new FundingTimedOut-variant ClosureReason
216 public static ClosureReason funding_timed_out() {
217 long ret = bindings.ClosureReason_funding_timed_out();
218 if (ret >= 0 && ret <= 4096) { return null; }
219 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
220 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
225 * Utility method to constructs a new ProcessingError-variant ClosureReason
227 public static ClosureReason processing_error(java.lang.String err) {
228 long ret = bindings.ClosureReason_processing_error(err);
229 Reference.reachabilityFence(err);
230 if (ret >= 0 && ret <= 4096) { return null; }
231 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
232 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
237 * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
239 public static ClosureReason disconnected_peer() {
240 long ret = bindings.ClosureReason_disconnected_peer();
241 if (ret >= 0 && ret <= 4096) { return null; }
242 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
243 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
248 * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
250 public static ClosureReason outdated_channel_manager() {
251 long ret = bindings.ClosureReason_outdated_channel_manager();
252 if (ret >= 0 && ret <= 4096) { return null; }
253 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
254 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
259 * Checks if two ClosureReasons contain equal inner contents.
260 * This ignores pointers and is_owned flags and looks at the values in fields.
262 public boolean eq(ClosureReason b) {
263 boolean ret = bindings.ClosureReason_eq(this.ptr, b == null ? 0 : b.ptr);
264 Reference.reachabilityFence(this);
265 Reference.reachabilityFence(b);
269 @Override public boolean equals(Object o) {
270 if (!(o instanceof ClosureReason)) return false;
271 return this.eq((ClosureReason)o);
274 * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
276 public byte[] write() {
277 byte[] ret = bindings.ClosureReason_write(this.ptr);
278 Reference.reachabilityFence(this);