]> git.bitcoin.ninja Git - ldk-java/blob - c_sharp/src/org/ldk/structs/Watch.cs
Update CI references to LDK 0.0.124 drop stale memchr pins
[ldk-java] / c_sharp / src / org / ldk / structs / Watch.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of Watch */
12 public interface WatchInterface {
13         /**Watches a channel identified by `funding_txo` using `monitor`.
14          * 
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.
18          * 
19          * A return of `Err(())` indicates that the channel should immediately be force-closed without
20          * broadcasting the funding transaction.
21          * 
22          * If the given `funding_txo` has previously been registered via `watch_channel`, `Err(())`
23          * must be returned.
24          * 
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
28          */
29         Result_ChannelMonitorUpdateStatusNoneZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor);
30         /**Updates a channel identified by `funding_txo` by applying `update` to its monitor.
31          * 
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.
38          * 
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.
43          * 
44          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
45          */
46         ChannelMonitorUpdateStatus update_channel(OutPoint funding_txo, ChannelMonitorUpdate update);
47         /**Returns any monitor events since the last call. Subsequent calls must only return new
48          * events.
49          * 
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
52          * to disk.
53          * 
54          * For details on asynchronous [`ChannelMonitor`] updating and returning
55          * [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
56          */
57         FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events();
58 }
59
60 /**
61  * The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as
62  * blocks are connected and disconnected.
63  * 
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.
69  * 
70  * See method documentation and [`ChannelMonitorUpdateStatus`] for specific requirements.
71  */
72 public class Watch : CommonBase {
73         internal bindings.LDKWatch bindings_instance;
74         internal long instance_idx;
75
76         internal Watch(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
77         ~Watch() {
78                 if (ptr != 0) { bindings.Watch_free(ptr); }
79         }
80
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);
92                                 GC.KeepAlive(arg);
93                         long result = ret.clone_ptr();
94                         return result;
95                 }
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);
101                                 GC.KeepAlive(arg);
102                         return ret;
103                 }
104                 public long release_pending_monitor_events() {
105                         FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] ret = arg.release_pending_monitor_events();
106                                 GC.KeepAlive(arg);
107                         long result = InternalUtils.encodeUint64Array(InternalUtils.mapArray(ret, ret_conv_57 => ret_conv_57.clone_ptr()));
108                         return result;
109                 }
110         }
111
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);
117
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;
122         }
123
124         /**
125          * Watches a channel identified by `funding_txo` using `monitor`.
126          * 
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.
130          * 
131          * A return of `Err(())` indicates that the channel should immediately be force-closed without
132          * broadcasting the funding transaction.
133          * 
134          * If the given `funding_txo` has previously been registered via `watch_channel`, `Err(())`
135          * must be returned.
136          * 
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
140          */
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);
143                 GC.KeepAlive(this);
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                 return ret_hu_conv;
149         }
150
151         /**
152          * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
153          * 
154          * Implementations must call [`ChannelMonitor::update_monitor`] with the given update. This
155          * may fail (returning an `Err(())`), in which case this should return
156          * [`ChannelMonitorUpdateStatus::InProgress`] (and the update should never complete). This
157          * generally implies the channel has been closed (either by the funding outpoint being spent
158          * on-chain or the [`ChannelMonitor`] having decided to do so and broadcasted a transaction),
159          * and the [`ChannelManager`] state will be updated once it sees the funding spend on-chain.
160          * 
161          * In general, persistence failures should be retried after returning
162          * [`ChannelMonitorUpdateStatus::InProgress`] and eventually complete. If a failure truly
163          * cannot be retried, the node should shut down immediately after returning
164          * [`ChannelMonitorUpdateStatus::UnrecoverableError`], see its documentation for more info.
165          * 
166          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
167          */
168         public ChannelMonitorUpdateStatus update_channel(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.ChannelMonitorUpdate update) {
169                 ChannelMonitorUpdateStatus ret = bindings.Watch_update_channel(this.ptr, funding_txo.ptr, update.ptr);
170                 GC.KeepAlive(this);
171                 GC.KeepAlive(funding_txo);
172                 GC.KeepAlive(update);
173                 if (this != null) { this.ptrs_to.AddLast(update); };
174                 return ret;
175         }
176
177         /**
178          * Returns any monitor events since the last call. Subsequent calls must only return new
179          * events.
180          * 
181          * Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
182          * further events may be returned here until the [`ChannelMonitor`] has been fully persisted
183          * to disk.
184          * 
185          * For details on asynchronous [`ChannelMonitor`] updating and returning
186          * [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
187          */
188         public FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events() {
189                 long ret = bindings.Watch_release_pending_monitor_events(this.ptr);
190                 GC.KeepAlive(this);
191                 if (ret >= 0 && ret <= 4096) { return null; }
192                 int ret_conv_57_len = InternalUtils.getArrayLength(ret);
193                 FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] ret_conv_57_arr = new FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[ret_conv_57_len];
194                 for (int f = 0; f < ret_conv_57_len; f++) {
195                         long ret_conv_57 = InternalUtils.getU64ArrayElem(ret, f);
196                         FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ ret_conv_57_hu_conv = new FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ(null, ret_conv_57);
197                         if (ret_conv_57_hu_conv != null) { ret_conv_57_hu_conv.ptrs_to.AddLast(this); };
198                         ret_conv_57_arr[f] = ret_conv_57_hu_conv;
199                 }
200                 bindings.free_buffer(ret);
201                 return ret_conv_57_arr;
202         }
203
204 }
205 } } }