|
| 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 javax.annotation.Nullable; |
| 8 | + |
| 9 | + |
| 10 | +/** |
| 11 | + * Details about the balance(s) available for spending once the channel appears on chain. |
| 12 | + * |
| 13 | + * See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not |
| 14 | + * be provided. |
| 15 | + */ |
| 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 { |
| 21 | + super.finalize(); |
| 22 | + if (ptr != 0) { bindings.Balance_free(ptr); } |
| 23 | + } |
| 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); |
| 28 | + } |
| 29 | + if (raw_val.getClass() == bindings.LDKBalance.ClaimableAwaitingConfirmations.class) { |
| 30 | + return new ClaimableAwaitingConfirmations(ptr, (bindings.LDKBalance.ClaimableAwaitingConfirmations)raw_val); |
| 31 | + } |
| 32 | + if (raw_val.getClass() == bindings.LDKBalance.ContentiousClaimable.class) { |
| 33 | + return new ContentiousClaimable(ptr, (bindings.LDKBalance.ContentiousClaimable)raw_val); |
| 34 | + } |
| 35 | + if (raw_val.getClass() == bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout.class) { |
| 36 | + return new MaybeClaimableHTLCAwaitingTimeout(ptr, (bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout)raw_val); |
| 37 | + } |
| 38 | + assert false; return null; // Unreachable without extending the (internal) bindings interface |
| 39 | + } |
| 40 | + |
| 41 | + public final static class ClaimableOnChannelClose extends Balance { |
| 42 | + /** |
| 43 | + * The amount available to claim, in satoshis, excluding the on-chain fees which will be |
| 44 | + * required to do so. |
| 45 | + */ |
| 46 | + public final long claimable_amount_satoshis; |
| 47 | + private ClaimableOnChannelClose(long ptr, bindings.LDKBalance.ClaimableOnChannelClose obj) { |
| 48 | + super(null, ptr); |
| 49 | + this.claimable_amount_satoshis = obj.claimable_amount_satoshis; |
| 50 | + } |
| 51 | + } |
| 52 | + public final static class ClaimableAwaitingConfirmations extends Balance { |
| 53 | + /** |
| 54 | + * The amount available to claim, in satoshis, possibly excluding the on-chain fees which |
| 55 | + * were spent in broadcasting the transaction. |
| 56 | + */ |
| 57 | + public final long claimable_amount_satoshis; |
| 58 | + /** |
| 59 | + * The height at which an [`Event::SpendableOutputs`] event will be generated for this |
| 60 | + * amount. |
| 61 | + */ |
| 62 | + public final int confirmation_height; |
| 63 | + private ClaimableAwaitingConfirmations(long ptr, bindings.LDKBalance.ClaimableAwaitingConfirmations obj) { |
| 64 | + super(null, ptr); |
| 65 | + this.claimable_amount_satoshis = obj.claimable_amount_satoshis; |
| 66 | + this.confirmation_height = obj.confirmation_height; |
| 67 | + } |
| 68 | + } |
| 69 | + public final static class ContentiousClaimable extends Balance { |
| 70 | + /** |
| 71 | + * The amount available to claim, in satoshis, excluding the on-chain fees which will be |
| 72 | + * required to do so. |
| 73 | + */ |
| 74 | + public final long claimable_amount_satoshis; |
| 75 | + /** |
| 76 | + * The height at which the counterparty may be able to claim the balance if we have not |
| 77 | + * done so. |
| 78 | + */ |
| 79 | + public final int timeout_height; |
| 80 | + private ContentiousClaimable(long ptr, bindings.LDKBalance.ContentiousClaimable obj) { |
| 81 | + super(null, ptr); |
| 82 | + this.claimable_amount_satoshis = obj.claimable_amount_satoshis; |
| 83 | + this.timeout_height = obj.timeout_height; |
| 84 | + } |
| 85 | + } |
| 86 | + public final static class MaybeClaimableHTLCAwaitingTimeout extends Balance { |
| 87 | + /** |
| 88 | + * The amount available to claim, in satoshis, excluding the on-chain fees which will be |
| 89 | + * required to do so. |
| 90 | + */ |
| 91 | + public final long claimable_amount_satoshis; |
| 92 | + /** |
| 93 | + * The height at which we will be able to claim the balance if our counterparty has not |
| 94 | + * done so. |
| 95 | + */ |
| 96 | + public final int claimable_height; |
| 97 | + private MaybeClaimableHTLCAwaitingTimeout(long ptr, bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout obj) { |
| 98 | + super(null, ptr); |
| 99 | + this.claimable_amount_satoshis = obj.claimable_amount_satoshis; |
| 100 | + this.claimable_height = obj.claimable_height; |
| 101 | + } |
| 102 | + } |
| 103 | + /** |
| 104 | + * Creates a copy of the Balance |
| 105 | + */ |
| 106 | + public Balance clone() { |
| 107 | + long ret = bindings.Balance_clone(this.ptr); |
| 108 | + if (ret < 1024) { return null; } |
| 109 | + Balance ret_hu_conv = Balance.constr_from_ptr(ret); |
| 110 | + ret_hu_conv.ptrs_to.add(this); |
| 111 | + return ret_hu_conv; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Utility method to constructs a new ClaimableOnChannelClose-variant Balance |
| 116 | + */ |
| 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 < 1024) { return null; } |
| 120 | + Balance ret_hu_conv = Balance.constr_from_ptr(ret); |
| 121 | + ret_hu_conv.ptrs_to.add(ret_hu_conv); |
| 122 | + return ret_hu_conv; |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance |
| 127 | + */ |
| 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 < 1024) { return null; } |
| 131 | + Balance ret_hu_conv = Balance.constr_from_ptr(ret); |
| 132 | + ret_hu_conv.ptrs_to.add(ret_hu_conv); |
| 133 | + return ret_hu_conv; |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Utility method to constructs a new ContentiousClaimable-variant Balance |
| 138 | + */ |
| 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 < 1024) { return null; } |
| 142 | + Balance ret_hu_conv = Balance.constr_from_ptr(ret); |
| 143 | + ret_hu_conv.ptrs_to.add(ret_hu_conv); |
| 144 | + return ret_hu_conv; |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance |
| 149 | + */ |
| 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 < 1024) { return null; } |
| 153 | + Balance ret_hu_conv = Balance.constr_from_ptr(ret); |
| 154 | + ret_hu_conv.ptrs_to.add(ret_hu_conv); |
| 155 | + return ret_hu_conv; |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Checks if two Balances contain equal inner contents. |
| 160 | + * This ignores pointers and is_owned flags and looks at the values in fields. |
| 161 | + */ |
| 162 | + public boolean eq(Balance b) { |
| 163 | + boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr & ~1); |
| 164 | + this.ptrs_to.add(b); |
| 165 | + return ret; |
| 166 | + } |
| 167 | + |
| 168 | +} |
0 commit comments