1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
10 * An implementation of [`chain::Watch`] for monitoring channels.
12 * Connected and disconnected blocks must be provided to `ChainMonitor` as documented by
13 * [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
14 * or used independently to monitor channels remotely. See the [module-level documentation] for
17 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
18 * [module-level documentation]: crate::chain::chainmonitor
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class ChainMonitor extends CommonBase {
22 ChainMonitor(Object _dummy, long ptr) { super(ptr); }
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
26 if (ptr != 0) { bindings.ChainMonitor_free(ptr); }
30 * Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
32 * When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
33 * will call back to it indicating transactions and outputs of interest. This allows clients to
34 * pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
35 * always need to fetch full blocks absent another means for determining which blocks contain
36 * transactions relevant to the watched channels.
38 * Note that chain_source (or a relevant inner pointer) may be NULL or all-0s to represent None
40 public static ChainMonitor of(@Nullable Filter chain_source, BroadcasterInterface broadcaster, Logger logger, FeeEstimator feeest, Persist persister) {
41 long ret = bindings.ChainMonitor_new(chain_source == null ? 0 : chain_source.ptr, broadcaster == null ? 0 : broadcaster.ptr, logger == null ? 0 : logger.ptr, feeest == null ? 0 : feeest.ptr, persister == null ? 0 : persister.ptr);
42 if (ret < 1024) { return null; }
43 ChainMonitor ret_hu_conv = new ChainMonitor(null, ret);
44 ret_hu_conv.ptrs_to.add(ret_hu_conv);
45 ret_hu_conv.ptrs_to.add(chain_source);
46 ret_hu_conv.ptrs_to.add(broadcaster);
47 ret_hu_conv.ptrs_to.add(logger);
48 ret_hu_conv.ptrs_to.add(feeest);
49 ret_hu_conv.ptrs_to.add(persister);
54 * Constructs a new Listen which calls the relevant methods on this_arg.
55 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
57 public Listen as_Listen() {
58 long ret = bindings.ChainMonitor_as_Listen(this.ptr);
59 if (ret < 1024) { return null; }
60 Listen ret_hu_conv = new Listen(null, ret);
61 ret_hu_conv.ptrs_to.add(this);
66 * Constructs a new Confirm which calls the relevant methods on this_arg.
67 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
69 public Confirm as_Confirm() {
70 long ret = bindings.ChainMonitor_as_Confirm(this.ptr);
71 if (ret < 1024) { return null; }
72 Confirm ret_hu_conv = new Confirm(null, ret);
73 ret_hu_conv.ptrs_to.add(this);
78 * Constructs a new Watch which calls the relevant methods on this_arg.
79 * This copies the `inner` pointer in this_arg and thus the returned Watch must be freed before this_arg is
81 public Watch as_Watch() {
82 long ret = bindings.ChainMonitor_as_Watch(this.ptr);
83 if (ret < 1024) { return null; }
84 Watch ret_hu_conv = new Watch(null, ret);
85 ret_hu_conv.ptrs_to.add(this);
90 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
91 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
93 public EventsProvider as_EventsProvider() {
94 long ret = bindings.ChainMonitor_as_EventsProvider(this.ptr);
95 if (ret < 1024) { return null; }
96 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
97 ret_hu_conv.ptrs_to.add(this);