46160fd1ce9970cbd3ac475f98a2c7d929aa1e84
[ldk-java] / c_sharp / src / org / ldk / structs / ClosureReason.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * The reason the channel was closed. See individual variants more details.
10  */
11 public class ClosureReason : CommonBase {
12         protected ClosureReason(object _dummy, long ptr) : base(ptr) { }
13         ~ClosureReason() {
14                 if (ptr != 0) { bindings.ClosureReason_free(ptr); }
15         }
16
17         internal static ClosureReason constr_from_ptr(long ptr) {
18                 long raw_ty = bindings.LDKClosureReason_ty_from_ptr(ptr);
19                 switch (raw_ty) {
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                         default:
29                                 throw new ArgumentException("Impossible enum variant");
30                 }
31         }
32
33         /** A ClosureReason of type CounterpartyForceClosed */
34         public class ClosureReason_CounterpartyForceClosed : ClosureReason {
35                 /**
36                  * The error which the peer sent us.
37                  * 
38                  * The string should be sanitized before it is used (e.g emitted to logs
39                  * or printed to stdout). Otherwise, a well crafted error message may exploit
40                  * a security vulnerability in the terminal emulator or the logging subsystem.
41                  */
42                 public string peer_msg;
43                 internal ClosureReason_CounterpartyForceClosed(long ptr) : base(null, ptr) {
44                         this.peer_msg = bindings.LDKClosureReason_CounterpartyForceClosed_get_peer_msg(ptr);
45                 }
46         }
47         /** A ClosureReason of type HolderForceClosed */
48         public class ClosureReason_HolderForceClosed : ClosureReason {
49                 internal ClosureReason_HolderForceClosed(long ptr) : base(null, ptr) {
50                 }
51         }
52         /** A ClosureReason of type CooperativeClosure */
53         public class ClosureReason_CooperativeClosure : ClosureReason {
54                 internal ClosureReason_CooperativeClosure(long ptr) : base(null, ptr) {
55                 }
56         }
57         /** A ClosureReason of type CommitmentTxConfirmed */
58         public class ClosureReason_CommitmentTxConfirmed : ClosureReason {
59                 internal ClosureReason_CommitmentTxConfirmed(long ptr) : base(null, ptr) {
60                 }
61         }
62         /** A ClosureReason of type FundingTimedOut */
63         public class ClosureReason_FundingTimedOut : ClosureReason {
64                 internal ClosureReason_FundingTimedOut(long ptr) : base(null, ptr) {
65                 }
66         }
67         /** A ClosureReason of type ProcessingError */
68         public class ClosureReason_ProcessingError : ClosureReason {
69                 /**
70                  * A developer-readable error message which we generated.
71                  */
72                 public string err;
73                 internal ClosureReason_ProcessingError(long ptr) : base(null, ptr) {
74                         this.err = bindings.LDKClosureReason_ProcessingError_get_err(ptr);
75                 }
76         }
77         /** A ClosureReason of type DisconnectedPeer */
78         public class ClosureReason_DisconnectedPeer : ClosureReason {
79                 internal ClosureReason_DisconnectedPeer(long ptr) : base(null, ptr) {
80                 }
81         }
82         /** A ClosureReason of type OutdatedChannelManager */
83         public class ClosureReason_OutdatedChannelManager : ClosureReason {
84                 internal ClosureReason_OutdatedChannelManager(long ptr) : base(null, ptr) {
85                 }
86         }
87         internal long clone_ptr() {
88                 long ret = bindings.ClosureReason_clone_ptr(this.ptr);
89                 GC.KeepAlive(this);
90                 return ret;
91         }
92
93         /**
94          * Creates a copy of the ClosureReason
95          */
96         public ClosureReason clone() {
97                 long ret = bindings.ClosureReason_clone(this.ptr);
98                 GC.KeepAlive(this);
99                 if (ret >= 0 && ret <= 4096) { return null; }
100                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
101                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
102                 return ret_hu_conv;
103         }
104
105         /**
106          * Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
107          */
108         public static ClosureReason counterparty_force_closed(string peer_msg) {
109                 long ret = bindings.ClosureReason_counterparty_force_closed(peer_msg);
110                 GC.KeepAlive(peer_msg);
111                 if (ret >= 0 && ret <= 4096) { return null; }
112                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
113                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Utility method to constructs a new HolderForceClosed-variant ClosureReason
119          */
120         public static ClosureReason holder_force_closed() {
121                 long ret = bindings.ClosureReason_holder_force_closed();
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                 return ret_hu_conv;
126         }
127
128         /**
129          * Utility method to constructs a new CooperativeClosure-variant ClosureReason
130          */
131         public static ClosureReason cooperative_closure() {
132                 long ret = bindings.ClosureReason_cooperative_closure();
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
135                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
136                 return ret_hu_conv;
137         }
138
139         /**
140          * Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
141          */
142         public static ClosureReason commitment_tx_confirmed() {
143                 long ret = bindings.ClosureReason_commitment_tx_confirmed();
144                 if (ret >= 0 && ret <= 4096) { return null; }
145                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
146                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
147                 return ret_hu_conv;
148         }
149
150         /**
151          * Utility method to constructs a new FundingTimedOut-variant ClosureReason
152          */
153         public static ClosureReason funding_timed_out() {
154                 long ret = bindings.ClosureReason_funding_timed_out();
155                 if (ret >= 0 && ret <= 4096) { return null; }
156                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
157                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
158                 return ret_hu_conv;
159         }
160
161         /**
162          * Utility method to constructs a new ProcessingError-variant ClosureReason
163          */
164         public static ClosureReason processing_error(string err) {
165                 long ret = bindings.ClosureReason_processing_error(err);
166                 GC.KeepAlive(err);
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); };
170                 return ret_hu_conv;
171         }
172
173         /**
174          * Utility method to constructs a new DisconnectedPeer-variant ClosureReason
175          */
176         public static ClosureReason disconnected_peer() {
177                 long ret = bindings.ClosureReason_disconnected_peer();
178                 if (ret >= 0 && ret <= 4096) { return null; }
179                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
180                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
181                 return ret_hu_conv;
182         }
183
184         /**
185          * Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
186          */
187         public static ClosureReason outdated_channel_manager() {
188                 long ret = bindings.ClosureReason_outdated_channel_manager();
189                 if (ret >= 0 && ret <= 4096) { return null; }
190                 org.ldk.structs.ClosureReason ret_hu_conv = org.ldk.structs.ClosureReason.constr_from_ptr(ret);
191                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
192                 return ret_hu_conv;
193         }
194
195         /**
196          * Checks if two ClosureReasons contain equal inner contents.
197          * This ignores pointers and is_owned flags and looks at the values in fields.
198          */
199         public bool eq(org.ldk.structs.ClosureReason b) {
200                 bool ret = bindings.ClosureReason_eq(this.ptr, b == null ? 0 : b.ptr);
201                 GC.KeepAlive(this);
202                 GC.KeepAlive(b);
203                 return ret;
204         }
205
206         public override bool Equals(object o) {
207                 if (!(o is ClosureReason)) return false;
208                 return this.eq((ClosureReason)o);
209         }
210         /**
211          * Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
212          */
213         public byte[] write() {
214                 byte[] ret = bindings.ClosureReason_write(this.ptr);
215                 GC.KeepAlive(this);
216                 return ret;
217         }
218
219 }
220 } } }