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 * An implementation of [`chain::Watch`] for monitoring channels.
13 * Connected and disconnected blocks must be provided to `ChainMonitor` as documented by
14 * [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
15 * or used independently to monitor channels remotely. See the [module-level documentation] for
18 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
19 * [module-level documentation]: crate::chain::chainmonitor
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class ChainMonitor extends CommonBase {
23 ChainMonitor(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.ChainMonitor_free(ptr); }
31 * Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
33 * When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
34 * will call back to it indicating transactions and outputs of interest. This allows clients to
35 * pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
36 * always need to fetch full blocks absent another means for determining which blocks contain
37 * transactions relevant to the watched channels.
39 * Note that chain_source (or a relevant inner pointer) may be NULL or all-0s to represent None
41 public static ChainMonitor of(@Nullable Filter chain_source, BroadcasterInterface broadcaster, Logger logger, FeeEstimator feeest, Persist persister) {
42 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);
43 if (ret < 1024) { return null; }
44 ChainMonitor ret_hu_conv = new ChainMonitor(null, ret);
45 ret_hu_conv.ptrs_to.add(ret_hu_conv);
46 ret_hu_conv.ptrs_to.add(chain_source);
47 ret_hu_conv.ptrs_to.add(broadcaster);
48 ret_hu_conv.ptrs_to.add(logger);
49 ret_hu_conv.ptrs_to.add(feeest);
50 ret_hu_conv.ptrs_to.add(persister);
55 * Constructs a new Listen which calls the relevant methods on this_arg.
56 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
58 public Listen as_Listen() {
59 long ret = bindings.ChainMonitor_as_Listen(this.ptr);
60 if (ret < 1024) { return null; }
61 Listen ret_hu_conv = new Listen(null, ret);
62 ret_hu_conv.ptrs_to.add(this);
67 * Constructs a new Confirm which calls the relevant methods on this_arg.
68 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
70 public Confirm as_Confirm() {
71 long ret = bindings.ChainMonitor_as_Confirm(this.ptr);
72 if (ret < 1024) { return null; }
73 Confirm ret_hu_conv = new Confirm(null, ret);
74 ret_hu_conv.ptrs_to.add(this);
79 * Constructs a new Watch which calls the relevant methods on this_arg.
80 * This copies the `inner` pointer in this_arg and thus the returned Watch must be freed before this_arg is
82 public Watch as_Watch() {
83 long ret = bindings.ChainMonitor_as_Watch(this.ptr);
84 if (ret < 1024) { return null; }
85 Watch ret_hu_conv = new Watch(null, ret);
86 ret_hu_conv.ptrs_to.add(this);
91 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
92 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
94 public EventsProvider as_EventsProvider() {
95 long ret = bindings.ChainMonitor_as_EventsProvider(this.ptr);
96 if (ret < 1024) { return null; }
97 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
98 ret_hu_conv.ptrs_to.add(this);