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
41 public final static class ClaimableOnChannelClose extends Balance {
43 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
46 public final long claimable_amount_satoshis;
47 private ClaimableOnChannelClose(long ptr, bindings.LDKBalance.ClaimableOnChannelClose obj) {
49 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
52 public final static class ClaimableAwaitingConfirmations extends Balance {
54 * The amount available to claim, in satoshis, possibly excluding the on-chain fees which
55 * were spent in broadcasting the transaction.
57 public final long claimable_amount_satoshis;
59 * The height at which an [`Event::SpendableOutputs`] event will be generated for this
62 public final int confirmation_height;
63 private ClaimableAwaitingConfirmations(long ptr, bindings.LDKBalance.ClaimableAwaitingConfirmations obj) {
65 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
66 this.confirmation_height = obj.confirmation_height;
69 public final static class ContentiousClaimable extends Balance {
71 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
74 public final long claimable_amount_satoshis;
76 * The height at which the counterparty may be able to claim the balance if we have not
79 public final int timeout_height;
80 private ContentiousClaimable(long ptr, bindings.LDKBalance.ContentiousClaimable obj) {
82 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
83 this.timeout_height = obj.timeout_height;
86 public final static class MaybeClaimableHTLCAwaitingTimeout extends Balance {
88 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
91 public final long claimable_amount_satoshis;
93 * The height at which we will be able to claim the balance if our counterparty has not
96 public final int claimable_height;
97 private MaybeClaimableHTLCAwaitingTimeout(long ptr, bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout obj) {
99 this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
100 this.claimable_height = obj.claimable_height;
104 * Creates a copy of the Balance
106 public Balance clone() {
107 long ret = bindings.Balance_clone(this.ptr);
108 if (ret >= 0 && ret < 1024) { return null; }
109 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
110 ret_hu_conv.ptrs_to.add(this);
115 * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
117 public static Balance claimable_on_channel_close(long claimable_amount_satoshis) {
118 long ret = bindings.Balance_claimable_on_channel_close(claimable_amount_satoshis);
119 if (ret >= 0 && ret < 1024) { return null; }
120 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
121 ret_hu_conv.ptrs_to.add(ret_hu_conv);
126 * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
128 public static Balance claimable_awaiting_confirmations(long claimable_amount_satoshis, int confirmation_height) {
129 long ret = bindings.Balance_claimable_awaiting_confirmations(claimable_amount_satoshis, confirmation_height);
130 if (ret >= 0 && ret < 1024) { return null; }
131 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
132 ret_hu_conv.ptrs_to.add(ret_hu_conv);
137 * Utility method to constructs a new ContentiousClaimable-variant Balance
139 public static Balance contentious_claimable(long claimable_amount_satoshis, int timeout_height) {
140 long ret = bindings.Balance_contentious_claimable(claimable_amount_satoshis, timeout_height);
141 if (ret >= 0 && ret < 1024) { return null; }
142 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
143 ret_hu_conv.ptrs_to.add(ret_hu_conv);
148 * Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance
150 public static Balance maybe_claimable_htlcawaiting_timeout(long claimable_amount_satoshis, int claimable_height) {
151 long ret = bindings.Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis, claimable_height);
152 if (ret >= 0 && ret < 1024) { return null; }
153 Balance ret_hu_conv = Balance.constr_from_ptr(ret);
154 ret_hu_conv.ptrs_to.add(ret_hu_conv);
159 * Checks if two Balances contain equal inner contents.
160 * This ignores pointers and is_owned flags and looks at the values in fields.
162 public boolean eq(Balance b) {
163 boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr & ~1);