6 namespace org { namespace ldk { namespace structs {
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 public class ChainMonitor : CommonBase {
21 internal ChainMonitor(object _dummy, long ptr) : base(ptr) { }
23 if (ptr != 0) { bindings.ChainMonitor_free(ptr); }
27 * Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
29 * When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
30 * will call back to it indicating transactions and outputs of interest. This allows clients to
31 * pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
32 * always need to fetch full blocks absent another means for determining which blocks contain
33 * transactions relevant to the watched channels.
35 public static ChainMonitor of(org.ldk.structs.Option_FilterZ chain_source, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.Logger logger, org.ldk.structs.FeeEstimator feeest, org.ldk.structs.Persist persister) {
36 long ret = bindings.ChainMonitor_new(chain_source.ptr, broadcaster == null ? 0 : broadcaster.ptr, logger == null ? 0 : logger.ptr, feeest == null ? 0 : feeest.ptr, persister == null ? 0 : persister.ptr);
37 GC.KeepAlive(chain_source);
38 GC.KeepAlive(broadcaster);
41 GC.KeepAlive(persister);
42 if (ret >= 0 && ret <= 4096) { return null; }
43 org.ldk.structs.ChainMonitor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChainMonitor(null, ret); }
44 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
45 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(chain_source); };
46 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(broadcaster); };
47 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
48 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(feeest); };
49 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(persister); };
54 * Gets the balances in the contained [`ChannelMonitor`]s which are claimable on-chain or
55 * claims which are awaiting confirmation.
57 * Includes the balances from each [`ChannelMonitor`] *except* those included in
58 * `ignored_channels`, allowing you to filter out balances from channels which are still open
59 * (and whose balance should likely be pulled from the [`ChannelDetails`]).
61 * See [`ChannelMonitor::get_claimable_balances`] for more details on the exact criteria for
62 * inclusion in the return value.
64 public Balance[] get_claimable_balances(ChannelDetails[] ignored_channels) {
65 long[] ret = bindings.ChainMonitor_get_claimable_balances(this.ptr, ignored_channels != null ? InternalUtils.mapArray(ignored_channels, ignored_channels_conv_16 => ignored_channels_conv_16 == null ? 0 : ignored_channels_conv_16.ptr) : null);
67 GC.KeepAlive(ignored_channels);
68 int ret_conv_9_len = ret.Length;
69 Balance[] ret_conv_9_arr = new Balance[ret_conv_9_len];
70 for (int j = 0; j < ret_conv_9_len; j++) {
71 long ret_conv_9 = ret[j];
72 org.ldk.structs.Balance ret_conv_9_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret_conv_9);
73 if (ret_conv_9_hu_conv != null) { ret_conv_9_hu_conv.ptrs_to.AddLast(this); };
74 ret_conv_9_arr[j] = ret_conv_9_hu_conv;
76 foreach (ChannelDetails ignored_channels_conv_16 in ignored_channels) { if (this != null) { this.ptrs_to.AddLast(ignored_channels_conv_16); }; };
77 return ret_conv_9_arr;
81 * Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no
82 * such [`ChannelMonitor`] is currently being monitored for.
84 * Note that the result holds a mutex over our monitor set, and should not be held
87 public Result_LockedChannelMonitorNoneZ get_monitor(org.ldk.structs.OutPoint funding_txo) {
88 long ret = bindings.ChainMonitor_get_monitor(this.ptr, funding_txo == null ? 0 : funding_txo.ptr);
90 GC.KeepAlive(funding_txo);
91 if (ret >= 0 && ret <= 4096) { return null; }
92 Result_LockedChannelMonitorNoneZ ret_hu_conv = Result_LockedChannelMonitorNoneZ.constr_from_ptr(ret);
93 if (this != null) { this.ptrs_to.AddLast(funding_txo); };
98 * Lists the funding outpoint of each [`ChannelMonitor`] being monitored.
100 * Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always
101 * monitoring for on-chain state resolutions.
103 public OutPoint[] list_monitors() {
104 long[] ret = bindings.ChainMonitor_list_monitors(this.ptr);
106 int ret_conv_10_len = ret.Length;
107 OutPoint[] ret_conv_10_arr = new OutPoint[ret_conv_10_len];
108 for (int k = 0; k < ret_conv_10_len; k++) {
109 long ret_conv_10 = ret[k];
110 org.ldk.structs.OutPoint ret_conv_10_hu_conv = null; if (ret_conv_10 < 0 || ret_conv_10 > 4096) { ret_conv_10_hu_conv = new org.ldk.structs.OutPoint(null, ret_conv_10); }
111 if (ret_conv_10_hu_conv != null) { ret_conv_10_hu_conv.ptrs_to.AddLast(this); };
112 ret_conv_10_arr[k] = ret_conv_10_hu_conv;
114 return ret_conv_10_arr;
118 * Lists the pending updates for each [`ChannelMonitor`] (by `OutPoint` being monitored).
120 public TwoTuple_OutPointCVec_MonitorUpdateIdZZ[] list_pending_monitor_updates() {
121 long[] ret = bindings.ChainMonitor_list_pending_monitor_updates(this.ptr);
123 int ret_conv_41_len = ret.Length;
124 TwoTuple_OutPointCVec_MonitorUpdateIdZZ[] ret_conv_41_arr = new TwoTuple_OutPointCVec_MonitorUpdateIdZZ[ret_conv_41_len];
125 for (int p = 0; p < ret_conv_41_len; p++) {
126 long ret_conv_41 = ret[p];
127 TwoTuple_OutPointCVec_MonitorUpdateIdZZ ret_conv_41_hu_conv = new TwoTuple_OutPointCVec_MonitorUpdateIdZZ(null, ret_conv_41);
128 if (ret_conv_41_hu_conv != null) { ret_conv_41_hu_conv.ptrs_to.AddLast(this); };
129 ret_conv_41_arr[p] = ret_conv_41_hu_conv;
131 return ret_conv_41_arr;
135 * Indicates the persistence of a [`ChannelMonitor`] has completed after
136 * [`ChannelMonitorUpdateStatus::InProgress`] was returned from an update operation.
138 * Thus, the anticipated use is, at a high level:
139 * 1) This [`ChainMonitor`] calls [`Persist::update_persisted_channel`] which stores the
140 * update to disk and begins updating any remote (e.g. watchtower/backup) copies,
141 * returning [`ChannelMonitorUpdateStatus::InProgress`],
142 * 2) once all remote copies are updated, you call this function with the
143 * `completed_update_id` that completed, and once all pending updates have completed the
144 * channel will be re-enabled.
146 * Returns an [`APIError::APIMisuseError`] if `funding_txo` does not match any currently
147 * registered [`ChannelMonitor`]s.
149 public Result_NoneAPIErrorZ channel_monitor_updated(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.MonitorUpdateId completed_update_id) {
150 long ret = bindings.ChainMonitor_channel_monitor_updated(this.ptr, funding_txo == null ? 0 : funding_txo.ptr, completed_update_id == null ? 0 : completed_update_id.ptr);
152 GC.KeepAlive(funding_txo);
153 GC.KeepAlive(completed_update_id);
154 if (ret >= 0 && ret <= 4096) { return null; }
155 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
156 if (this != null) { this.ptrs_to.AddLast(funding_txo); };
157 if (this != null) { this.ptrs_to.AddLast(completed_update_id); };
162 * Constructs a new Listen which calls the relevant methods on this_arg.
163 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
165 public Listen as_Listen() {
166 long ret = bindings.ChainMonitor_as_Listen(this.ptr);
168 if (ret >= 0 && ret <= 4096) { return null; }
169 Listen ret_hu_conv = new Listen(null, ret);
170 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
175 * Constructs a new Confirm which calls the relevant methods on this_arg.
176 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
178 public Confirm as_Confirm() {
179 long ret = bindings.ChainMonitor_as_Confirm(this.ptr);
181 if (ret >= 0 && ret <= 4096) { return null; }
182 Confirm ret_hu_conv = new Confirm(null, ret);
183 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
188 * Constructs a new Watch which calls the relevant methods on this_arg.
189 * This copies the `inner` pointer in this_arg and thus the returned Watch must be freed before this_arg is
191 public Watch as_Watch() {
192 long ret = bindings.ChainMonitor_as_Watch(this.ptr);
194 if (ret >= 0 && ret <= 4096) { return null; }
195 Watch ret_hu_conv = new Watch(null, ret);
196 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
201 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
202 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
204 public EventsProvider as_EventsProvider() {
205 long ret = bindings.ChainMonitor_as_EventsProvider(this.ptr);
207 if (ret >= 0 && ret <= 4096) { return null; }
208 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
209 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };