Update auto-generated bindings to 0.0.103
[ldk-java] / src / main / java / org / ldk / structs / Watch.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9 /**
10  * The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as
11  * blocks are connected and disconnected.
12  * 
13  * Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are
14  * responsible for maintaining a set of monitors such that they can be updated accordingly as
15  * channel state changes and HTLCs are resolved. See method documentation for specific
16  * requirements.
17  * 
18  * Implementations **must** ensure that updates are successfully applied and persisted upon method
19  * completion. If an update fails with a [`PermanentFailure`], then it must immediately shut down
20  * without taking any further action such as persisting the current state.
21  * 
22  * If an implementation maintains multiple instances of a channel's monitor (e.g., by storing
23  * backup copies), then it must ensure that updates are applied across all instances. Otherwise, it
24  * could result in a revoked transaction being broadcast, allowing the counterparty to claim all
25  * funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle
26  * multiple instances.
27  * 
28  * [`PermanentFailure`]: ChannelMonitorUpdateErr::PermanentFailure
29  */
30 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
31 public class Watch extends CommonBase {
32         final bindings.LDKWatch bindings_instance;
33         Watch(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
34         private Watch(bindings.LDKWatch arg) {
35                 super(bindings.LDKWatch_new(arg));
36                 this.ptrs_to.add(arg);
37                 this.bindings_instance = arg;
38         }
39         @Override @SuppressWarnings("deprecation")
40         protected void finalize() throws Throwable {
41                 if (ptr != 0) { bindings.Watch_free(ptr); } super.finalize();
42         }
43
44         public static interface WatchInterface {
45                 /**
46                  * Watches a channel identified by `funding_txo` using `monitor`.
47                  * 
48                  * Implementations are responsible for watching the chain for the funding transaction along
49                  * with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
50                  * calling [`block_connected`] and [`block_disconnected`] on the monitor.
51                  * 
52                  * Note: this interface MUST error with `ChannelMonitorUpdateErr::PermanentFailure` if
53                  * the given `funding_txo` has previously been registered via `watch_channel`.
54                  * 
55                  * [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
56                  * [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
57                  * [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected
58                  */
59                 Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor);
60                 /**
61                  * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
62                  * 
63                  * Implementations must call [`update_monitor`] with the given update. See
64                  * [`ChannelMonitorUpdateErr`] for invariants around returning an error.
65                  * 
66                  * [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor
67                  */
68                 Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update);
69                 /**
70                  * Returns any monitor events since the last call. Subsequent calls must only return new
71                  * events.
72                  * 
73                  * Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
74                  * further events may be returned here until the [`ChannelMonitor`] has been fully persisted
75                  * to disk.
76                  * 
77                  * For details on asynchronous [`ChannelMonitor`] updating and returning
78                  * [`MonitorEvent::UpdateCompleted`] here, see [`ChannelMonitorUpdateErr::TemporaryFailure`].
79                  */
80                 MonitorEvent[] release_pending_monitor_events();
81         }
82         private static class LDKWatchHolder { Watch held; }
83         public static Watch new_impl(WatchInterface arg) {
84                 final LDKWatchHolder impl_holder = new LDKWatchHolder();
85                 impl_holder.held = new Watch(new bindings.LDKWatch() {
86                         @Override public long watch_channel(long funding_txo, long monitor) {
87                                 OutPoint funding_txo_hu_conv = null; if (funding_txo < 0 || funding_txo > 4096) { funding_txo_hu_conv = new OutPoint(null, funding_txo); }
88                                 funding_txo_hu_conv.ptrs_to.add(this);
89                                 ChannelMonitor monitor_hu_conv = null; if (monitor < 0 || monitor > 4096) { monitor_hu_conv = new ChannelMonitor(null, monitor); }
90                                 monitor_hu_conv.ptrs_to.add(this);
91                                 Result_NoneChannelMonitorUpdateErrZ ret = arg.watch_channel(funding_txo_hu_conv, monitor_hu_conv);
92                                 long result = ret != null ? ret.ptr : 0;
93                                 return result;
94                         }
95                         @Override public long update_channel(long funding_txo, long update) {
96                                 OutPoint funding_txo_hu_conv = null; if (funding_txo < 0 || funding_txo > 4096) { funding_txo_hu_conv = new OutPoint(null, funding_txo); }
97                                 funding_txo_hu_conv.ptrs_to.add(this);
98                                 ChannelMonitorUpdate update_hu_conv = null; if (update < 0 || update > 4096) { update_hu_conv = new ChannelMonitorUpdate(null, update); }
99                                 update_hu_conv.ptrs_to.add(this);
100                                 Result_NoneChannelMonitorUpdateErrZ ret = arg.update_channel(funding_txo_hu_conv, update_hu_conv);
101                                 long result = ret != null ? ret.ptr : 0;
102                                 return result;
103                         }
104                         @Override public long[] release_pending_monitor_events() {
105                                 MonitorEvent[] ret = arg.release_pending_monitor_events();
106                                 long[] result = ret != null ? Arrays.stream(ret).mapToLong(ret_conv_14 -> ret_conv_14.ptr).toArray() : null;
107                                 return result;
108                         }
109                 });
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 `ChannelMonitorUpdateErr::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 Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor) {
127                 long ret = bindings.Watch_watch_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, monitor == null ? 0 : monitor.ptr & ~1);
128                 if (ret >= 0 && ret <= 4096) { return null; }
129                 Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
130                 return ret_hu_conv;
131         }
132
133         /**
134          * Updates a channel identified by `funding_txo` by applying `update` to its monitor.
135          * 
136          * Implementations must call [`update_monitor`] with the given update. See
137          * [`ChannelMonitorUpdateErr`] for invariants around returning an error.
138          * 
139          * [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor
140          */
141         public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) {
142                 long ret = bindings.Watch_update_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, update == null ? 0 : update.ptr & ~1);
143                 if (ret >= 0 && ret <= 4096) { return null; }
144                 Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret);
145                 return ret_hu_conv;
146         }
147
148         /**
149          * Returns any monitor events since the last call. Subsequent calls must only return new
150          * events.
151          * 
152          * Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
153          * further events may be returned here until the [`ChannelMonitor`] has been fully persisted
154          * to disk.
155          * 
156          * For details on asynchronous [`ChannelMonitor`] updating and returning
157          * [`MonitorEvent::UpdateCompleted`] here, see [`ChannelMonitorUpdateErr::TemporaryFailure`].
158          */
159         public MonitorEvent[] release_pending_monitor_events() {
160                 long[] ret = bindings.Watch_release_pending_monitor_events(this.ptr);
161                 MonitorEvent[] ret_conv_14_arr = new MonitorEvent[ret.length];
162                 for (int o = 0; o < ret.length; o++) {
163                         long ret_conv_14 = ret[o];
164                         MonitorEvent ret_conv_14_hu_conv = MonitorEvent.constr_from_ptr(ret_conv_14);
165                         ret_conv_14_hu_conv.ptrs_to.add(this);
166                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
167                 }
168                 return ret_conv_14_arr;
169         }
170
171 }