7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of Watch */
12 public interface WatchInterface {
13 /**Watches a channel identified by `funding_txo` using `monitor`.
15 * Implementations are responsible for watching the chain for the funding transaction along
16 * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
17 * calling [`block_connected`] and [`block_disconnected`] on the monitor.
19 * A return of `Err(())` indicates that the channel should immediately be force-closed without
20 * broadcasting the funding transaction.
22 * If the given `funding_txo` has previously been registered via `watch_channel`, `Err(())`
25 * [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
26 * [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
27 * [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected
29 Result_ChannelMonitorUpdateStatusNoneZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor);
30 /**Updates a channel identified by `funding_txo` by applying `update` to its monitor.
32 * Implementations must call [`ChannelMonitor::update_monitor`] with the given update. This
33 * may fail (returning an `Err(())`), in which case this should return
34 * [`ChannelMonitorUpdateStatus::InProgress`] (and the update should never complete). This
35 * generally implies the channel has been closed (either by the funding outpoint being spent
36 * on-chain or the [`ChannelMonitor`] having decided to do so and broadcasted a transaction),
37 * and the [`ChannelManager`] state will be updated once it sees the funding spend on-chain.
39 * In general, persistence failures should be retried after returning
40 * [`ChannelMonitorUpdateStatus::InProgress`] and eventually complete. If a failure truly
41 * cannot be retried, the node should shut down immediately after returning
42 * [`ChannelMonitorUpdateStatus::UnrecoverableError`], see its documentation for more info.
44 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
46 ChannelMonitorUpdateStatus update_channel(OutPoint funding_txo, ChannelMonitorUpdate update);
47 /**Returns any monitor events since the last call. Subsequent calls must only return new
50 * Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
51 * further events may be returned here until the [`ChannelMonitor`] has been fully persisted
54 * For details on asynchronous [`ChannelMonitor`] updating and returning
55 * [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
57 FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events();
61 * The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as
62 * blocks are connected and disconnected.
64 * Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are
65 * responsible for maintaining a set of monitors such that they can be updated as channel state
66 * changes. On each update, *all copies* of a [`ChannelMonitor`] must be updated and the update
67 * persisted to disk to ensure that the latest [`ChannelMonitor`] state can be reloaded if the
68 * application crashes.
70 * See method documentation and [`ChannelMonitorUpdateStatus`] for specific requirements.
72 public class Watch : CommonBase {
73 internal bindings.LDKWatch bindings_instance;
74 internal long instance_idx;
76 internal Watch(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
78 if (ptr != 0) { bindings.Watch_free(ptr); }
81 private class LDKWatchHolder { internal Watch held; }
82 private class LDKWatchImpl : bindings.LDKWatch {
83 internal LDKWatchImpl(WatchInterface arg, LDKWatchHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
84 private WatchInterface arg;
85 private LDKWatchHolder impl_holder;
86 public long watch_channel(long _funding_txo, long _monitor) {
87 org.ldk.structs.OutPoint _funding_txo_hu_conv = null; if (_funding_txo < 0 || _funding_txo > 4096) { _funding_txo_hu_conv = new org.ldk.structs.OutPoint(null, _funding_txo); }
88 if (_funding_txo_hu_conv != null) { _funding_txo_hu_conv.ptrs_to.AddLast(this); };
89 org.ldk.structs.ChannelMonitor _monitor_hu_conv = null; if (_monitor < 0 || _monitor > 4096) { _monitor_hu_conv = new org.ldk.structs.ChannelMonitor(null, _monitor); }
90 if (_monitor_hu_conv != null) { _monitor_hu_conv.ptrs_to.AddLast(this); };
91 Result_ChannelMonitorUpdateStatusNoneZ ret = arg.watch_channel(_funding_txo_hu_conv, _monitor_hu_conv);
93 long result = ret.clone_ptr();
96 public ChannelMonitorUpdateStatus update_channel(long _funding_txo, long _update) {
97 org.ldk.structs.OutPoint _funding_txo_hu_conv = null; if (_funding_txo < 0 || _funding_txo > 4096) { _funding_txo_hu_conv = new org.ldk.structs.OutPoint(null, _funding_txo); }
98 if (_funding_txo_hu_conv != null) { _funding_txo_hu_conv.ptrs_to.AddLast(this); };
99 org.ldk.structs.ChannelMonitorUpdate _update_hu_conv = null; if (_update < 0 || _update > 4096) { _update_hu_conv = new org.ldk.structs.ChannelMonitorUpdate(null, _update); }
100 ChannelMonitorUpdateStatus ret = arg.update_channel(_funding_txo_hu_conv, _update_hu_conv);
104 public long release_pending_monitor_events() {
105 FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] ret = arg.release_pending_monitor_events();
107 long result = InternalUtils.encodeUint64Array(InternalUtils.mapArray(ret, ret_conv_57 => ret_conv_57.clone_ptr()));
112 /** Creates a new instance of Watch from a given implementation */
113 public static Watch new_impl(WatchInterface arg) {
114 LDKWatchHolder impl_holder = new LDKWatchHolder();
115 LDKWatchImpl impl = new LDKWatchImpl(arg, impl_holder);
116 long[] ptr_idx = bindings.LDKWatch_new(impl);
118 impl_holder.held = new Watch(null, ptr_idx[0]);
119 impl_holder.held.instance_idx = ptr_idx[1];
120 impl_holder.held.bindings_instance = impl;
121 return impl_holder.held;
125 * Watches a channel identified by `funding_txo` using `monitor`.
127 * Implementations are responsible for watching the chain for the funding transaction along
128 * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
129 * calling [`block_connected`] and [`block_disconnected`] on the monitor.
131 * A return of `Err(())` indicates that the channel should immediately be force-closed without
132 * broadcasting the funding transaction.
134 * If the given `funding_txo` has previously been registered via `watch_channel`, `Err(())`
137 * [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
138 * [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
139 * [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected
141 public Result_ChannelMonitorUpdateStatusNoneZ watch_channel(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.ChannelMonitor monitor) {
142 long ret = bindings.Watch_watch_channel(this.ptr, funding_txo.ptr, monitor.ptr);
144 GC.KeepAlive(funding_txo);
145 GC.KeepAlive(monitor);
146 if (ret >= 0 && ret <= 4096) { return null; }
147 Result_ChannelMonitorUpdateStatusNoneZ ret_hu_conv = Result_ChannelMonitorUpdateStatusNoneZ.constr_from_ptr(ret);
148 if (this != null) { this.ptrs_to.AddLast(funding_txo); };
149 if (this != null) { this.ptrs_to.AddLast(monitor); };
154 * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
156 * Implementations must call [`ChannelMonitor::update_monitor`] with the given update. This
157 * may fail (returning an `Err(())`), in which case this should return
158 * [`ChannelMonitorUpdateStatus::InProgress`] (and the update should never complete). This
159 * generally implies the channel has been closed (either by the funding outpoint being spent
160 * on-chain or the [`ChannelMonitor`] having decided to do so and broadcasted a transaction),
161 * and the [`ChannelManager`] state will be updated once it sees the funding spend on-chain.
163 * In general, persistence failures should be retried after returning
164 * [`ChannelMonitorUpdateStatus::InProgress`] and eventually complete. If a failure truly
165 * cannot be retried, the node should shut down immediately after returning
166 * [`ChannelMonitorUpdateStatus::UnrecoverableError`], see its documentation for more info.
168 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
170 public ChannelMonitorUpdateStatus update_channel(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.ChannelMonitorUpdate update) {
171 ChannelMonitorUpdateStatus ret = bindings.Watch_update_channel(this.ptr, funding_txo.ptr, update.ptr);
173 GC.KeepAlive(funding_txo);
174 GC.KeepAlive(update);
175 if (this != null) { this.ptrs_to.AddLast(funding_txo); };
176 if (this != null) { this.ptrs_to.AddLast(update); };
181 * Returns any monitor events since the last call. Subsequent calls must only return new
184 * Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
185 * further events may be returned here until the [`ChannelMonitor`] has been fully persisted
188 * For details on asynchronous [`ChannelMonitor`] updating and returning
189 * [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
191 public FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events() {
192 long ret = bindings.Watch_release_pending_monitor_events(this.ptr);
194 if (ret >= 0 && ret <= 4096) { return null; }
195 int ret_conv_57_len = InternalUtils.getArrayLength(ret);
196 FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] ret_conv_57_arr = new FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[ret_conv_57_len];
197 for (int f = 0; f < ret_conv_57_len; f++) {
198 long ret_conv_57 = InternalUtils.getU64ArrayElem(ret, f);
199 FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ ret_conv_57_hu_conv = new FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ(null, ret_conv_57);
200 if (ret_conv_57_hu_conv != null) { ret_conv_57_hu_conv.ptrs_to.AddLast(this); };
201 ret_conv_57_arr[f] = ret_conv_57_hu_conv;
203 bindings.free_buffer(ret);
204 return ret_conv_57_arr;