[C#] Update test to LDK 0.0.123 and pay a BOLT12 offer
[ldk-java] / src / main / java / org / ldk / structs / Balance.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Details about the balance(s) available for spending once the channel appears on chain.
13  * 
14  * See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
15  * be provided.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class Balance extends CommonBase {
19         private Balance(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.Balance_free(ptr); }
24         }
25         static Balance constr_from_ptr(long ptr) {
26                 bindings.LDKBalance raw_val = bindings.LDKBalance_ref_from_ptr(ptr);
27                 if (raw_val.getClass() == bindings.LDKBalance.ClaimableOnChannelClose.class) {
28                         return new ClaimableOnChannelClose(ptr, (bindings.LDKBalance.ClaimableOnChannelClose)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKBalance.ClaimableAwaitingConfirmations.class) {
31                         return new ClaimableAwaitingConfirmations(ptr, (bindings.LDKBalance.ClaimableAwaitingConfirmations)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKBalance.ContentiousClaimable.class) {
34                         return new ContentiousClaimable(ptr, (bindings.LDKBalance.ContentiousClaimable)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKBalance.MaybeTimeoutClaimableHTLC.class) {
37                         return new MaybeTimeoutClaimableHTLC(ptr, (bindings.LDKBalance.MaybeTimeoutClaimableHTLC)raw_val);
38                 }
39                 if (raw_val.getClass() == bindings.LDKBalance.MaybePreimageClaimableHTLC.class) {
40                         return new MaybePreimageClaimableHTLC(ptr, (bindings.LDKBalance.MaybePreimageClaimableHTLC)raw_val);
41                 }
42                 if (raw_val.getClass() == bindings.LDKBalance.CounterpartyRevokedOutputClaimable.class) {
43                         return new CounterpartyRevokedOutputClaimable(ptr, (bindings.LDKBalance.CounterpartyRevokedOutputClaimable)raw_val);
44                 }
45                 assert false; return null; // Unreachable without extending the (internal) bindings interface
46         }
47
48         /**
49          * The channel is not yet closed (or the commitment or closing transaction has not yet
50          * appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
51          * force-closed now.
52          */
53         public final static class ClaimableOnChannelClose extends Balance {
54                 /**
55                  * The amount available to claim, in satoshis, excluding the on-chain fees which will be
56                  * required to do so.
57                 */
58                 public final long amount_satoshis;
59                 private ClaimableOnChannelClose(long ptr, bindings.LDKBalance.ClaimableOnChannelClose obj) {
60                         super(null, ptr);
61                         this.amount_satoshis = obj.amount_satoshis;
62                 }
63         }
64         /**
65          * The channel has been closed, and the given balance is ours but awaiting confirmations until
66          * we consider it spendable.
67          */
68         public final static class ClaimableAwaitingConfirmations extends Balance {
69                 /**
70                  * The amount available to claim, in satoshis, possibly excluding the on-chain fees which
71                  * were spent in broadcasting the transaction.
72                 */
73                 public final long amount_satoshis;
74                 /**
75                  * The height at which an [`Event::SpendableOutputs`] event will be generated for this
76                  * amount.
77                 */
78                 public final int confirmation_height;
79                 private ClaimableAwaitingConfirmations(long ptr, bindings.LDKBalance.ClaimableAwaitingConfirmations obj) {
80                         super(null, ptr);
81                         this.amount_satoshis = obj.amount_satoshis;
82                         this.confirmation_height = obj.confirmation_height;
83                 }
84         }
85         /**
86          * The channel has been closed, and the given balance should be ours but awaiting spending
87          * transaction confirmation. If the spending transaction does not confirm in time, it is
88          * possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
89          * 
90          * Once the spending transaction confirms, before it has reached enough confirmations to be
91          * considered safe from chain reorganizations, the balance will instead be provided via
92          * [`Balance::ClaimableAwaitingConfirmations`].
93          */
94         public final static class ContentiousClaimable extends Balance {
95                 /**
96                  * The amount available to claim, in satoshis, excluding the on-chain fees which will be
97                  * required to do so.
98                 */
99                 public final long amount_satoshis;
100                 /**
101                  * The height at which the counterparty may be able to claim the balance if we have not
102                  * done so.
103                 */
104                 public final int timeout_height;
105                 /**
106                  * The payment hash that locks this HTLC.
107                 */
108                 public final byte[] payment_hash;
109                 /**
110                  * The preimage that can be used to claim this HTLC.
111                 */
112                 public final byte[] payment_preimage;
113                 private ContentiousClaimable(long ptr, bindings.LDKBalance.ContentiousClaimable obj) {
114                         super(null, ptr);
115                         this.amount_satoshis = obj.amount_satoshis;
116                         this.timeout_height = obj.timeout_height;
117                         this.payment_hash = obj.payment_hash;
118                         this.payment_preimage = obj.payment_preimage;
119                 }
120         }
121         /**
122          * HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
123          * fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
124          * likely to be claimed by our counterparty before we do.
125          */
126         public final static class MaybeTimeoutClaimableHTLC extends Balance {
127                 /**
128                  * The amount potentially available to claim, in satoshis, excluding the on-chain fees
129                  * which will be required to do so.
130                 */
131                 public final long amount_satoshis;
132                 /**
133                  * The height at which we will be able to claim the balance if our counterparty has not
134                  * done so.
135                 */
136                 public final int claimable_height;
137                 /**
138                  * The payment hash whose preimage our counterparty needs to claim this HTLC.
139                 */
140                 public final byte[] payment_hash;
141                 private MaybeTimeoutClaimableHTLC(long ptr, bindings.LDKBalance.MaybeTimeoutClaimableHTLC obj) {
142                         super(null, ptr);
143                         this.amount_satoshis = obj.amount_satoshis;
144                         this.claimable_height = obj.claimable_height;
145                         this.payment_hash = obj.payment_hash;
146                 }
147         }
148         /**
149          * HTLCs which we received from our counterparty which are claimable with a preimage which we
150          * do not currently have. This will only be claimable if we receive the preimage from the node
151          * to which we forwarded this HTLC before the timeout.
152          */
153         public final static class MaybePreimageClaimableHTLC extends Balance {
154                 /**
155                  * The amount potentially available to claim, in satoshis, excluding the on-chain fees
156                  * which will be required to do so.
157                 */
158                 public final long amount_satoshis;
159                 /**
160                  * The height at which our counterparty will be able to claim the balance if we have not
161                  * yet received the preimage and claimed it ourselves.
162                 */
163                 public final int expiry_height;
164                 /**
165                  * The payment hash whose preimage we need to claim this HTLC.
166                 */
167                 public final byte[] payment_hash;
168                 private MaybePreimageClaimableHTLC(long ptr, bindings.LDKBalance.MaybePreimageClaimableHTLC obj) {
169                         super(null, ptr);
170                         this.amount_satoshis = obj.amount_satoshis;
171                         this.expiry_height = obj.expiry_height;
172                         this.payment_hash = obj.payment_hash;
173                 }
174         }
175         /**
176          * The channel has been closed, and our counterparty broadcasted a revoked commitment
177          * transaction.
178          * 
179          * Thus, we're able to claim all outputs in the commitment transaction, one of which has the
180          * following amount.
181          */
182         public final static class CounterpartyRevokedOutputClaimable extends Balance {
183                 /**
184                  * The amount, in satoshis, of the output which we can claim.
185                  * 
186                  * Note that for outputs from HTLC balances this may be excluding some on-chain fees that
187                  * were already spent.
188                 */
189                 public final long amount_satoshis;
190                 private CounterpartyRevokedOutputClaimable(long ptr, bindings.LDKBalance.CounterpartyRevokedOutputClaimable obj) {
191                         super(null, ptr);
192                         this.amount_satoshis = obj.amount_satoshis;
193                 }
194         }
195         long clone_ptr() {
196                 long ret = bindings.Balance_clone_ptr(this.ptr);
197                 Reference.reachabilityFence(this);
198                 return ret;
199         }
200
201         /**
202          * Creates a copy of the Balance
203          */
204         public Balance clone() {
205                 long ret = bindings.Balance_clone(this.ptr);
206                 Reference.reachabilityFence(this);
207                 if (ret >= 0 && ret <= 4096) { return null; }
208                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
209                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
210                 return ret_hu_conv;
211         }
212
213         /**
214          * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
215          */
216         public static Balance claimable_on_channel_close(long amount_satoshis) {
217                 long ret = bindings.Balance_claimable_on_channel_close(amount_satoshis);
218                 Reference.reachabilityFence(amount_satoshis);
219                 if (ret >= 0 && ret <= 4096) { return null; }
220                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
221                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
222                 return ret_hu_conv;
223         }
224
225         /**
226          * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
227          */
228         public static Balance claimable_awaiting_confirmations(long amount_satoshis, int confirmation_height) {
229                 long ret = bindings.Balance_claimable_awaiting_confirmations(amount_satoshis, confirmation_height);
230                 Reference.reachabilityFence(amount_satoshis);
231                 Reference.reachabilityFence(confirmation_height);
232                 if (ret >= 0 && ret <= 4096) { return null; }
233                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
234                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
235                 return ret_hu_conv;
236         }
237
238         /**
239          * Utility method to constructs a new ContentiousClaimable-variant Balance
240          */
241         public static Balance contentious_claimable(long amount_satoshis, int timeout_height, byte[] payment_hash, byte[] payment_preimage) {
242                 long ret = bindings.Balance_contentious_claimable(amount_satoshis, timeout_height, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_preimage, 32));
243                 Reference.reachabilityFence(amount_satoshis);
244                 Reference.reachabilityFence(timeout_height);
245                 Reference.reachabilityFence(payment_hash);
246                 Reference.reachabilityFence(payment_preimage);
247                 if (ret >= 0 && ret <= 4096) { return null; }
248                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
249                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
250                 return ret_hu_conv;
251         }
252
253         /**
254          * Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
255          */
256         public static Balance maybe_timeout_claimable_htlc(long amount_satoshis, int claimable_height, byte[] payment_hash) {
257                 long ret = bindings.Balance_maybe_timeout_claimable_htlc(amount_satoshis, claimable_height, InternalUtils.check_arr_len(payment_hash, 32));
258                 Reference.reachabilityFence(amount_satoshis);
259                 Reference.reachabilityFence(claimable_height);
260                 Reference.reachabilityFence(payment_hash);
261                 if (ret >= 0 && ret <= 4096) { return null; }
262                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
263                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
264                 return ret_hu_conv;
265         }
266
267         /**
268          * Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
269          */
270         public static Balance maybe_preimage_claimable_htlc(long amount_satoshis, int expiry_height, byte[] payment_hash) {
271                 long ret = bindings.Balance_maybe_preimage_claimable_htlc(amount_satoshis, expiry_height, InternalUtils.check_arr_len(payment_hash, 32));
272                 Reference.reachabilityFence(amount_satoshis);
273                 Reference.reachabilityFence(expiry_height);
274                 Reference.reachabilityFence(payment_hash);
275                 if (ret >= 0 && ret <= 4096) { return null; }
276                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
277                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
278                 return ret_hu_conv;
279         }
280
281         /**
282          * Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
283          */
284         public static Balance counterparty_revoked_output_claimable(long amount_satoshis) {
285                 long ret = bindings.Balance_counterparty_revoked_output_claimable(amount_satoshis);
286                 Reference.reachabilityFence(amount_satoshis);
287                 if (ret >= 0 && ret <= 4096) { return null; }
288                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
289                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
290                 return ret_hu_conv;
291         }
292
293         /**
294          * Checks if two Balances contain equal inner contents.
295          * This ignores pointers and is_owned flags and looks at the values in fields.
296          */
297         public boolean eq(org.ldk.structs.Balance b) {
298                 boolean ret = bindings.Balance_eq(this.ptr, b.ptr);
299                 Reference.reachabilityFence(this);
300                 Reference.reachabilityFence(b);
301                 return ret;
302         }
303
304         @Override public boolean equals(Object o) {
305                 if (!(o instanceof Balance)) return false;
306                 return this.eq((Balance)o);
307         }
308         /**
309          * The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
310          * to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
311          * information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
312          * [`Balance::MaybePreimageClaimableHTLC`].
313          * 
314          * On-chain fees required to claim the balance are not included in this amount.
315          */
316         public long claimable_amount_satoshis() {
317                 long ret = bindings.Balance_claimable_amount_satoshis(this.ptr);
318                 Reference.reachabilityFence(this);
319                 return ret;
320         }
321
322 }