1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Details about the balance(s) available for spending once the channel appears on chain.
14 * See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
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 {
23 if (ptr != 0) { bindings.Balance_free(ptr); }
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);
30 if (raw_val.getClass() == bindings.LDKBalance.ClaimableAwaitingConfirmations.class) {
31 return new ClaimableAwaitingConfirmations(ptr, (bindings.LDKBalance.ClaimableAwaitingConfirmations)raw_val);
33 if (raw_val.getClass() == bindings.LDKBalance.ContentiousClaimable.class) {
34 return new ContentiousClaimable(ptr, (bindings.LDKBalance.ContentiousClaimable)raw_val);
36 if (raw_val.getClass() == bindings.LDKBalance.MaybeTimeoutClaimableHTLC.class) {
37 return new MaybeTimeoutClaimableHTLC(ptr, (bindings.LDKBalance.MaybeTimeoutClaimableHTLC)raw_val);
39 if (raw_val.getClass() == bindings.LDKBalance.MaybePreimageClaimableHTLC.class) {
40 return new MaybePreimageClaimableHTLC(ptr, (bindings.LDKBalance.MaybePreimageClaimableHTLC)raw_val);
42 if (raw_val.getClass() == bindings.LDKBalance.CounterpartyRevokedOutputClaimable.class) {
43 return new CounterpartyRevokedOutputClaimable(ptr, (bindings.LDKBalance.CounterpartyRevokedOutputClaimable)raw_val);
45 assert false; return null; // Unreachable without extending the (internal) bindings interface
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
53 public final static class ClaimableOnChannelClose extends Balance {
55 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
58 public final long claimable_amount_satoshis;
59 private ClaimableOnChannelClose(long ptr, bindings.LDKBalance.ClaimableOnChannelClose obj) {
61 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
65 * The channel has been closed, and the given balance is ours but awaiting confirmations until
66 * we consider it spendable.
68 public final static class ClaimableAwaitingConfirmations extends Balance {
70 * The amount available to claim, in satoshis, possibly excluding the on-chain fees which
71 * were spent in broadcasting the transaction.
73 public final long claimable_amount_satoshis;
75 * The height at which an [`Event::SpendableOutputs`] event will be generated for this
78 public final int confirmation_height;
79 private ClaimableAwaitingConfirmations(long ptr, bindings.LDKBalance.ClaimableAwaitingConfirmations obj) {
81 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
82 this.confirmation_height = obj.confirmation_height;
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.
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`].
94 public final static class ContentiousClaimable extends Balance {
96 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
99 public final long claimable_amount_satoshis;
101 * The height at which the counterparty may be able to claim the balance if we have not
104 public final int timeout_height;
105 private ContentiousClaimable(long ptr, bindings.LDKBalance.ContentiousClaimable obj) {
107 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
108 this.timeout_height = obj.timeout_height;
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.
116 public final static class MaybeTimeoutClaimableHTLC extends Balance {
118 * The amount potentially available to claim, in satoshis, excluding the on-chain fees
119 * which will be required to do so.
121 public final long claimable_amount_satoshis;
123 * The height at which we will be able to claim the balance if our counterparty has not
126 public final int claimable_height;
127 private MaybeTimeoutClaimableHTLC(long ptr, bindings.LDKBalance.MaybeTimeoutClaimableHTLC obj) {
129 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
130 this.claimable_height = obj.claimable_height;
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.
138 public final static class MaybePreimageClaimableHTLC extends Balance {
140 * The amount potentially available to claim, in satoshis, excluding the on-chain fees
141 * which will be required to do so.
143 public final long claimable_amount_satoshis;
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.
148 public final int expiry_height;
149 private MaybePreimageClaimableHTLC(long ptr, bindings.LDKBalance.MaybePreimageClaimableHTLC obj) {
151 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
152 this.expiry_height = obj.expiry_height;
156 * The channel has been closed, and our counterparty broadcasted a revoked commitment
159 * Thus, we're able to claim all outputs in the commitment transaction, one of which has the
162 public final static class CounterpartyRevokedOutputClaimable extends Balance {
164 * The amount, in satoshis, of the output which we can claim.
166 * Note that for outputs from HTLC balances this may be excluding some on-chain fees that
167 * were already spent.
169 public final long claimable_amount_satoshis;
170 private CounterpartyRevokedOutputClaimable(long ptr, bindings.LDKBalance.CounterpartyRevokedOutputClaimable obj) {
172 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
176 long ret = bindings.Balance_clone_ptr(this.ptr);
177 Reference.reachabilityFence(this);
182 * Creates a copy of the Balance
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); };
194 * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
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); };
206 * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
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); };
219 * Utility method to constructs a new ContentiousClaimable-variant Balance
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); };
232 * Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
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); };
245 * Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
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); };
258 * Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
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); };
270 * Checks if two Balances contain equal inner contents.
271 * This ignores pointers and is_owned flags and looks at the values in fields.
273 public boolean eq(Balance b) {
274 boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr);
275 Reference.reachabilityFence(this);
276 Reference.reachabilityFence(b);
280 @Override public boolean equals(Object o) {
281 if (!(o instanceof Balance)) return false;
282 return this.eq((Balance)o);