[Java] Update auto-generated Java bindings for 0.0.113
[ldk-java] / src / main / java / org / ldk / structs / ChainMonitor.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * An implementation of [`chain::Watch`] for monitoring channels.
13  * 
14  * Connected and disconnected blocks must be provided to `ChainMonitor` as documented by
15  * [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
16  * or used independently to monitor channels remotely. See the [module-level documentation] for
17  * details.
18  * 
19  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
20  * [module-level documentation]: crate::chain::chainmonitor
21  */
22 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
23 public class ChainMonitor extends CommonBase {
24         ChainMonitor(Object _dummy, long ptr) { super(ptr); }
25         @Override @SuppressWarnings("deprecation")
26         protected void finalize() throws Throwable {
27                 super.finalize();
28                 if (ptr != 0) { bindings.ChainMonitor_free(ptr); }
29         }
30
31         /**
32          * Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
33          * 
34          * When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
35          * will call back to it indicating transactions and outputs of interest. This allows clients to
36          * pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
37          * always need to fetch full blocks absent another means for determining which blocks contain
38          * transactions relevant to the watched channels.
39          */
40         public static ChainMonitor of(org.ldk.structs.Option_FilterZ chain_source, org.ldk.structs.BroadcasterInterface broadcaster, org.ldk.structs.Logger logger, org.ldk.structs.FeeEstimator feeest, org.ldk.structs.Persist persister) {
41                 long ret = bindings.ChainMonitor_new(chain_source.ptr, broadcaster == null ? 0 : broadcaster.ptr, logger == null ? 0 : logger.ptr, feeest == null ? 0 : feeest.ptr, persister == null ? 0 : persister.ptr);
42                 Reference.reachabilityFence(chain_source);
43                 Reference.reachabilityFence(broadcaster);
44                 Reference.reachabilityFence(logger);
45                 Reference.reachabilityFence(feeest);
46                 Reference.reachabilityFence(persister);
47                 if (ret >= 0 && ret <= 4096) { return null; }
48                 org.ldk.structs.ChainMonitor ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChainMonitor(null, ret); }
49                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
50                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_source); };
51                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(broadcaster); };
52                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
53                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(feeest); };
54                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(persister); };
55                 return ret_hu_conv;
56         }
57
58         /**
59          * Gets the balances in the contained [`ChannelMonitor`]s which are claimable on-chain or
60          * claims which are awaiting confirmation.
61          * 
62          * Includes the balances from each [`ChannelMonitor`] *except* those included in
63          * `ignored_channels`, allowing you to filter out balances from channels which are still open
64          * (and whose balance should likely be pulled from the [`ChannelDetails`]).
65          * 
66          * See [`ChannelMonitor::get_claimable_balances`] for more details on the exact criteria for
67          * inclusion in the return value.
68          */
69         public Balance[] get_claimable_balances(ChannelDetails[] ignored_channels) {
70                 long[] ret = bindings.ChainMonitor_get_claimable_balances(this.ptr, ignored_channels != null ? Arrays.stream(ignored_channels).mapToLong(ignored_channels_conv_16 -> ignored_channels_conv_16 == null ? 0 : ignored_channels_conv_16.ptr).toArray() : null);
71                 Reference.reachabilityFence(this);
72                 Reference.reachabilityFence(ignored_channels);
73                 int ret_conv_9_len = ret.length;
74                 Balance[] ret_conv_9_arr = new Balance[ret_conv_9_len];
75                 for (int j = 0; j < ret_conv_9_len; j++) {
76                         long ret_conv_9 = ret[j];
77                         org.ldk.structs.Balance ret_conv_9_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret_conv_9);
78                         if (ret_conv_9_hu_conv != null) { ret_conv_9_hu_conv.ptrs_to.add(this); };
79                         ret_conv_9_arr[j] = ret_conv_9_hu_conv;
80                 }
81                 for (ChannelDetails ignored_channels_conv_16: ignored_channels) { if (this != null) { this.ptrs_to.add(ignored_channels_conv_16); }; };
82                 return ret_conv_9_arr;
83         }
84
85         /**
86          * Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no
87          * such [`ChannelMonitor`] is currently being monitored for.
88          * 
89          * Note that the result holds a mutex over our monitor set, and should not be held
90          * indefinitely.
91          */
92         public Result_LockedChannelMonitorNoneZ get_monitor(org.ldk.structs.OutPoint funding_txo) {
93                 long ret = bindings.ChainMonitor_get_monitor(this.ptr, funding_txo == null ? 0 : funding_txo.ptr);
94                 Reference.reachabilityFence(this);
95                 Reference.reachabilityFence(funding_txo);
96                 if (ret >= 0 && ret <= 4096) { return null; }
97                 Result_LockedChannelMonitorNoneZ ret_hu_conv = Result_LockedChannelMonitorNoneZ.constr_from_ptr(ret);
98                 if (this != null) { this.ptrs_to.add(funding_txo); };
99                 return ret_hu_conv;
100         }
101
102         /**
103          * Lists the funding outpoint of each [`ChannelMonitor`] being monitored.
104          * 
105          * Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always
106          * monitoring for on-chain state resolutions.
107          */
108         public OutPoint[] list_monitors() {
109                 long[] ret = bindings.ChainMonitor_list_monitors(this.ptr);
110                 Reference.reachabilityFence(this);
111                 int ret_conv_10_len = ret.length;
112                 OutPoint[] ret_conv_10_arr = new OutPoint[ret_conv_10_len];
113                 for (int k = 0; k < ret_conv_10_len; k++) {
114                         long ret_conv_10 = ret[k];
115                         org.ldk.structs.OutPoint ret_conv_10_hu_conv = null; if (ret_conv_10 < 0 || ret_conv_10 > 4096) { ret_conv_10_hu_conv = new org.ldk.structs.OutPoint(null, ret_conv_10); }
116                         if (ret_conv_10_hu_conv != null) { ret_conv_10_hu_conv.ptrs_to.add(this); };
117                         ret_conv_10_arr[k] = ret_conv_10_hu_conv;
118                 }
119                 return ret_conv_10_arr;
120         }
121
122         /**
123          * Lists the pending updates for each [`ChannelMonitor`] (by `OutPoint` being monitored).
124          */
125         public TwoTuple_OutPointCVec_MonitorUpdateIdZZ[] list_pending_monitor_updates() {
126                 long[] ret = bindings.ChainMonitor_list_pending_monitor_updates(this.ptr);
127                 Reference.reachabilityFence(this);
128                 int ret_conv_41_len = ret.length;
129                 TwoTuple_OutPointCVec_MonitorUpdateIdZZ[] ret_conv_41_arr = new TwoTuple_OutPointCVec_MonitorUpdateIdZZ[ret_conv_41_len];
130                 for (int p = 0; p < ret_conv_41_len; p++) {
131                         long ret_conv_41 = ret[p];
132                         TwoTuple_OutPointCVec_MonitorUpdateIdZZ ret_conv_41_hu_conv = new TwoTuple_OutPointCVec_MonitorUpdateIdZZ(null, ret_conv_41);
133                         if (ret_conv_41_hu_conv != null) { ret_conv_41_hu_conv.ptrs_to.add(this); };
134                         ret_conv_41_arr[p] = ret_conv_41_hu_conv;
135                 }
136                 return ret_conv_41_arr;
137         }
138
139         /**
140          * Indicates the persistence of a [`ChannelMonitor`] has completed after
141          * [`ChannelMonitorUpdateStatus::InProgress`] was returned from an update operation.
142          * 
143          * Thus, the anticipated use is, at a high level:
144          * 1) This [`ChainMonitor`] calls [`Persist::update_persisted_channel`] which stores the
145          * update to disk and begins updating any remote (e.g. watchtower/backup) copies,
146          * returning [`ChannelMonitorUpdateStatus::InProgress`],
147          * 2) once all remote copies are updated, you call this function with the
148          * `completed_update_id` that completed, and once all pending updates have completed the
149          * channel will be re-enabled.
150          * 
151          * Returns an [`APIError::APIMisuseError`] if `funding_txo` does not match any currently
152          * registered [`ChannelMonitor`]s.
153          */
154         public Result_NoneAPIErrorZ channel_monitor_updated(org.ldk.structs.OutPoint funding_txo, org.ldk.structs.MonitorUpdateId completed_update_id) {
155                 long ret = bindings.ChainMonitor_channel_monitor_updated(this.ptr, funding_txo == null ? 0 : funding_txo.ptr, completed_update_id == null ? 0 : completed_update_id.ptr);
156                 Reference.reachabilityFence(this);
157                 Reference.reachabilityFence(funding_txo);
158                 Reference.reachabilityFence(completed_update_id);
159                 if (ret >= 0 && ret <= 4096) { return null; }
160                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
161                 if (this != null) { this.ptrs_to.add(funding_txo); };
162                 if (this != null) { this.ptrs_to.add(completed_update_id); };
163                 return ret_hu_conv;
164         }
165
166         /**
167          * Constructs a new Listen which calls the relevant methods on this_arg.
168          * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
169          */
170         public Listen as_Listen() {
171                 long ret = bindings.ChainMonitor_as_Listen(this.ptr);
172                 Reference.reachabilityFence(this);
173                 if (ret >= 0 && ret <= 4096) { return null; }
174                 Listen ret_hu_conv = new Listen(null, ret);
175                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
176                 return ret_hu_conv;
177         }
178
179         /**
180          * Constructs a new Confirm which calls the relevant methods on this_arg.
181          * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
182          */
183         public Confirm as_Confirm() {
184                 long ret = bindings.ChainMonitor_as_Confirm(this.ptr);
185                 Reference.reachabilityFence(this);
186                 if (ret >= 0 && ret <= 4096) { return null; }
187                 Confirm ret_hu_conv = new Confirm(null, ret);
188                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
189                 return ret_hu_conv;
190         }
191
192         /**
193          * Constructs a new Watch which calls the relevant methods on this_arg.
194          * This copies the `inner` pointer in this_arg and thus the returned Watch must be freed before this_arg is
195          */
196         public Watch as_Watch() {
197                 long ret = bindings.ChainMonitor_as_Watch(this.ptr);
198                 Reference.reachabilityFence(this);
199                 if (ret >= 0 && ret <= 4096) { return null; }
200                 Watch ret_hu_conv = new Watch(null, ret);
201                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
202                 return ret_hu_conv;
203         }
204
205         /**
206          * Constructs a new EventsProvider which calls the relevant methods on this_arg.
207          * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
208          */
209         public EventsProvider as_EventsProvider() {
210                 long ret = bindings.ChainMonitor_as_EventsProvider(this.ptr);
211                 Reference.reachabilityFence(this);
212                 if (ret >= 0 && ret <= 4096) { return null; }
213                 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
214                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
215                 return ret_hu_conv;
216         }
217
218 }