[Java] Update auto-generated Java bindings for 0.0.113
[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 claimable_amount_satoshis;
59                 private ClaimableOnChannelClose(long ptr, bindings.LDKBalance.ClaimableOnChannelClose obj) {
60                         super(null, ptr);
61                         this.claimable_amount_satoshis = obj.claimable_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 claimable_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.claimable_amount_satoshis = obj.claimable_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 claimable_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                 private ContentiousClaimable(long ptr, bindings.LDKBalance.ContentiousClaimable obj) {
106                         super(null, ptr);
107                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
108                         this.timeout_height = obj.timeout_height;
109                 }
110         }
111         /**
112          * HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
113          * fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
114          * likely to be claimed by our counterparty before we do.
115          */
116         public final static class MaybeTimeoutClaimableHTLC extends Balance {
117                 /**
118                  * The amount potentially available to claim, in satoshis, excluding the on-chain fees
119                  * which will be required to do so.
120                 */
121                 public final long claimable_amount_satoshis;
122                 /**
123                  * The height at which we will be able to claim the balance if our counterparty has not
124                  * done so.
125                 */
126                 public final int claimable_height;
127                 private MaybeTimeoutClaimableHTLC(long ptr, bindings.LDKBalance.MaybeTimeoutClaimableHTLC obj) {
128                         super(null, ptr);
129                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
130                         this.claimable_height = obj.claimable_height;
131                 }
132         }
133         /**
134          * HTLCs which we received from our counterparty which are claimable with a preimage which we
135          * do not currently have. This will only be claimable if we receive the preimage from the node
136          * to which we forwarded this HTLC before the timeout.
137          */
138         public final static class MaybePreimageClaimableHTLC extends Balance {
139                 /**
140                  * The amount potentially available to claim, in satoshis, excluding the on-chain fees
141                  * which will be required to do so.
142                 */
143                 public final long claimable_amount_satoshis;
144                 /**
145                  * The height at which our counterparty will be able to claim the balance if we have not
146                  * yet received the preimage and claimed it ourselves.
147                 */
148                 public final int expiry_height;
149                 private MaybePreimageClaimableHTLC(long ptr, bindings.LDKBalance.MaybePreimageClaimableHTLC obj) {
150                         super(null, ptr);
151                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
152                         this.expiry_height = obj.expiry_height;
153                 }
154         }
155         /**
156          * The channel has been closed, and our counterparty broadcasted a revoked commitment
157          * transaction.
158          * 
159          * Thus, we're able to claim all outputs in the commitment transaction, one of which has the
160          * following amount.
161          */
162         public final static class CounterpartyRevokedOutputClaimable extends Balance {
163                 /**
164                  * The amount, in satoshis, of the output which we can claim.
165                  * 
166                  * Note that for outputs from HTLC balances this may be excluding some on-chain fees that
167                  * were already spent.
168                 */
169                 public final long claimable_amount_satoshis;
170                 private CounterpartyRevokedOutputClaimable(long ptr, bindings.LDKBalance.CounterpartyRevokedOutputClaimable obj) {
171                         super(null, ptr);
172                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
173                 }
174         }
175         long clone_ptr() {
176                 long ret = bindings.Balance_clone_ptr(this.ptr);
177                 Reference.reachabilityFence(this);
178                 return ret;
179         }
180
181         /**
182          * Creates a copy of the Balance
183          */
184         public Balance clone() {
185                 long ret = bindings.Balance_clone(this.ptr);
186                 Reference.reachabilityFence(this);
187                 if (ret >= 0 && ret <= 4096) { return null; }
188                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
189                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
190                 return ret_hu_conv;
191         }
192
193         /**
194          * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
195          */
196         public static Balance claimable_on_channel_close(long claimable_amount_satoshis) {
197                 long ret = bindings.Balance_claimable_on_channel_close(claimable_amount_satoshis);
198                 Reference.reachabilityFence(claimable_amount_satoshis);
199                 if (ret >= 0 && ret <= 4096) { return null; }
200                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
201                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
202                 return ret_hu_conv;
203         }
204
205         /**
206          * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
207          */
208         public static Balance claimable_awaiting_confirmations(long claimable_amount_satoshis, int confirmation_height) {
209                 long ret = bindings.Balance_claimable_awaiting_confirmations(claimable_amount_satoshis, confirmation_height);
210                 Reference.reachabilityFence(claimable_amount_satoshis);
211                 Reference.reachabilityFence(confirmation_height);
212                 if (ret >= 0 && ret <= 4096) { return null; }
213                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
214                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
215                 return ret_hu_conv;
216         }
217
218         /**
219          * Utility method to constructs a new ContentiousClaimable-variant Balance
220          */
221         public static Balance contentious_claimable(long claimable_amount_satoshis, int timeout_height) {
222                 long ret = bindings.Balance_contentious_claimable(claimable_amount_satoshis, timeout_height);
223                 Reference.reachabilityFence(claimable_amount_satoshis);
224                 Reference.reachabilityFence(timeout_height);
225                 if (ret >= 0 && ret <= 4096) { return null; }
226                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
227                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
228                 return ret_hu_conv;
229         }
230
231         /**
232          * Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
233          */
234         public static Balance maybe_timeout_claimable_htlc(long claimable_amount_satoshis, int claimable_height) {
235                 long ret = bindings.Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis, claimable_height);
236                 Reference.reachabilityFence(claimable_amount_satoshis);
237                 Reference.reachabilityFence(claimable_height);
238                 if (ret >= 0 && ret <= 4096) { return null; }
239                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
240                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
241                 return ret_hu_conv;
242         }
243
244         /**
245          * Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
246          */
247         public static Balance maybe_preimage_claimable_htlc(long claimable_amount_satoshis, int expiry_height) {
248                 long ret = bindings.Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis, expiry_height);
249                 Reference.reachabilityFence(claimable_amount_satoshis);
250                 Reference.reachabilityFence(expiry_height);
251                 if (ret >= 0 && ret <= 4096) { return null; }
252                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
253                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
254                 return ret_hu_conv;
255         }
256
257         /**
258          * Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
259          */
260         public static Balance counterparty_revoked_output_claimable(long claimable_amount_satoshis) {
261                 long ret = bindings.Balance_counterparty_revoked_output_claimable(claimable_amount_satoshis);
262                 Reference.reachabilityFence(claimable_amount_satoshis);
263                 if (ret >= 0 && ret <= 4096) { return null; }
264                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
265                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
266                 return ret_hu_conv;
267         }
268
269         /**
270          * Checks if two Balances contain equal inner contents.
271          * This ignores pointers and is_owned flags and looks at the values in fields.
272          */
273         public boolean eq(org.ldk.structs.Balance b) {
274                 boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr);
275                 Reference.reachabilityFence(this);
276                 Reference.reachabilityFence(b);
277                 return ret;
278         }
279
280         @Override public boolean equals(Object o) {
281                 if (!(o instanceof Balance)) return false;
282                 return this.eq((Balance)o);
283         }
284 }