[C#] Update auto-generated files
[ldk-java] / c_sharp / src / org / ldk / structs / Watch.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as
10  * blocks are connected and disconnected.
11  * 
12  * Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are
13  * responsible for maintaining a set of monitors such that they can be updated accordingly as
14  * channel state changes and HTLCs are resolved. See method documentation for specific
15  * requirements.
16  * 
17  * Implementations **must** ensure that updates are successfully applied and persisted upon method
18  * completion. If an update fails with a [`PermanentFailure`], then it must immediately shut down
19  * without taking any further action such as persisting the current state.
20  * 
21  * If an implementation maintains multiple instances of a channel's monitor (e.g., by storing
22  * backup copies), then it must ensure that updates are applied across all instances. Otherwise, it
23  * could result in a revoked transaction being broadcast, allowing the counterparty to claim all
24  * funds in the channel. See [`ChannelMonitorUpdateStatus`] for more details about how to handle
25  * multiple instances.
26  * 
27  * [`PermanentFailure`]: ChannelMonitorUpdateStatus::PermanentFailure
28  */
29 public class Watch : CommonBase {
30         internal readonly bindings.LDKWatch bindings_instance;
31         internal Watch(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
32         private Watch(bindings.LDKWatch arg) : base(bindings.LDKWatch_new(arg)) {
33                 this.ptrs_to.AddLast(arg);
34                 this.bindings_instance = arg;
35         }
36         ~Watch() {
37                 if (ptr != 0) { bindings.Watch_free(ptr); }
38         }
39
40         public interface WatchInterface {
41                 /**
42                  * Watches a channel identified by `funding_txo` using `monitor`.
43                  * 
44                  * Implementations are responsible for watching the chain for the funding transaction along
45                  * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
46                  * calling [`block_connected`] and [`block_disconnected`] on the monitor.
47                  * 
48                  * Note: this interface MUST error with [`ChannelMonitorUpdateStatus::PermanentFailure`] if
49                  * the given `funding_txo` has previously been registered via `watch_channel`.
50                  * 
51                  * [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
52                  * [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
53                  * [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected
54                  */
55                 ChannelMonitorUpdateStatus watch_channel(OutPoint _funding_txo, ChannelMonitor _monitor);
56                 /**
57                  * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
58                  * 
59                  * Implementations must call [`update_monitor`] with the given update. See
60                  * [`ChannelMonitorUpdateStatus`] for invariants around returning an error.
61                  * 
62                  * [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor
63                  */
64                 ChannelMonitorUpdateStatus update_channel(OutPoint _funding_txo, ChannelMonitorUpdate _update);
65                 /**
66                  * Returns any monitor events since the last call. Subsequent calls must only return new
67                  * events.
68                  * 
69                  * Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
70                  * further events may be returned here until the [`ChannelMonitor`] has been fully persisted
71                  * to disk.
72                  * 
73                  * For details on asynchronous [`ChannelMonitor`] updating and returning
74                  * [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
75                  */
76                 ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events();
77         }
78         private class LDKWatchHolder { internal Watch held; }
79         private class LDKWatchImpl : bindings.LDKWatch {
80                 internal LDKWatchImpl(WatchInterface arg, LDKWatchHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
81                 private WatchInterface arg;
82                 private LDKWatchHolder impl_holder;
83                 public ChannelMonitorUpdateStatus watch_channel(long _funding_txo, long _monitor) {
84                         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); }
85                         if (_funding_txo_hu_conv != null) { _funding_txo_hu_conv.ptrs_to.AddLast(this); };
86                         org.ldk.structs.ChannelMonitor _monitor_hu_conv = null; if (_monitor < 0 || _monitor > 4096) { _monitor_hu_conv = new org.ldk.structs.ChannelMonitor(null, _monitor); }
87                         if (_monitor_hu_conv != null) { _monitor_hu_conv.ptrs_to.AddLast(this); };
88                         ChannelMonitorUpdateStatus ret = arg.watch_channel(_funding_txo_hu_conv, _monitor_hu_conv);
89                                 GC.KeepAlive(arg);
90                         return ret;
91                 }
92                 public ChannelMonitorUpdateStatus update_channel(long _funding_txo, long _update) {
93                         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); }
94                         if (_funding_txo_hu_conv != null) { _funding_txo_hu_conv.ptrs_to.AddLast(this); };
95                         org.ldk.structs.ChannelMonitorUpdate _update_hu_conv = null; if (_update < 0 || _update > 4096) { _update_hu_conv = new org.ldk.structs.ChannelMonitorUpdate(null, _update); }
96                         ChannelMonitorUpdateStatus ret = arg.update_channel(_funding_txo_hu_conv, _update_hu_conv);
97                                 GC.KeepAlive(arg);
98                         return ret;
99                 }
100                 public long[] release_pending_monitor_events() {
101                         ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] ret = arg.release_pending_monitor_events();
102                                 GC.KeepAlive(arg);
103                         long[] result = ret != null ? InternalUtils.mapArray(ret, ret_conv_49 => ret_conv_49 == null ? 0 : ret_conv_49.clone_ptr()) : null;
104                         return result;
105                 }
106         }
107         public static Watch new_impl(WatchInterface arg) {
108                 LDKWatchHolder impl_holder = new LDKWatchHolder();
109                 impl_holder.held = new Watch(new LDKWatchImpl(arg, impl_holder));
110                 return impl_holder.held;
111         }
112         /**
113          * Watches a channel identified by `funding_txo` using `monitor`.
114          * 
115          * Implementations are responsible for watching the chain for the funding transaction along
116          * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
117          * calling [`block_connected`] and [`block_disconnected`] on the monitor.
118          * 
119          * Note: this interface MUST error with [`ChannelMonitorUpdateStatus::PermanentFailure`] if
120          * the given `funding_txo` has previously been registered via `watch_channel`.
121          * 
122          * [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
123          * [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
124          * [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected
125          */
126         public ChannelMonitorUpdateStatus watch_channel(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.ChannelMonitor monitor) {
127                 ChannelMonitorUpdateStatus ret = bindings.Watch_watch_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr, monitor == null ? 0 : monitor.ptr);
128                 GC.KeepAlive(this);
129                 GC.KeepAlive(funding_txo);
130                 GC.KeepAlive(monitor);
131                 if (this != null) { this.ptrs_to.AddLast(funding_txo); };
132                 if (this != null) { this.ptrs_to.AddLast(monitor); };
133                 return ret;
134         }
135
136         /**
137          * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
138          * 
139          * Implementations must call [`update_monitor`] with the given update. See
140          * [`ChannelMonitorUpdateStatus`] for invariants around returning an error.
141          * 
142          * [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor
143          */
144         public ChannelMonitorUpdateStatus update_channel(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.ChannelMonitorUpdate update) {
145                 ChannelMonitorUpdateStatus ret = bindings.Watch_update_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr, update == null ? 0 : update.ptr);
146                 GC.KeepAlive(this);
147                 GC.KeepAlive(funding_txo);
148                 GC.KeepAlive(update);
149                 if (this != null) { this.ptrs_to.AddLast(funding_txo); };
150                 if (this != null) { this.ptrs_to.AddLast(update); };
151                 return ret;
152         }
153
154         /**
155          * Returns any monitor events since the last call. Subsequent calls must only return new
156          * events.
157          * 
158          * Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
159          * further events may be returned here until the [`ChannelMonitor`] has been fully persisted
160          * to disk.
161          * 
162          * For details on asynchronous [`ChannelMonitor`] updating and returning
163          * [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
164          */
165         public ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events() {
166                 long[] ret = bindings.Watch_release_pending_monitor_events(this.ptr);
167                 GC.KeepAlive(this);
168                 int ret_conv_49_len = ret.Length;
169                 ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] ret_conv_49_arr = new ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[ret_conv_49_len];
170                 for (int x = 0; x < ret_conv_49_len; x++) {
171                         long ret_conv_49 = ret[x];
172                         ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ ret_conv_49_hu_conv = new ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ(null, ret_conv_49);
173                         if (ret_conv_49_hu_conv != null) { ret_conv_49_hu_conv.ptrs_to.AddLast(this); };
174                         ret_conv_49_arr[x] = ret_conv_49_hu_conv;
175                 }
176                 return ret_conv_49_arr;
177         }
178
179 }
180 } } }