6 namespace org { namespace ldk { namespace structs {
9 * Details about the balance(s) available for spending once the channel appears on chain.
11 * See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
14 public class Balance : CommonBase {
15 protected Balance(object _dummy, long ptr) : base(ptr) { }
17 if (ptr != 0) { bindings.Balance_free(ptr); }
20 internal static Balance constr_from_ptr(long ptr) {
21 long raw_ty = bindings.LDKBalance_ty_from_ptr(ptr);
23 case 0: return new Balance_ClaimableOnChannelClose(ptr);
24 case 1: return new Balance_ClaimableAwaitingConfirmations(ptr);
25 case 2: return new Balance_ContentiousClaimable(ptr);
26 case 3: return new Balance_MaybeTimeoutClaimableHTLC(ptr);
27 case 4: return new Balance_MaybePreimageClaimableHTLC(ptr);
28 case 5: return new Balance_CounterpartyRevokedOutputClaimable(ptr);
30 throw new ArgumentException("Impossible enum variant");
34 /** A Balance of type ClaimableOnChannelClose */
35 public class Balance_ClaimableOnChannelClose : Balance {
37 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
40 public long amount_satoshis;
41 internal Balance_ClaimableOnChannelClose(long ptr) : base(null, ptr) {
42 this.amount_satoshis = bindings.LDKBalance_ClaimableOnChannelClose_get_amount_satoshis(ptr);
45 /** A Balance of type ClaimableAwaitingConfirmations */
46 public class Balance_ClaimableAwaitingConfirmations : Balance {
48 * The amount available to claim, in satoshis, possibly excluding the on-chain fees which
49 * were spent in broadcasting the transaction.
51 public long amount_satoshis;
53 * The height at which an [`Event::SpendableOutputs`] event will be generated for this
56 public int confirmation_height;
57 internal Balance_ClaimableAwaitingConfirmations(long ptr) : base(null, ptr) {
58 this.amount_satoshis = bindings.LDKBalance_ClaimableAwaitingConfirmations_get_amount_satoshis(ptr);
59 this.confirmation_height = bindings.LDKBalance_ClaimableAwaitingConfirmations_get_confirmation_height(ptr);
62 /** A Balance of type ContentiousClaimable */
63 public class Balance_ContentiousClaimable : Balance {
65 * The amount available to claim, in satoshis, excluding the on-chain fees which will be
68 public long amount_satoshis;
70 * The height at which the counterparty may be able to claim the balance if we have not
73 public int timeout_height;
75 * The payment hash that locks this HTLC.
77 public byte[] payment_hash;
79 * The preimage that can be used to claim this HTLC.
81 public byte[] payment_preimage;
82 internal Balance_ContentiousClaimable(long ptr) : base(null, ptr) {
83 this.amount_satoshis = bindings.LDKBalance_ContentiousClaimable_get_amount_satoshis(ptr);
84 this.timeout_height = bindings.LDKBalance_ContentiousClaimable_get_timeout_height(ptr);
85 this.payment_hash = bindings.LDKBalance_ContentiousClaimable_get_payment_hash(ptr);
86 this.payment_preimage = bindings.LDKBalance_ContentiousClaimable_get_payment_preimage(ptr);
89 /** A Balance of type MaybeTimeoutClaimableHTLC */
90 public class Balance_MaybeTimeoutClaimableHTLC : Balance {
92 * The amount potentially available to claim, in satoshis, excluding the on-chain fees
93 * which will be required to do so.
95 public long amount_satoshis;
97 * The height at which we will be able to claim the balance if our counterparty has not
100 public int claimable_height;
102 * The payment hash whose preimage our counterparty needs to claim this HTLC.
104 public byte[] payment_hash;
105 internal Balance_MaybeTimeoutClaimableHTLC(long ptr) : base(null, ptr) {
106 this.amount_satoshis = bindings.LDKBalance_MaybeTimeoutClaimableHTLC_get_amount_satoshis(ptr);
107 this.claimable_height = bindings.LDKBalance_MaybeTimeoutClaimableHTLC_get_claimable_height(ptr);
108 this.payment_hash = bindings.LDKBalance_MaybeTimeoutClaimableHTLC_get_payment_hash(ptr);
111 /** A Balance of type MaybePreimageClaimableHTLC */
112 public class Balance_MaybePreimageClaimableHTLC : Balance {
114 * The amount potentially available to claim, in satoshis, excluding the on-chain fees
115 * which will be required to do so.
117 public long amount_satoshis;
119 * The height at which our counterparty will be able to claim the balance if we have not
120 * yet received the preimage and claimed it ourselves.
122 public int expiry_height;
124 * The payment hash whose preimage we need to claim this HTLC.
126 public byte[] payment_hash;
127 internal Balance_MaybePreimageClaimableHTLC(long ptr) : base(null, ptr) {
128 this.amount_satoshis = bindings.LDKBalance_MaybePreimageClaimableHTLC_get_amount_satoshis(ptr);
129 this.expiry_height = bindings.LDKBalance_MaybePreimageClaimableHTLC_get_expiry_height(ptr);
130 this.payment_hash = bindings.LDKBalance_MaybePreimageClaimableHTLC_get_payment_hash(ptr);
133 /** A Balance of type CounterpartyRevokedOutputClaimable */
134 public class Balance_CounterpartyRevokedOutputClaimable : Balance {
136 * The amount, in satoshis, of the output which we can claim.
138 * Note that for outputs from HTLC balances this may be excluding some on-chain fees that
139 * were already spent.
141 public long amount_satoshis;
142 internal Balance_CounterpartyRevokedOutputClaimable(long ptr) : base(null, ptr) {
143 this.amount_satoshis = bindings.LDKBalance_CounterpartyRevokedOutputClaimable_get_amount_satoshis(ptr);
146 internal long clone_ptr() {
147 long ret = bindings.Balance_clone_ptr(this.ptr);
153 * Creates a copy of the Balance
155 public Balance clone() {
156 long ret = bindings.Balance_clone(this.ptr);
158 if (ret >= 0 && ret <= 4096) { return null; }
159 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
160 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
165 * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
167 public static Balance claimable_on_channel_close(long amount_satoshis) {
168 long ret = bindings.Balance_claimable_on_channel_close(amount_satoshis);
169 GC.KeepAlive(amount_satoshis);
170 if (ret >= 0 && ret <= 4096) { return null; }
171 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
172 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
177 * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
179 public static Balance claimable_awaiting_confirmations(long amount_satoshis, int confirmation_height) {
180 long ret = bindings.Balance_claimable_awaiting_confirmations(amount_satoshis, confirmation_height);
181 GC.KeepAlive(amount_satoshis);
182 GC.KeepAlive(confirmation_height);
183 if (ret >= 0 && ret <= 4096) { return null; }
184 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
185 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
190 * Utility method to constructs a new ContentiousClaimable-variant Balance
192 public static Balance contentious_claimable(long amount_satoshis, int timeout_height, byte[] payment_hash, byte[] payment_preimage) {
193 long ret = bindings.Balance_contentious_claimable(amount_satoshis, timeout_height, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_preimage, 32));
194 GC.KeepAlive(amount_satoshis);
195 GC.KeepAlive(timeout_height);
196 GC.KeepAlive(payment_hash);
197 GC.KeepAlive(payment_preimage);
198 if (ret >= 0 && ret <= 4096) { return null; }
199 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
200 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
205 * Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
207 public static Balance maybe_timeout_claimable_htlc(long amount_satoshis, int claimable_height, byte[] payment_hash) {
208 long ret = bindings.Balance_maybe_timeout_claimable_htlc(amount_satoshis, claimable_height, InternalUtils.check_arr_len(payment_hash, 32));
209 GC.KeepAlive(amount_satoshis);
210 GC.KeepAlive(claimable_height);
211 GC.KeepAlive(payment_hash);
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.AddLast(ret_hu_conv); };
219 * Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
221 public static Balance maybe_preimage_claimable_htlc(long amount_satoshis, int expiry_height, byte[] payment_hash) {
222 long ret = bindings.Balance_maybe_preimage_claimable_htlc(amount_satoshis, expiry_height, InternalUtils.check_arr_len(payment_hash, 32));
223 GC.KeepAlive(amount_satoshis);
224 GC.KeepAlive(expiry_height);
225 GC.KeepAlive(payment_hash);
226 if (ret >= 0 && ret <= 4096) { return null; }
227 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
228 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
233 * Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
235 public static Balance counterparty_revoked_output_claimable(long amount_satoshis) {
236 long ret = bindings.Balance_counterparty_revoked_output_claimable(amount_satoshis);
237 GC.KeepAlive(amount_satoshis);
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.AddLast(ret_hu_conv); };
245 * Checks if two Balances contain equal inner contents.
246 * This ignores pointers and is_owned flags and looks at the values in fields.
248 public bool eq(org.ldk.structs.Balance b) {
249 bool ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr);
255 public override bool Equals(object o) {
256 if (!(o is Balance)) return false;
257 return this.eq((Balance)o);
260 * The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
261 * to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
262 * information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
263 * [`Balance::MaybePreimageClaimableHTLC`].
265 * On-chain fees required to claim the balance are not included in this amount.
267 public long claimable_amount_satoshis() {
268 long ret = bindings.Balance_claimable_amount_satoshis(this.ptr);