1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Details about the balance(s) available for spending once the channel appears on chain.
13 * See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class Balance extends CommonBase {
18 private Balance(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.Balance_free(ptr); }
24 static Balance constr_from_ptr(long ptr) {
25 bindings.LDKBalance raw_val = bindings.LDKBalance_ref_from_ptr(ptr);
26 if (raw_val.getClass() == bindings.LDKBalance.ClaimableOnChannelClose.class) {
27 return new ClaimableOnChannelClose(ptr, (bindings.LDKBalance.ClaimableOnChannelClose)raw_val);
29 if (raw_val.getClass() == bindings.LDKBalance.ClaimableAwaitingConfirmations.class) {
30 return new ClaimableAwaitingConfirmations(ptr, (bindings.LDKBalance.ClaimableAwaitingConfirmations)raw_val);
32 if (raw_val.getClass() == bindings.LDKBalance.ContentiousClaimable.class) {
33 return new ContentiousClaimable(ptr, (bindings.LDKBalance.ContentiousClaimable)raw_val);
35 if (raw_val.getClass() == bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout.class) {
36 return new MaybeClaimableHTLCAwaitingTimeout(ptr, (bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout)raw_val);
38 assert false; return null; // Unreachable without extending the (internal) bindings interface
42 * The channel is not yet closed (or the commitment or closing transaction has not yet
43 * appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
46 public final static class ClaimableOnChannelClose extends Balance {
48 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
51 public final long claimable_amount_satoshis;
52 private ClaimableOnChannelClose(long ptr, bindings.LDKBalance.ClaimableOnChannelClose obj) {
54 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
58 * The channel has been closed, and the given balance is ours but awaiting confirmations until
59 * we consider it spendable.
61 public final static class ClaimableAwaitingConfirmations extends Balance {
63 * The amount available to claim, in satoshis, possibly excluding the on-chain fees which
64 * were spent in broadcasting the transaction.
66 public final long claimable_amount_satoshis;
68 * The height at which an [`Event::SpendableOutputs`] event will be generated for this
71 public final int confirmation_height;
72 private ClaimableAwaitingConfirmations(long ptr, bindings.LDKBalance.ClaimableAwaitingConfirmations obj) {
74 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
75 this.confirmation_height = obj.confirmation_height;
79 * The channel has been closed, and the given balance should be ours but awaiting spending
80 * transaction confirmation. If the spending transaction does not confirm in time, it is
81 * possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
83 * Once the spending transaction confirms, before it has reached enough confirmations to be
84 * considered safe from chain reorganizations, the balance will instead be provided via
85 * [`Balance::ClaimableAwaitingConfirmations`].
87 public final static class ContentiousClaimable extends Balance {
89 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
92 public final long claimable_amount_satoshis;
94 * The height at which the counterparty may be able to claim the balance if we have not
97 public final int timeout_height;
98 private ContentiousClaimable(long ptr, bindings.LDKBalance.ContentiousClaimable obj) {
100 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
101 this.timeout_height = obj.timeout_height;
105 * HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
106 * fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
107 * likely to be claimed by our counterparty before we do.
109 public final static class MaybeClaimableHTLCAwaitingTimeout extends Balance {
111 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
114 public final long claimable_amount_satoshis;
116 * The height at which we will be able to claim the balance if our counterparty has not
119 public final int claimable_height;
120 private MaybeClaimableHTLCAwaitingTimeout(long ptr, bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout obj) {
122 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
123 this.claimable_height = obj.claimable_height;
127 long ret = bindings.Balance_clone_ptr(this.ptr);
132 * Creates a copy of the Balance
134 public Balance clone() {
135 long ret = bindings.Balance_clone(this.ptr);
136 if (ret >= 0 && ret <= 4096) { return null; }
137 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
138 ret_hu_conv.ptrs_to.add(this);
143 * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
145 public static Balance claimable_on_channel_close(long claimable_amount_satoshis) {
146 long ret = bindings.Balance_claimable_on_channel_close(claimable_amount_satoshis);
147 if (ret >= 0 && ret <= 4096) { return null; }
148 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
149 ret_hu_conv.ptrs_to.add(ret_hu_conv);
154 * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
156 public static Balance claimable_awaiting_confirmations(long claimable_amount_satoshis, int confirmation_height) {
157 long ret = bindings.Balance_claimable_awaiting_confirmations(claimable_amount_satoshis, confirmation_height);
158 if (ret >= 0 && ret <= 4096) { return null; }
159 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
160 ret_hu_conv.ptrs_to.add(ret_hu_conv);
165 * Utility method to constructs a new ContentiousClaimable-variant Balance
167 public static Balance contentious_claimable(long claimable_amount_satoshis, int timeout_height) {
168 long ret = bindings.Balance_contentious_claimable(claimable_amount_satoshis, timeout_height);
169 if (ret >= 0 && ret <= 4096) { return null; }
170 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
171 ret_hu_conv.ptrs_to.add(ret_hu_conv);
176 * Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance
178 public static Balance maybe_claimable_htlcawaiting_timeout(long claimable_amount_satoshis, int claimable_height) {
179 long ret = bindings.Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis, claimable_height);
180 if (ret >= 0 && ret <= 4096) { return null; }
181 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
182 ret_hu_conv.ptrs_to.add(ret_hu_conv);
187 * Checks if two Balances contain equal inner contents.
188 * This ignores pointers and is_owned flags and looks at the values in fields.
190 public boolean eq(Balance b) {
191 boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr & ~1);