6 namespace org { namespace ldk { namespace structs {
9 * The reason the channel was closed. See individual variants for more details.
11 public class ClosureReason : CommonBase {
12 protected ClosureReason(object _dummy, long ptr) : base(ptr) { }
14 if (ptr != 0) { bindings.ClosureReason_free(ptr); }
17 internal static ClosureReason constr_from_ptr(long ptr) {
18 long raw_ty = bindings.LDKClosureReason_ty_from_ptr(ptr);
20 case 0: return new ClosureReason_CounterpartyForceClosed(ptr);
21 case 1: return new ClosureReason_HolderForceClosed(ptr);
22 case 2: return new ClosureReason_CooperativeClosure(ptr);
23 case 3: return new ClosureReason_CommitmentTxConfirmed(ptr);
24 case 4: return new ClosureReason_FundingTimedOut(ptr);
25 case 5: return new ClosureReason_ProcessingError(ptr);
26 case 6: return new ClosureReason_DisconnectedPeer(ptr);
27 case 7: return new ClosureReason_OutdatedChannelManager(ptr);
28 case 8: return new ClosureReason_CounterpartyCoopClosedUnfundedChannel(ptr);
30 throw new ArgumentException("Impossible enum variant");
34 /** A ClosureReason of type CounterpartyForceClosed */
35 public class ClosureReason_CounterpartyForceClosed : ClosureReason {
37 * The error which the peer sent us.
39 * Be careful about printing the peer_msg, a well-crafted message could exploit
40 * a security vulnerability in the terminal emulator or the logging subsystem.
41 * To be safe, use `Display` on `UntrustedString`
43 * [`UntrustedString`]: crate::util::string::UntrustedString
45 public UntrustedString peer_msg;
46 internal ClosureReason_CounterpartyForceClosed(long ptr) : base(null, ptr) {
47 long peer_msg = bindings.LDKClosureReason_CounterpartyForceClosed_get_peer_msg(ptr);
48 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); }
49 if (peer_msg_hu_conv != null) { peer_msg_hu_conv.ptrs_to.AddLast(this); };
50 this.peer_msg = peer_msg_hu_conv;
53 /** A ClosureReason of type HolderForceClosed */
54 public class ClosureReason_HolderForceClosed : ClosureReason {
55 internal ClosureReason_HolderForceClosed(long ptr) : base(null, ptr) {
58 /** A ClosureReason of type CooperativeClosure */
59 public class ClosureReason_CooperativeClosure : ClosureReason {
60 internal ClosureReason_CooperativeClosure(long ptr) : base(null, ptr) {
63 /** A ClosureReason of type CommitmentTxConfirmed */
64 public class ClosureReason_CommitmentTxConfirmed : ClosureReason {
65 internal ClosureReason_CommitmentTxConfirmed(long ptr) : base(null, ptr) {
68 /** A ClosureReason of type FundingTimedOut */
69 public class ClosureReason_FundingTimedOut : ClosureReason {
70 internal ClosureReason_FundingTimedOut(long ptr) : base(null, ptr) {
73 /** A ClosureReason of type ProcessingError */
74 public class ClosureReason_ProcessingError : ClosureReason {
76 * A developer-readable error message which we generated.
79 internal ClosureReason_ProcessingError(long ptr) : base(null, ptr) {
80 this.err = bindings.LDKClosureReason_ProcessingError_get_err(ptr);
83 /** A ClosureReason of type DisconnectedPeer */
84 public class ClosureReason_DisconnectedPeer : ClosureReason {
85 internal ClosureReason_DisconnectedPeer(long ptr) : base(null, ptr) {
88 /** A ClosureReason of type OutdatedChannelManager */
89 public class ClosureReason_OutdatedChannelManager : ClosureReason {
90 internal ClosureReason_OutdatedChannelManager(long ptr) : base(null, ptr) {
93 /** A ClosureReason of type CounterpartyCoopClosedUnfundedChannel */
94 public class ClosureReason_CounterpartyCoopClosedUnfundedChannel : ClosureReason {
95 internal ClosureReason_CounterpartyCoopClosedUnfundedChannel(long ptr) : base(null, ptr) {
98 internal long clone_ptr() {
99 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
105 * Creates a copy of the ClosureReason
107 public ClosureReason clone() {
108 long ret = bindings.ClosureReason_clone(this.ptr);
110 if (ret >= 0 && ret <= 4096) { return null; }
111 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
112 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
117 * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
119 public static ClosureReason counterparty_force_closed(org.ldk.structs.UntrustedString peer_msg) {
120 long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg == null ? 0 : peer_msg.ptr);
121 GC.KeepAlive(peer_msg);
122 if (ret >= 0 && ret <= 4096) { return null; }
123 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
124 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
125 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(peer_msg); };
130 * Utility method to constructs a new HolderForceClosed-variant ClosureReason
132 public static ClosureReason holder_force_closed() {
133 long ret = bindings.ClosureReason_holder_force_closed();
134 if (ret >= 0 && ret <= 4096) { return null; }
135 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
136 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
141 * Utility method to constructs a new CooperativeClosure-variant ClosureReason
143 public static ClosureReason cooperative_closure() {
144 long ret = bindings.ClosureReason_cooperative_closure();
145 if (ret >= 0 && ret <= 4096) { return null; }
146 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
147 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
152 * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
154 public static ClosureReason commitment_tx_confirmed() {
155 long ret = bindings.ClosureReason_commitment_tx_confirmed();
156 if (ret >= 0 && ret <= 4096) { return null; }
157 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
158 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
163 * Utility method to constructs a new FundingTimedOut-variant ClosureReason
165 public static ClosureReason funding_timed_out() {
166 long ret = bindings.ClosureReason_funding_timed_out();
167 if (ret >= 0 && ret <= 4096) { return null; }
168 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
169 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
174 * Utility method to constructs a new ProcessingError-variant ClosureReason
176 public static ClosureReason processing_error(string err) {
177 long ret = bindings.ClosureReason_processing_error(err);
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.AddLast(ret_hu_conv); };
186 * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
188 public static ClosureReason disconnected_peer() {
189 long ret = bindings.ClosureReason_disconnected_peer();
190 if (ret >= 0 && ret <= 4096) { return null; }
191 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
192 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
197 * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
199 public static ClosureReason outdated_channel_manager() {
200 long ret = bindings.ClosureReason_outdated_channel_manager();
201 if (ret >= 0 && ret <= 4096) { return null; }
202 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
203 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
208 * Utility method to constructs a new CounterpartyCoopClosedUnfundedChannel-variant ClosureReason
210 public static ClosureReason counterparty_coop_closed_unfunded_channel() {
211 long ret = bindings.ClosureReason_counterparty_coop_closed_unfunded_channel();
212 if (ret >= 0 && ret <= 4096) { return null; }
213 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
214 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
219 * Checks if two ClosureReasons contain equal inner contents.
220 * This ignores pointers and is_owned flags and looks at the values in fields.
222 public bool eq(org.ldk.structs.ClosureReason b) {
223 bool ret = bindings.ClosureReason_eq(this.ptr, b == null ? 0 : b.ptr);
229 public override bool Equals(object o) {
230 if (!(o is ClosureReason)) return false;
231 return this.eq((ClosureReason)o);
234 * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
236 public byte[] write() {
237 byte[] ret = bindings.ClosureReason_write(this.ptr);