3214edf09671f9756435ccd34f40fe2245c05c29
[ldk-java] / c_sharp / src / org / ldk / structs / Balance.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  * Details about the balance(s) available for spending once the channel appears on chain.
10  * 
11  * See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
12  * be provided.
13  */
14 public class Balance : CommonBase {
15         protected Balance(object _dummy, long ptr) : base(ptr) { }
16         ~Balance() {
17                 if (ptr != 0) { bindings.Balance_free(ptr); }
18         }
19
20         internal static Balance constr_from_ptr(long ptr) {
21                 long raw_ty = bindings.LDKBalance_ty_from_ptr(ptr);
22                 switch (raw_ty) {
23                         case 0: return new Balance_ClaimableOnChannelClose(ptr);
24                         case 1: return new Balance_ClaimableAwaitingConfirmations(ptr);
25                         case 2: return new Balance_ContentiousClaimable(ptr);
26                         case 3: return new Balance_MaybeTimeoutClaimableHTLC(ptr);
27                         case 4: return new Balance_MaybePreimageClaimableHTLC(ptr);
28                         case 5: return new Balance_CounterpartyRevokedOutputClaimable(ptr);
29                         default:
30                                 throw new ArgumentException("Impossible enum variant");
31                 }
32         }
33
34         /** A Balance of type ClaimableOnChannelClose */
35         public class Balance_ClaimableOnChannelClose : Balance {
36                 /**
37                  * The amount available to claim, in satoshis, excluding the on-chain fees which will be
38                  * required to do so.
39                  */
40                 public long claimable_amount_satoshis;
41                 internal Balance_ClaimableOnChannelClose(long ptr) : base(null, ptr) {
42                         this.claimable_amount_satoshis = bindings.LDKBalance_ClaimableOnChannelClose_get_claimable_amount_satoshis(ptr);
43                 }
44         }
45         /** A Balance of type ClaimableAwaitingConfirmations */
46         public class Balance_ClaimableAwaitingConfirmations : Balance {
47                 /**
48                  * The amount available to claim, in satoshis, possibly excluding the on-chain fees which
49                  * were spent in broadcasting the transaction.
50                  */
51                 public long claimable_amount_satoshis;
52                 /**
53                  * The height at which an [`Event::SpendableOutputs`] event will be generated for this
54                  * amount.
55                  */
56                 public int confirmation_height;
57                 internal Balance_ClaimableAwaitingConfirmations(long ptr) : base(null, ptr) {
58                         this.claimable_amount_satoshis = bindings.LDKBalance_ClaimableAwaitingConfirmations_get_claimable_amount_satoshis(ptr);
59                         this.confirmation_height = bindings.LDKBalance_ClaimableAwaitingConfirmations_get_confirmation_height(ptr);
60                 }
61         }
62         /** A Balance of type ContentiousClaimable */
63         public class Balance_ContentiousClaimable : Balance {
64                 /**
65                  * The amount available to claim, in satoshis, excluding the on-chain fees which will be
66                  * required to do so.
67                  */
68                 public long claimable_amount_satoshis;
69                 /**
70                  * The height at which the counterparty may be able to claim the balance if we have not
71                  * done so.
72                  */
73                 public int timeout_height;
74                 internal Balance_ContentiousClaimable(long ptr) : base(null, ptr) {
75                         this.claimable_amount_satoshis = bindings.LDKBalance_ContentiousClaimable_get_claimable_amount_satoshis(ptr);
76                         this.timeout_height = bindings.LDKBalance_ContentiousClaimable_get_timeout_height(ptr);
77                 }
78         }
79         /** A Balance of type MaybeTimeoutClaimableHTLC */
80         public class Balance_MaybeTimeoutClaimableHTLC : Balance {
81                 /**
82                  * The amount potentially available to claim, in satoshis, excluding the on-chain fees
83                  * which will be required to do so.
84                  */
85                 public long claimable_amount_satoshis;
86                 /**
87                  * The height at which we will be able to claim the balance if our counterparty has not
88                  * done so.
89                  */
90                 public int claimable_height;
91                 internal Balance_MaybeTimeoutClaimableHTLC(long ptr) : base(null, ptr) {
92                         this.claimable_amount_satoshis = bindings.LDKBalance_MaybeTimeoutClaimableHTLC_get_claimable_amount_satoshis(ptr);
93                         this.claimable_height = bindings.LDKBalance_MaybeTimeoutClaimableHTLC_get_claimable_height(ptr);
94                 }
95         }
96         /** A Balance of type MaybePreimageClaimableHTLC */
97         public class Balance_MaybePreimageClaimableHTLC : Balance {
98                 /**
99                  * The amount potentially available to claim, in satoshis, excluding the on-chain fees
100                  * which will be required to do so.
101                  */
102                 public long claimable_amount_satoshis;
103                 /**
104                  * The height at which our counterparty will be able to claim the balance if we have not
105                  * yet received the preimage and claimed it ourselves.
106                  */
107                 public int expiry_height;
108                 internal Balance_MaybePreimageClaimableHTLC(long ptr) : base(null, ptr) {
109                         this.claimable_amount_satoshis = bindings.LDKBalance_MaybePreimageClaimableHTLC_get_claimable_amount_satoshis(ptr);
110                         this.expiry_height = bindings.LDKBalance_MaybePreimageClaimableHTLC_get_expiry_height(ptr);
111                 }
112         }
113         /** A Balance of type CounterpartyRevokedOutputClaimable */
114         public class Balance_CounterpartyRevokedOutputClaimable : Balance {
115                 /**
116                  * The amount, in satoshis, of the output which we can claim.
117                  * 
118                  * Note that for outputs from HTLC balances this may be excluding some on-chain fees that
119                  * were already spent.
120                  */
121                 public long claimable_amount_satoshis;
122                 internal Balance_CounterpartyRevokedOutputClaimable(long ptr) : base(null, ptr) {
123                         this.claimable_amount_satoshis = bindings.LDKBalance_CounterpartyRevokedOutputClaimable_get_claimable_amount_satoshis(ptr);
124                 }
125         }
126         internal long clone_ptr() {
127                 long ret = bindings.Balance_clone_ptr(this.ptr);
128                 GC.KeepAlive(this);
129                 return ret;
130         }
131
132         /**
133          * Creates a copy of the Balance
134          */
135         public Balance clone() {
136                 long ret = bindings.Balance_clone(this.ptr);
137                 GC.KeepAlive(this);
138                 if (ret >= 0 && ret <= 4096) { return null; }
139                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
140                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
141                 return ret_hu_conv;
142         }
143
144         /**
145          * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
146          */
147         public static Balance claimable_on_channel_close(long claimable_amount_satoshis) {
148                 long ret = bindings.Balance_claimable_on_channel_close(claimable_amount_satoshis);
149                 GC.KeepAlive(claimable_amount_satoshis);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
152                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
153                 return ret_hu_conv;
154         }
155
156         /**
157          * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
158          */
159         public static Balance claimable_awaiting_confirmations(long claimable_amount_satoshis, int confirmation_height) {
160                 long ret = bindings.Balance_claimable_awaiting_confirmations(claimable_amount_satoshis, confirmation_height);
161                 GC.KeepAlive(claimable_amount_satoshis);
162                 GC.KeepAlive(confirmation_height);
163                 if (ret >= 0 && ret <= 4096) { return null; }
164                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
165                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
166                 return ret_hu_conv;
167         }
168
169         /**
170          * Utility method to constructs a new ContentiousClaimable-variant Balance
171          */
172         public static Balance contentious_claimable(long claimable_amount_satoshis, int timeout_height) {
173                 long ret = bindings.Balance_contentious_claimable(claimable_amount_satoshis, timeout_height);
174                 GC.KeepAlive(claimable_amount_satoshis);
175                 GC.KeepAlive(timeout_height);
176                 if (ret >= 0 && ret <= 4096) { return null; }
177                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
178                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
179                 return ret_hu_conv;
180         }
181
182         /**
183          * Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
184          */
185         public static Balance maybe_timeout_claimable_htlc(long claimable_amount_satoshis, int claimable_height) {
186                 long ret = bindings.Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis, claimable_height);
187                 GC.KeepAlive(claimable_amount_satoshis);
188                 GC.KeepAlive(claimable_height);
189                 if (ret >= 0 && ret <= 4096) { return null; }
190                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.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          * Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
197          */
198         public static Balance maybe_preimage_claimable_htlc(long claimable_amount_satoshis, int expiry_height) {
199                 long ret = bindings.Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis, expiry_height);
200                 GC.KeepAlive(claimable_amount_satoshis);
201                 GC.KeepAlive(expiry_height);
202                 if (ret >= 0 && ret <= 4096) { return null; }
203                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
204                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
205                 return ret_hu_conv;
206         }
207
208         /**
209          * Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
210          */
211         public static Balance counterparty_revoked_output_claimable(long claimable_amount_satoshis) {
212                 long ret = bindings.Balance_counterparty_revoked_output_claimable(claimable_amount_satoshis);
213                 GC.KeepAlive(claimable_amount_satoshis);
214                 if (ret >= 0 && ret <= 4096) { return null; }
215                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
216                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
217                 return ret_hu_conv;
218         }
219
220         /**
221          * Checks if two Balances contain equal inner contents.
222          * This ignores pointers and is_owned flags and looks at the values in fields.
223          */
224         public bool eq(org.ldk.structs.Balance b) {
225                 bool ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr);
226                 GC.KeepAlive(this);
227                 GC.KeepAlive(b);
228                 return ret;
229         }
230
231         public override bool Equals(object o) {
232                 if (!(o is Balance)) return false;
233                 return this.eq((Balance)o);
234         }
235 }
236 } } }