X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FClosureReason.java;h=b4da105e045e997a61d117cebb9cb333b08783fe;hb=07d5d868dfe064aadb28a7f7ca6002c16be9723d;hp=519ac61be4df5a9b675e65c316b62bdeb0ff52d0;hpb=9aa1eebc40df06586c7ab12f7c8eb22ebcb8b365;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ClosureReason.java b/src/main/java/org/ldk/structs/ClosureReason.java index 519ac61b..b4da105e 100644 --- a/src/main/java/org/ldk/structs/ClosureReason.java +++ b/src/main/java/org/ldk/structs/ClosureReason.java @@ -9,7 +9,7 @@ import javax.annotation.Nullable; /** - * The reason the channel was closed. See individual variants more details. + * The reason the channel was closed. See individual variants for more details. */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ClosureReason extends CommonBase { @@ -45,6 +45,12 @@ public class ClosureReason extends CommonBase { if (raw_val.getClass() == bindings.LDKClosureReason.OutdatedChannelManager.class) { return new OutdatedChannelManager(ptr, (bindings.LDKClosureReason.OutdatedChannelManager)raw_val); } + if (raw_val.getClass() == bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel.class) { + return new CounterpartyCoopClosedUnfundedChannel(ptr, (bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel)raw_val); + } + if (raw_val.getClass() == bindings.LDKClosureReason.FundingBatchClosure.class) { + return new FundingBatchClosure(ptr, (bindings.LDKClosureReason.FundingBatchClosure)raw_val); + } assert false; return null; // Unreachable without extending the (internal) bindings interface } @@ -58,14 +64,19 @@ public class ClosureReason extends CommonBase { /** * The error which the peer sent us. * - * The string should be sanitized before it is used (e.g emitted to logs - * or printed to stdout). Otherwise, a well crafted error message may exploit + * Be careful about printing the peer_msg, a well-crafted message could exploit * a security vulnerability in the terminal emulator or the logging subsystem. + * To be safe, use `Display` on `UntrustedString` + * + * [`UntrustedString`]: crate::util::string::UntrustedString */ - public final java.lang.String peer_msg; + public final org.ldk.structs.UntrustedString peer_msg; private CounterpartyForceClosed(long ptr, bindings.LDKClosureReason.CounterpartyForceClosed obj) { super(null, ptr); - this.peer_msg = obj.peer_msg; + long peer_msg = obj.peer_msg; + 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); } + if (peer_msg_hu_conv != null) { peer_msg_hu_conv.ptrs_to.add(this); }; + this.peer_msg = peer_msg_hu_conv; } } /** @@ -119,11 +130,16 @@ public class ClosureReason extends CommonBase { } } /** - * The `PeerManager` informed us that we've disconnected from the peer. We close channels - * if the `PeerManager` informed us that it is unlikely we'll be able to connect to the - * peer again in the future or if the peer disconnected before we finished negotiating - * the channel open. The first case may be caused by incompatible features which our - * counterparty, or we, require. + * The peer disconnected prior to funding completing. In this case the spec mandates that we + * forget the channel entirely - we can attempt again if the peer reconnects. + * + * This includes cases where we restarted prior to funding completion, including prior to the + * initial [`ChannelMonitor`] persistence completing. + * + * In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the + * peer because of mutual incompatibility between us and our channel counterparty. + * + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor */ public final static class DisconnectedPeer extends ClosureReason { private DisconnectedPeer(long ptr, bindings.LDKClosureReason.DisconnectedPeer obj) { @@ -131,14 +147,35 @@ public class ClosureReason extends CommonBase { } } /** - * Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than - * the ChannelManager deserialized. + * Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than + * the [`ChannelManager`] deserialized. + * + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor + * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager */ public final static class OutdatedChannelManager extends ClosureReason { private OutdatedChannelManager(long ptr, bindings.LDKClosureReason.OutdatedChannelManager obj) { super(null, ptr); } } + /** + * The counterparty requested a cooperative close of a channel that had not been funded yet. + * The channel has been immediately closed. + */ + public final static class CounterpartyCoopClosedUnfundedChannel extends ClosureReason { + private CounterpartyCoopClosedUnfundedChannel(long ptr, bindings.LDKClosureReason.CounterpartyCoopClosedUnfundedChannel obj) { + super(null, ptr); + } + } + /** + * Another channel in the same funding batch closed before the funding transaction + * was ready to be broadcast. + */ + public final static class FundingBatchClosure extends ClosureReason { + private FundingBatchClosure(long ptr, bindings.LDKClosureReason.FundingBatchClosure obj) { + super(null, ptr); + } + } long clone_ptr() { long ret = bindings.ClosureReason_clone_ptr(this.ptr); Reference.reachabilityFence(this); @@ -153,19 +190,20 @@ public class ClosureReason extends CommonBase { Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } /** * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason */ - public static ClosureReason counterparty_force_closed(java.lang.String peer_msg) { - long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg); + public static ClosureReason counterparty_force_closed(org.ldk.structs.UntrustedString peer_msg) { + long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg == null ? 0 : peer_msg.ptr); Reference.reachabilityFence(peer_msg); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(peer_msg); }; return ret_hu_conv; } @@ -176,7 +214,7 @@ public class ClosureReason extends CommonBase { long ret = bindings.ClosureReason_holder_force_closed(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -187,7 +225,7 @@ public class ClosureReason extends CommonBase { long ret = bindings.ClosureReason_cooperative_closure(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -198,7 +236,7 @@ public class ClosureReason extends CommonBase { long ret = bindings.ClosureReason_commitment_tx_confirmed(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -209,7 +247,7 @@ public class ClosureReason extends CommonBase { long ret = bindings.ClosureReason_funding_timed_out(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -221,7 +259,7 @@ public class ClosureReason extends CommonBase { Reference.reachabilityFence(err); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -232,7 +270,7 @@ public class ClosureReason extends CommonBase { long ret = bindings.ClosureReason_disconnected_peer(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -243,10 +281,47 @@ public class ClosureReason extends CommonBase { long ret = bindings.ClosureReason_outdated_channel_manager(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + return ret_hu_conv; + } + + /** + * Utility method to constructs a new CounterpartyCoopClosedUnfundedChannel-variant ClosureReason + */ + public static ClosureReason counterparty_coop_closed_unfunded_channel() { + long ret = bindings.ClosureReason_counterparty_coop_closed_unfunded_channel(); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } + /** + * Utility method to constructs a new FundingBatchClosure-variant ClosureReason + */ + public static ClosureReason funding_batch_closure() { + long ret = bindings.ClosureReason_funding_batch_closure(); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + return ret_hu_conv; + } + + /** + * Checks if two ClosureReasons contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + */ + public boolean eq(org.ldk.structs.ClosureReason b) { + boolean ret = bindings.ClosureReason_eq(this.ptr, b == null ? 0 : b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + return ret; + } + + @Override public boolean equals(Object o) { + if (!(o instanceof ClosureReason)) return false; + return this.eq((ClosureReason)o); + } /** * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read */