[C#] Update auto-generated C# bindings
[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         ThreeTuple_OutPointCVec_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 == null ? 0 : 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                         ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] ret = arg.release_pending_monitor_events();
106                                 GC.KeepAlive(arg);
107                         long result = InternalUtils.encodeUint64Array(InternalUtils.mapArray(ret, ret_conv_49 => ret_conv_49 == null ? 0 : ret_conv_49.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 == null ? 0 : funding_txo.ptr, monitor == null ? 0 : 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                 if (this != null) { this.ptrs_to.AddLast(funding_txo); };
149                 if (this != null) { this.ptrs_to.AddLast(monitor); };
150                 return ret_hu_conv;
151         }
152
153         /**
154          * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
155          * 
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.
162          * 
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.
167          * 
168          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
169          */
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 == null ? 0 : funding_txo.ptr, update == null ? 0 : update.ptr);
172                 GC.KeepAlive(this);
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); };
177                 return ret;
178         }
179
180         /**
181          * Returns any monitor events since the last call. Subsequent calls must only return new
182          * events.
183          * 
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
186          * to disk.
187          * 
188          * For details on asynchronous [`ChannelMonitor`] updating and returning
189          * [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
190          */
191         public ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events() {
192                 long ret = bindings.Watch_release_pending_monitor_events(this.ptr);
193                 GC.KeepAlive(this);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 int ret_conv_49_len = InternalUtils.getArrayLength(ret);
196                 ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] ret_conv_49_arr = new ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[ret_conv_49_len];
197                 for (int x = 0; x < ret_conv_49_len; x++) {
198                         long ret_conv_49 = InternalUtils.getU64ArrayElem(ret, x);
199                         ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ ret_conv_49_hu_conv = new ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ(null, ret_conv_49);
200                         if (ret_conv_49_hu_conv != null) { ret_conv_49_hu_conv.ptrs_to.AddLast(this); };
201                         ret_conv_49_arr[x] = ret_conv_49_hu_conv;
202                 }
203                 bindings.free_buffer(ret);
204                 return ret_conv_49_arr;
205         }
206
207 }
208 } } }