6 namespace org { namespace ldk { namespace structs {
10 * A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
11 * on-chain transactions to ensure no loss of funds occurs.
13 * You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
14 * information and are actively monitoring the chain.
16 * Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
17 * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
18 * the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
19 * returned block hash and the the current chain and then reconnecting blocks to get to the
20 * best chain) upon deserializing the object!
22 public class ChannelMonitor : CommonBase {
23 internal ChannelMonitor(object _dummy, long ptr) : base(ptr) { }
25 if (ptr != 0) { bindings.ChannelMonitor_free(ptr); }
28 internal long clone_ptr() {
29 long ret = bindings.ChannelMonitor_clone_ptr(this.ptr);
35 * Creates a copy of the ChannelMonitor
37 public ChannelMonitor clone() {
38 long ret = bindings.ChannelMonitor_clone(this.ptr);
40 if (ret >= 0 && ret <= 4096) { return null; }
41 org.ldk.structs.ChannelMonitor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelMonitor(null, ret); }
42 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
47 * Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
49 public byte[] write() {
50 long ret = bindings.ChannelMonitor_write(this.ptr);
52 if (ret >= 0 && ret <= 4096) { return null; }
53 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
58 * Updates a ChannelMonitor on the basis of some new information provided by the Channel
61 * panics if the given update is not the next update by update_id.
63 public Result_NoneNoneZ update_monitor(org.ldk.structs.ChannelMonitorUpdate updates, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Logger logger) {
64 long ret = bindings.ChannelMonitor_update_monitor(this.ptr, updates == null ? 0 : updates.ptr, broadcaster.ptr, fee_estimator.ptr, logger.ptr);
66 GC.KeepAlive(updates);
67 GC.KeepAlive(broadcaster);
68 GC.KeepAlive(fee_estimator);
70 if (ret >= 0 && ret <= 4096) { return null; }
71 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
72 if (this != null) { this.ptrs_to.AddLast(updates); };
73 if (this != null) { this.ptrs_to.AddLast(broadcaster); };
74 if (this != null) { this.ptrs_to.AddLast(fee_estimator); };
75 if (this != null) { this.ptrs_to.AddLast(logger); };
80 * Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
83 public long get_latest_update_id() {
84 long ret = bindings.ChannelMonitor_get_latest_update_id(this.ptr);
90 * Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
92 public TwoTuple_OutPointCVec_u8ZZ get_funding_txo() {
93 long ret = bindings.ChannelMonitor_get_funding_txo(this.ptr);
95 if (ret >= 0 && ret <= 4096) { return null; }
96 TwoTuple_OutPointCVec_u8ZZ ret_hu_conv = new TwoTuple_OutPointCVec_u8ZZ(null, ret);
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
102 * Gets a list of txids, with their output scripts (in the order they appear in the
103 * transaction), which we must learn about spends of via block_connected().
105 public TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZ[] get_outputs_to_watch() {
106 long ret = bindings.ChannelMonitor_get_outputs_to_watch(this.ptr);
108 if (ret >= 0 && ret <= 4096) { return null; }
109 int ret_conv_52_len = InternalUtils.getArrayLength(ret);
110 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZ[] ret_conv_52_arr = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZ[ret_conv_52_len];
111 for (int a = 0; a < ret_conv_52_len; a++) {
112 long ret_conv_52 = InternalUtils.getU64ArrayElem(ret, a);
113 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZ ret_conv_52_hu_conv = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZ(null, ret_conv_52);
114 if (ret_conv_52_hu_conv != null) { ret_conv_52_hu_conv.ptrs_to.AddLast(this); };
115 ret_conv_52_arr[a] = ret_conv_52_hu_conv;
117 bindings.free_buffer(ret);
118 return ret_conv_52_arr;
122 * Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
123 * calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
124 * have been registered.
126 public void load_outputs_to_watch(org.ldk.structs.Filter filter) {
127 bindings.ChannelMonitor_load_outputs_to_watch(this.ptr, filter.ptr);
129 GC.KeepAlive(filter);
130 if (this != null) { this.ptrs_to.AddLast(filter); };
134 * Get the list of HTLCs who's status has been updated on chain. This should be called by
135 * ChannelManager via [`chain::Watch::release_pending_monitor_events`].
137 public MonitorEvent[] get_and_clear_pending_monitor_events() {
138 long ret = bindings.ChannelMonitor_get_and_clear_pending_monitor_events(this.ptr);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 int ret_conv_14_len = InternalUtils.getArrayLength(ret);
142 MonitorEvent[] ret_conv_14_arr = new MonitorEvent[ret_conv_14_len];
143 for (int o = 0; o < ret_conv_14_len; o++) {
144 long ret_conv_14 = InternalUtils.getU64ArrayElem(ret, o);
145 org.ldk.structs.MonitorEvent ret_conv_14_hu_conv = org.ldk.structs.MonitorEvent.constr_from_ptr(ret_conv_14);
146 if (ret_conv_14_hu_conv != null) { ret_conv_14_hu_conv.ptrs_to.AddLast(this); };
147 ret_conv_14_arr[o] = ret_conv_14_hu_conv;
149 bindings.free_buffer(ret);
150 return ret_conv_14_arr;
154 * Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
156 * For channels featuring anchor outputs, this method will also process [`BumpTransaction`]
157 * events produced from each [`ChannelMonitor`] while there is a balance to claim onchain
158 * within each channel. As the confirmation of a commitment transaction may be critical to the
159 * safety of funds, we recommend invoking this every 30 seconds, or lower if running in an
160 * environment with spotty connections, like on mobile.
162 * An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
163 * order to handle these events.
165 * [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
166 * [`BumpTransaction`]: crate::events::Event::BumpTransaction
168 public void process_pending_events(org.ldk.structs.EventHandler handler) {
169 bindings.ChannelMonitor_process_pending_events(this.ptr, handler.ptr);
171 GC.KeepAlive(handler);
172 if (this != null) { this.ptrs_to.AddLast(handler); };
176 * Gets the counterparty's initial commitment transaction. The returned commitment
177 * transaction is unsigned. This is intended to be called during the initial persistence of
178 * the monitor (inside an implementation of [`Persist::persist_new_channel`]), to allow for
179 * watchtowers in the persistence pipeline to have enough data to form justice transactions.
181 * This is similar to [`Self::counterparty_commitment_txs_from_update`], except
182 * that for the initial commitment transaction, we don't have a corresponding update.
184 * This will only return `Some` for channel monitors that have been created after upgrading
187 * [`Persist::persist_new_channel`]: crate::chain::chainmonitor::Persist::persist_new_channel
189 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
191 public CommitmentTransaction initial_counterparty_commitment_tx() {
192 long ret = bindings.ChannelMonitor_initial_counterparty_commitment_tx(this.ptr);
194 if (ret >= 0 && ret <= 4096) { return null; }
195 org.ldk.structs.CommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentTransaction(null, ret); }
196 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
201 * Gets all of the counterparty commitment transactions provided by the given update. This
202 * may be empty if the update doesn't include any new counterparty commitments. Returned
203 * commitment transactions are unsigned.
205 * This is provided so that watchtower clients in the persistence pipeline are able to build
206 * justice transactions for each counterparty commitment upon each update. It's intended to be
207 * used within an implementation of [`Persist::update_persisted_channel`], which is provided
208 * with a monitor and an update. Once revoked, signing a justice transaction can be done using
209 * [`Self::sign_to_local_justice_tx`].
211 * It is expected that a watchtower client may use this method to retrieve the latest counterparty
212 * commitment transaction(s), and then hold the necessary data until a later update in which
213 * the monitor has been updated with the corresponding revocation data, at which point the
214 * monitor can sign the justice transaction.
216 * This will only return a non-empty list for monitor updates that have been created after
217 * upgrading to LDK 0.0.117+. Note that no restriction lies on the monitors themselves, which
218 * may have been created prior to upgrading.
220 * [`Persist::update_persisted_channel`]: crate::chain::chainmonitor::Persist::update_persisted_channel
222 public CommitmentTransaction[] counterparty_commitment_txs_from_update(org.ldk.structs.ChannelMonitorUpdate update) {
223 long ret = bindings.ChannelMonitor_counterparty_commitment_txs_from_update(this.ptr, update == null ? 0 : update.ptr);
225 GC.KeepAlive(update);
226 if (ret >= 0 && ret <= 4096) { return null; }
227 int ret_conv_23_len = InternalUtils.getArrayLength(ret);
228 CommitmentTransaction[] ret_conv_23_arr = new CommitmentTransaction[ret_conv_23_len];
229 for (int x = 0; x < ret_conv_23_len; x++) {
230 long ret_conv_23 = InternalUtils.getU64ArrayElem(ret, x);
231 org.ldk.structs.CommitmentTransaction ret_conv_23_hu_conv = null; if (ret_conv_23 < 0 || ret_conv_23 > 4096) { ret_conv_23_hu_conv = new org.ldk.structs.CommitmentTransaction(null, ret_conv_23); }
232 if (ret_conv_23_hu_conv != null) { ret_conv_23_hu_conv.ptrs_to.AddLast(this); };
233 ret_conv_23_arr[x] = ret_conv_23_hu_conv;
235 bindings.free_buffer(ret);
236 if (this != null) { this.ptrs_to.AddLast(update); };
237 return ret_conv_23_arr;
241 * Wrapper around [`EcdsaChannelSigner::sign_justice_revoked_output`] to make
242 * signing the justice transaction easier for implementors of
243 * [`chain::chainmonitor::Persist`]. On success this method returns the provided transaction
244 * signing the input at `input_idx`. This method will only produce a valid signature for
245 * a transaction spending the `to_local` output of a commitment transaction, i.e. this cannot
246 * be used for revoked HTLC outputs.
248 * `Value` is the value of the output being spent by the input at `input_idx`, committed
249 * in the BIP 143 signature.
251 * This method will only succeed if this monitor has received the revocation secret for the
252 * provided `commitment_number`. If a commitment number is provided that does not correspond
253 * to the commitment transaction being revoked, this will return a signed transaction, but
254 * the signature will not be valid.
256 * [`EcdsaChannelSigner::sign_justice_revoked_output`]: crate::sign::EcdsaChannelSigner::sign_justice_revoked_output
257 * [`Persist`]: crate::chain::chainmonitor::Persist
259 public Result_TransactionNoneZ sign_to_local_justice_tx(byte[] justice_tx, long input_idx, long value, long commitment_number) {
260 long ret = bindings.ChannelMonitor_sign_to_local_justice_tx(this.ptr, InternalUtils.encodeUint8Array(justice_tx), input_idx, value, commitment_number);
262 GC.KeepAlive(justice_tx);
263 GC.KeepAlive(input_idx);
265 GC.KeepAlive(commitment_number);
266 if (ret >= 0 && ret <= 4096) { return null; }
267 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
272 * Gets the `node_id` of the counterparty for this channel.
274 * Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
277 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
279 public byte[] get_counterparty_node_id() {
280 long ret = bindings.ChannelMonitor_get_counterparty_node_id(this.ptr);
282 if (ret >= 0 && ret <= 4096) { return null; }
283 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
288 * Used by [`ChannelManager`] deserialization to broadcast the latest holder state if its copy
289 * of the channel state was out-of-date.
291 * You may also use this to broadcast the latest local commitment transaction, either because
292 * a monitor update failed or because we've fallen behind (i.e. we've received proof that our
293 * counterparty side knows a revocation secret we gave them that they shouldn't know).
295 * Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
296 * side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
297 * close channel with their commitment transaction after a substantial amount of time. Best
298 * may be to contact the other node operator out-of-band to coordinate other options available
301 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
303 public byte[][] get_latest_holder_commitment_txn(org.ldk.structs.Logger logger) {
304 long ret = bindings.ChannelMonitor_get_latest_holder_commitment_txn(this.ptr, logger.ptr);
306 GC.KeepAlive(logger);
307 if (ret >= 0 && ret <= 4096) { return null; }
308 int ret_conv_8_len = InternalUtils.getArrayLength(ret);
309 byte[][] ret_conv_8_arr = new byte[ret_conv_8_len][];
310 for (int i = 0; i < ret_conv_8_len; i++) {
311 long ret_conv_8 = InternalUtils.getU64ArrayElem(ret, i);
312 byte[] ret_conv_8_conv = InternalUtils.decodeUint8Array(ret_conv_8);
313 ret_conv_8_arr[i] = ret_conv_8_conv;
315 bindings.free_buffer(ret);
316 if (this != null) { this.ptrs_to.AddLast(logger); };
317 return ret_conv_8_arr;
321 * Processes transactions in a newly connected block, which may result in any of the following:
322 * - update the monitor's state against resolved HTLCs
323 * - punish the counterparty in the case of seeing a revoked commitment transaction
324 * - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
325 * - detect settled outputs for later spending
326 * - schedule and bump any in-flight claims
328 * Returns any new outputs to watch from `txdata`; after called, these are also included in
329 * [`get_outputs_to_watch`].
331 * [`get_outputs_to_watch`]: #method.get_outputs_to_watch
333 public TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[] block_connected(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Logger logger) {
334 long ret = bindings.ChannelMonitor_block_connected(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(header, 80)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(txdata, txdata_conv_28 => txdata_conv_28 != null ? txdata_conv_28.ptr : 0)), height, broadcaster.ptr, fee_estimator.ptr, logger.ptr);
336 GC.KeepAlive(header);
337 GC.KeepAlive(txdata);
338 GC.KeepAlive(height);
339 GC.KeepAlive(broadcaster);
340 GC.KeepAlive(fee_estimator);
341 GC.KeepAlive(logger);
342 if (ret >= 0 && ret <= 4096) { return null; }
343 int ret_conv_49_len = InternalUtils.getArrayLength(ret);
344 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[] ret_conv_49_arr = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[ret_conv_49_len];
345 for (int x = 0; x < ret_conv_49_len; x++) {
346 long ret_conv_49 = InternalUtils.getU64ArrayElem(ret, x);
347 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ ret_conv_49_hu_conv = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ(null, ret_conv_49);
348 if (ret_conv_49_hu_conv != null) { ret_conv_49_hu_conv.ptrs_to.AddLast(this); };
349 ret_conv_49_arr[x] = ret_conv_49_hu_conv;
351 bindings.free_buffer(ret);
352 if (this != null) { this.ptrs_to.AddLast(broadcaster); };
353 if (this != null) { this.ptrs_to.AddLast(fee_estimator); };
354 if (this != null) { this.ptrs_to.AddLast(logger); };
355 return ret_conv_49_arr;
359 * Determines if the disconnected block contained any transactions of interest and updates
362 public void block_disconnected(byte[] header, int height, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Logger logger) {
363 bindings.ChannelMonitor_block_disconnected(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(header, 80)), height, broadcaster.ptr, fee_estimator.ptr, logger.ptr);
365 GC.KeepAlive(header);
366 GC.KeepAlive(height);
367 GC.KeepAlive(broadcaster);
368 GC.KeepAlive(fee_estimator);
369 GC.KeepAlive(logger);
370 if (this != null) { this.ptrs_to.AddLast(broadcaster); };
371 if (this != null) { this.ptrs_to.AddLast(fee_estimator); };
372 if (this != null) { this.ptrs_to.AddLast(logger); };
376 * Processes transactions confirmed in a block with the given header and height, returning new
377 * outputs to watch. See [`block_connected`] for details.
379 * Used instead of [`block_connected`] by clients that are notified of transactions rather than
380 * blocks. See [`chain::Confirm`] for calling expectations.
382 * [`block_connected`]: Self::block_connected
384 public TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[] transactions_confirmed(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Logger logger) {
385 long ret = bindings.ChannelMonitor_transactions_confirmed(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(header, 80)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(txdata, txdata_conv_28 => txdata_conv_28 != null ? txdata_conv_28.ptr : 0)), height, broadcaster.ptr, fee_estimator.ptr, logger.ptr);
387 GC.KeepAlive(header);
388 GC.KeepAlive(txdata);
389 GC.KeepAlive(height);
390 GC.KeepAlive(broadcaster);
391 GC.KeepAlive(fee_estimator);
392 GC.KeepAlive(logger);
393 if (ret >= 0 && ret <= 4096) { return null; }
394 int ret_conv_49_len = InternalUtils.getArrayLength(ret);
395 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[] ret_conv_49_arr = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[ret_conv_49_len];
396 for (int x = 0; x < ret_conv_49_len; x++) {
397 long ret_conv_49 = InternalUtils.getU64ArrayElem(ret, x);
398 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ ret_conv_49_hu_conv = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ(null, ret_conv_49);
399 if (ret_conv_49_hu_conv != null) { ret_conv_49_hu_conv.ptrs_to.AddLast(this); };
400 ret_conv_49_arr[x] = ret_conv_49_hu_conv;
402 bindings.free_buffer(ret);
403 if (this != null) { this.ptrs_to.AddLast(broadcaster); };
404 if (this != null) { this.ptrs_to.AddLast(fee_estimator); };
405 if (this != null) { this.ptrs_to.AddLast(logger); };
406 return ret_conv_49_arr;
410 * Processes a transaction that was reorganized out of the chain.
412 * Used instead of [`block_disconnected`] by clients that are notified of transactions rather
413 * than blocks. See [`chain::Confirm`] for calling expectations.
415 * [`block_disconnected`]: Self::block_disconnected
417 public void transaction_unconfirmed(byte[] txid, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Logger logger) {
418 bindings.ChannelMonitor_transaction_unconfirmed(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(txid, 32)), broadcaster.ptr, fee_estimator.ptr, logger.ptr);
421 GC.KeepAlive(broadcaster);
422 GC.KeepAlive(fee_estimator);
423 GC.KeepAlive(logger);
424 if (this != null) { this.ptrs_to.AddLast(broadcaster); };
425 if (this != null) { this.ptrs_to.AddLast(fee_estimator); };
426 if (this != null) { this.ptrs_to.AddLast(logger); };
430 * Updates the monitor with the current best chain tip, returning new outputs to watch. See
431 * [`block_connected`] for details.
433 * Used instead of [`block_connected`] by clients that are notified of transactions rather than
434 * blocks. See [`chain::Confirm`] for calling expectations.
436 * [`block_connected`]: Self::block_connected
438 public TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[] best_block_updated(byte[] header, int height, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Logger logger) {
439 long ret = bindings.ChannelMonitor_best_block_updated(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(header, 80)), height, broadcaster.ptr, fee_estimator.ptr, logger.ptr);
441 GC.KeepAlive(header);
442 GC.KeepAlive(height);
443 GC.KeepAlive(broadcaster);
444 GC.KeepAlive(fee_estimator);
445 GC.KeepAlive(logger);
446 if (ret >= 0 && ret <= 4096) { return null; }
447 int ret_conv_49_len = InternalUtils.getArrayLength(ret);
448 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[] ret_conv_49_arr = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ[ret_conv_49_len];
449 for (int x = 0; x < ret_conv_49_len; x++) {
450 long ret_conv_49 = InternalUtils.getU64ArrayElem(ret, x);
451 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ ret_conv_49_hu_conv = new TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ(null, ret_conv_49);
452 if (ret_conv_49_hu_conv != null) { ret_conv_49_hu_conv.ptrs_to.AddLast(this); };
453 ret_conv_49_arr[x] = ret_conv_49_hu_conv;
455 bindings.free_buffer(ret);
456 if (this != null) { this.ptrs_to.AddLast(broadcaster); };
457 if (this != null) { this.ptrs_to.AddLast(fee_estimator); };
458 if (this != null) { this.ptrs_to.AddLast(logger); };
459 return ret_conv_49_arr;
463 * Returns the set of txids that should be monitored for re-organization out of the chain.
465 public TwoTuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZ[] get_relevant_txids() {
466 long ret = bindings.ChannelMonitor_get_relevant_txids(this.ptr);
468 if (ret >= 0 && ret <= 4096) { return null; }
469 int ret_conv_49_len = InternalUtils.getArrayLength(ret);
470 TwoTuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZ[] ret_conv_49_arr = new TwoTuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZ[ret_conv_49_len];
471 for (int x = 0; x < ret_conv_49_len; x++) {
472 long ret_conv_49 = InternalUtils.getU64ArrayElem(ret, x);
473 TwoTuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZ ret_conv_49_hu_conv = new TwoTuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZ(null, ret_conv_49);
474 if (ret_conv_49_hu_conv != null) { ret_conv_49_hu_conv.ptrs_to.AddLast(this); };
475 ret_conv_49_arr[x] = ret_conv_49_hu_conv;
477 bindings.free_buffer(ret);
478 return ret_conv_49_arr;
482 * Gets the latest best block which was connected either via the [`chain::Listen`] or
483 * [`chain::Confirm`] interfaces.
485 public BestBlock current_best_block() {
486 long ret = bindings.ChannelMonitor_current_best_block(this.ptr);
488 if (ret >= 0 && ret <= 4096) { return null; }
489 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
490 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
495 * Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is
496 * crucial in preventing certain classes of pinning attacks, detecting substantial mempool
497 * feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
498 * invoking this every 30 seconds, or lower if running in an environment with spotty
499 * connections, like on mobile.
501 public void rebroadcast_pending_claims(org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.FeeEstimator fee_estimator, org.ldk.structs.Logger logger) {
502 bindings.ChannelMonitor_rebroadcast_pending_claims(this.ptr, broadcaster.ptr, fee_estimator.ptr, logger.ptr);
504 GC.KeepAlive(broadcaster);
505 GC.KeepAlive(fee_estimator);
506 GC.KeepAlive(logger);
507 if (this != null) { this.ptrs_to.AddLast(broadcaster); };
508 if (this != null) { this.ptrs_to.AddLast(fee_estimator); };
509 if (this != null) { this.ptrs_to.AddLast(logger); };
513 * Returns the descriptors for relevant outputs (i.e., those that we can spend) within the
514 * transaction if they exist and the transaction has at least [`ANTI_REORG_DELAY`]
515 * confirmations. For [`SpendableOutputDescriptor::DelayedPaymentOutput`] descriptors to be
516 * returned, the transaction must have at least `max(ANTI_REORG_DELAY, to_self_delay)`
519 * Descriptors returned by this method are primarily exposed via [`Event::SpendableOutputs`]
520 * once they are no longer under reorg risk. This method serves as a way to retrieve these
521 * descriptors at a later time, either for historical purposes, or to replay any
522 * missed/unhandled descriptors. For the purpose of gathering historical records, if the
523 * channel close has fully resolved (i.e., [`ChannelMonitor::get_claimable_balances`] returns
524 * an empty set), you can retrieve all spendable outputs by providing all descendant spending
525 * transactions starting from the channel's funding transaction and going down three levels.
527 * `tx` is a transaction we'll scan the outputs of. Any transaction can be provided. If any
528 * outputs which can be spent by us are found, at least one descriptor is returned.
530 * `confirmation_height` must be the height of the block in which `tx` was included in.
532 public SpendableOutputDescriptor[] get_spendable_outputs(byte[] tx, int confirmation_height) {
533 long ret = bindings.ChannelMonitor_get_spendable_outputs(this.ptr, InternalUtils.encodeUint8Array(tx), confirmation_height);
536 GC.KeepAlive(confirmation_height);
537 if (ret >= 0 && ret <= 4096) { return null; }
538 int ret_conv_27_len = InternalUtils.getArrayLength(ret);
539 SpendableOutputDescriptor[] ret_conv_27_arr = new SpendableOutputDescriptor[ret_conv_27_len];
540 for (int b = 0; b < ret_conv_27_len; b++) {
541 long ret_conv_27 = InternalUtils.getU64ArrayElem(ret, b);
542 org.ldk.structs.SpendableOutputDescriptor ret_conv_27_hu_conv = org.ldk.structs.SpendableOutputDescriptor.constr_from_ptr(ret_conv_27);
543 if (ret_conv_27_hu_conv != null) { ret_conv_27_hu_conv.ptrs_to.AddLast(this); };
544 ret_conv_27_arr[b] = ret_conv_27_hu_conv;
546 bindings.free_buffer(ret);
547 return ret_conv_27_arr;
551 * Gets the balances in this channel which are either claimable by us if we were to
552 * force-close the channel now or which are claimable on-chain (possibly awaiting
555 * Any balances in the channel which are available on-chain (excluding on-chain fees) are
556 * included here until an [`Event::SpendableOutputs`] event has been generated for the
557 * balance, or until our counterparty has claimed the balance and accrued several
558 * confirmations on the claim transaction.
560 * Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
561 * LDK prior to 0.0.111, not all or excess balances may be included.
563 * See [`Balance`] for additional details on the types of claimable balances which
564 * may be returned here and their meanings.
566 public Balance[] get_claimable_balances() {
567 long ret = bindings.ChannelMonitor_get_claimable_balances(this.ptr);
569 if (ret >= 0 && ret <= 4096) { return null; }
570 int ret_conv_9_len = InternalUtils.getArrayLength(ret);
571 Balance[] ret_conv_9_arr = new Balance[ret_conv_9_len];
572 for (int j = 0; j < ret_conv_9_len; j++) {
573 long ret_conv_9 = InternalUtils.getU64ArrayElem(ret, j);
574 org.ldk.structs.Balance ret_conv_9_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret_conv_9);
575 if (ret_conv_9_hu_conv != null) { ret_conv_9_hu_conv.ptrs_to.AddLast(this); };
576 ret_conv_9_arr[j] = ret_conv_9_hu_conv;
578 bindings.free_buffer(ret);
579 return ret_conv_9_arr;