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 * In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
126 * peer because of mutual incompatibility between us and our channel counterparty.
128 public final static class DisconnectedPeer extends ClosureReason {
129 private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) {
134 * Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
135 * the ChannelManager deserialized.
137 public final static class OutdatedChannelManager extends ClosureReason {
138 private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) {
143 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
144 Reference.reachabilityFence(this);
149 * Creates a copy of the ClosureReason
151 public ClosureReason clone() {
152 long ret = bindings.ClosureReason_clone(this.ptr);
153 Reference.reachabilityFence(this);
154 if (ret >= 0 && ret <= 4096) { return null; }
155 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
156 ret_hu_conv.ptrs_to.add(this);
161 * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
163 public static ClosureReason counterparty_force_closed(java.lang.String peer_msg) {
164 long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg);
165 Reference.reachabilityFence(peer_msg);
166 if (ret >= 0 && ret <= 4096) { return null; }
167 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
168 ret_hu_conv.ptrs_to.add(ret_hu_conv);
173 * Utility method to constructs a new HolderForceClosed-variant ClosureReason
175 public static ClosureReason holder_force_closed() {
176 long ret = bindings.ClosureReason_holder_force_closed();
177 if (ret >= 0 && ret <= 4096) { return null; }
178 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
179 ret_hu_conv.ptrs_to.add(ret_hu_conv);
184 * Utility method to constructs a new CooperativeClosure-variant ClosureReason
186 public static ClosureReason cooperative_closure() {
187 long ret = bindings.ClosureReason_cooperative_closure();
188 if (ret >= 0 && ret <= 4096) { return null; }
189 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
190 ret_hu_conv.ptrs_to.add(ret_hu_conv);
195 * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
197 public static ClosureReason commitment_tx_confirmed() {
198 long ret = bindings.ClosureReason_commitment_tx_confirmed();
199 if (ret >= 0 && ret <= 4096) { return null; }
200 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
201 ret_hu_conv.ptrs_to.add(ret_hu_conv);
206 * Utility method to constructs a new FundingTimedOut-variant ClosureReason
208 public static ClosureReason funding_timed_out() {
209 long ret = bindings.ClosureReason_funding_timed_out();
210 if (ret >= 0 && ret <= 4096) { return null; }
211 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
212 ret_hu_conv.ptrs_to.add(ret_hu_conv);
217 * Utility method to constructs a new ProcessingError-variant ClosureReason
219 public static ClosureReason processing_error(java.lang.String err) {
220 long ret = bindings.ClosureReason_processing_error(err);
221 Reference.reachabilityFence(err);
222 if (ret >= 0 && ret <= 4096) { return null; }
223 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
224 ret_hu_conv.ptrs_to.add(ret_hu_conv);
229 * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
231 public static ClosureReason disconnected_peer() {
232 long ret = bindings.ClosureReason_disconnected_peer();
233 if (ret >= 0 && ret <= 4096) { return null; }
234 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
235 ret_hu_conv.ptrs_to.add(ret_hu_conv);
240 * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
242 public static ClosureReason outdated_channel_manager() {
243 long ret = bindings.ClosureReason_outdated_channel_manager();
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 ret_hu_conv.ptrs_to.add(ret_hu_conv);
251 * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
253 public byte[] write() {
254 byte[] ret = bindings.ClosureReason_write(this.ptr);
255 Reference.reachabilityFence(this);