Merge pull request #120 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / ChannelManager.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  * Manager which keeps track of a number of channels and sends messages to the appropriate
13  * channel, also tracking HTLC preimages and forwarding onion packets appropriately.
14  * 
15  * Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
16  * to individual Channels.
17  * 
18  * Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
19  * all peers during write/read (though does not modify this instance, only the instance being
20  * serialized). This will result in any channels which have not yet exchanged funding_created (ie
21  * called funding_transaction_generated for outbound channels).
22  * 
23  * Note that you can be a bit lazier about writing out ChannelManager than you can be with
24  * ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
25  * returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
26  * happens out-of-band (and will prevent any other ChannelManager operations from occurring during
27  * the serialization process). If the deserialized version is out-of-date compared to the
28  * ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
29  * ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
30  * 
31  * Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
32  * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
33  * the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
34  * block_connected() to step towards your best block) upon deserialization before using the
35  * object!
36  * 
37  * Note that ChannelManager is responsible for tracking liveness of its channels and generating
38  * ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
39  * spam due to quick disconnection/reconnection, updates are not sent until the channel has been
40  * offline for a full minute. In order to track this, you must call
41  * timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
42  * 
43  * Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
44  * a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
45  * essentially you should default to using a SimpleRefChannelManager, and use a
46  * SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
47  * you're using lightning-net-tokio.
48  */
49 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
50 public class ChannelManager extends CommonBase {
51         ChannelManager(Object _dummy, long ptr) { super(ptr); }
52         @Override @SuppressWarnings("deprecation")
53         protected void finalize() throws Throwable {
54                 super.finalize();
55                 if (ptr != 0) { bindings.ChannelManager_free(ptr); }
56         }
57
58         /**
59          * Constructs a new ChannelManager to hold several channels and route between them.
60          * 
61          * This is the main \"logic hub\" for all channel-related actions, and implements
62          * ChannelMessageHandler.
63          * 
64          * Non-proportional fees are fixed according to our risk using the provided fee estimator.
65          * 
66          * Users need to notify the new ChannelManager when a new block is connected or
67          * disconnected using its `block_connected` and `block_disconnected` methods, starting
68          * from after `params.latest_hash`.
69          */
70         public static ChannelManager of(FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, ChainParameters params) {
71                 long ret = bindings.ChannelManager_new(fee_est == null ? 0 : fee_est.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, keys_manager == null ? 0 : keys_manager.ptr, config == null ? 0 : config.ptr, params == null ? 0 : params.ptr);
72                 Reference.reachabilityFence(fee_est);
73                 Reference.reachabilityFence(chain_monitor);
74                 Reference.reachabilityFence(tx_broadcaster);
75                 Reference.reachabilityFence(logger);
76                 Reference.reachabilityFence(keys_manager);
77                 Reference.reachabilityFence(config);
78                 Reference.reachabilityFence(params);
79                 if (ret >= 0 && ret <= 4096) { return null; }
80                 org.ldk.structs.ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManager(null, ret); }
81                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
82                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fee_est); };
83                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_monitor); };
84                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(tx_broadcaster); };
85                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
86                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
87                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(config); };
88                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(params); };
89                 return ret_hu_conv;
90         }
91
92         /**
93          * Gets the current configuration applied to all new channels.
94          */
95         public UserConfig get_current_default_configuration() {
96                 long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
97                 Reference.reachabilityFence(this);
98                 if (ret >= 0 && ret <= 4096) { return null; }
99                 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
100                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
101                 return ret_hu_conv;
102         }
103
104         /**
105          * Creates a new outbound channel to the given remote node and with the given value.
106          * 
107          * `user_channel_id` will be provided back as in
108          * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
109          * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
110          * for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
111          * `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
112          * ignored.
113          * 
114          * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
115          * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
116          * 
117          * Note that we do not check if you are currently connected to the given peer. If no
118          * connection is available, the outbound `open_channel` message may fail to send, resulting in
119          * the channel eventually being silently forgotten (dropped on reload).
120          * 
121          * Returns the new Channel's temporary `channel_id`. This ID will appear as
122          * [`Event::FundingGenerationReady::temporary_channel_id`] and in
123          * [`ChannelDetails::channel_id`] until after
124          * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
125          * one derived from the funding transaction's TXID. If the counterparty rejects the channel
126          * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
127          * 
128          * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
129          * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
130          * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
131          * 
132          * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
133          */
134         public Result__u832APIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_channel_id, @Nullable UserConfig override_config) {
135                 long ret = bindings.ChannelManager_create_channel(this.ptr, InternalUtils.check_arr_len(their_network_key, 33), channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr);
136                 Reference.reachabilityFence(this);
137                 Reference.reachabilityFence(their_network_key);
138                 Reference.reachabilityFence(channel_value_satoshis);
139                 Reference.reachabilityFence(push_msat);
140                 Reference.reachabilityFence(user_channel_id);
141                 Reference.reachabilityFence(override_config);
142                 if (ret >= 0 && ret <= 4096) { return null; }
143                 Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
144                 if (this != null) { this.ptrs_to.add(override_config); };
145                 return ret_hu_conv;
146         }
147
148         /**
149          * Gets the list of open channels, in random order. See ChannelDetail field documentation for
150          * more information.
151          */
152         public ChannelDetails[] list_channels() {
153                 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
154                 Reference.reachabilityFence(this);
155                 int ret_conv_16_len = ret.length;
156                 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
157                 for (int q = 0; q < ret_conv_16_len; q++) {
158                         long ret_conv_16 = ret[q];
159                         org.ldk.structs.ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, ret_conv_16); }
160                         if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
161                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
162                 }
163                 return ret_conv_16_arr;
164         }
165
166         /**
167          * Gets the list of usable channels, in random order. Useful as an argument to [`find_route`]
168          * to ensure non-announced channels are used.
169          * 
170          * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
171          * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
172          * are.
173          * 
174          * [`find_route`]: crate::routing::router::find_route
175          */
176         public ChannelDetails[] list_usable_channels() {
177                 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
178                 Reference.reachabilityFence(this);
179                 int ret_conv_16_len = ret.length;
180                 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
181                 for (int q = 0; q < ret_conv_16_len; q++) {
182                         long ret_conv_16 = ret[q];
183                         org.ldk.structs.ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new org.ldk.structs.ChannelDetails(null, ret_conv_16); }
184                         if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
185                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
186                 }
187                 return ret_conv_16_arr;
188         }
189
190         /**
191          * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
192          * will be accepted on the given channel, and after additional timeout/the closing of all
193          * pending HTLCs, the channel will be closed on chain.
194          * 
195          * If we are the channel initiator, we will pay between our [`Background`] and
196          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
197          * estimate.
198          * If our counterparty is the channel initiator, we will require a channel closing
199          * transaction feerate of at least our [`Background`] feerate or the feerate which
200          * would appear on a force-closure transaction, whichever is lower. We will allow our
201          * counterparty to pay as much fee as they'd like, however.
202          * 
203          * May generate a SendShutdown message event on success, which should be relayed.
204          * 
205          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
206          * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
207          * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
208          */
209         public Result_NoneAPIErrorZ close_channel(byte[] channel_id, byte[] counterparty_node_id) {
210                 long ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
211                 Reference.reachabilityFence(this);
212                 Reference.reachabilityFence(channel_id);
213                 Reference.reachabilityFence(counterparty_node_id);
214                 if (ret >= 0 && ret <= 4096) { return null; }
215                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
216                 return ret_hu_conv;
217         }
218
219         /**
220          * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
221          * will be accepted on the given channel, and after additional timeout/the closing of all
222          * pending HTLCs, the channel will be closed on chain.
223          * 
224          * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
225          * the channel being closed or not:
226          * If we are the channel initiator, we will pay at least this feerate on the closing
227          * transaction. The upper-bound is set by
228          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
229          * estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
230          * If our counterparty is the channel initiator, we will refuse to accept a channel closure
231          * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
232          * will appear on a force-closure transaction, whichever is lower).
233          * 
234          * May generate a SendShutdown message event on success, which should be relayed.
235          * 
236          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
237          * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
238          * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
239          */
240         public Result_NoneAPIErrorZ close_channel_with_target_feerate(byte[] channel_id, byte[] counterparty_node_id, int target_feerate_sats_per_1000_weight) {
241                 long ret = bindings.ChannelManager_close_channel_with_target_feerate(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33), target_feerate_sats_per_1000_weight);
242                 Reference.reachabilityFence(this);
243                 Reference.reachabilityFence(channel_id);
244                 Reference.reachabilityFence(counterparty_node_id);
245                 Reference.reachabilityFence(target_feerate_sats_per_1000_weight);
246                 if (ret >= 0 && ret <= 4096) { return null; }
247                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
248                 return ret_hu_conv;
249         }
250
251         /**
252          * Force closes a channel, immediately broadcasting the latest local transaction(s) and
253          * rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
254          * the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
255          * channel.
256          */
257         public Result_NoneAPIErrorZ force_close_broadcasting_latest_txn(byte[] channel_id, byte[] counterparty_node_id) {
258                 long ret = bindings.ChannelManager_force_close_broadcasting_latest_txn(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
259                 Reference.reachabilityFence(this);
260                 Reference.reachabilityFence(channel_id);
261                 Reference.reachabilityFence(counterparty_node_id);
262                 if (ret >= 0 && ret <= 4096) { return null; }
263                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
264                 return ret_hu_conv;
265         }
266
267         /**
268          * Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
269          * the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
270          * `counterparty_node_id` isn't the counterparty of the corresponding channel.
271          * 
272          * You can always get the latest local transaction(s) to broadcast from
273          * [`ChannelMonitor::get_latest_holder_commitment_txn`].
274          */
275         public Result_NoneAPIErrorZ force_close_without_broadcasting_txn(byte[] channel_id, byte[] counterparty_node_id) {
276                 long ret = bindings.ChannelManager_force_close_without_broadcasting_txn(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
277                 Reference.reachabilityFence(this);
278                 Reference.reachabilityFence(channel_id);
279                 Reference.reachabilityFence(counterparty_node_id);
280                 if (ret >= 0 && ret <= 4096) { return null; }
281                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
282                 return ret_hu_conv;
283         }
284
285         /**
286          * Force close all channels, immediately broadcasting the latest local commitment transaction
287          * for each to the chain and rejecting new HTLCs on each.
288          */
289         public void force_close_all_channels_broadcasting_latest_txn() {
290                 bindings.ChannelManager_force_close_all_channels_broadcasting_latest_txn(this.ptr);
291                 Reference.reachabilityFence(this);
292         }
293
294         /**
295          * Force close all channels rejecting new HTLCs on each but without broadcasting the latest
296          * local transaction(s).
297          */
298         public void force_close_all_channels_without_broadcasting_txn() {
299                 bindings.ChannelManager_force_close_all_channels_without_broadcasting_txn(this.ptr);
300                 Reference.reachabilityFence(this);
301         }
302
303         /**
304          * Sends a payment along a given route.
305          * 
306          * Value parameters are provided via the last hop in route, see documentation for RouteHop
307          * fields for more info.
308          * 
309          * Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
310          * payment), we don't do anything to stop you! We always try to ensure that if the provided
311          * next hop knows the preimage to payment_hash they can claim an additional amount as
312          * specified in the last hop in the route! Thus, you should probably do your own
313          * payment_preimage tracking (which you should already be doing as they represent \"proof of
314          * payment\") and prevent double-sends yourself.
315          * 
316          * May generate SendHTLCs message(s) event on success, which should be relayed.
317          * 
318          * Each path may have a different return value, and PaymentSendValue may return a Vec with
319          * each entry matching the corresponding-index entry in the route paths, see
320          * PaymentSendFailure for more info.
321          * 
322          * In general, a path may raise:
323          * [`APIError::RouteError`] when an invalid route or forwarding parameter (cltv_delta, fee,
324          * node public key) is specified.
325          * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
326          * (including due to previous monitor update failure or new permanent monitor update
327          * failure).
328          * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
329          * relevant updates.
330          * 
331          * Note that depending on the type of the PaymentSendFailure the HTLC may have been
332          * irrevocably committed to on our end. In such a case, do NOT retry the payment with a
333          * different route unless you intend to pay twice!
334          * 
335          * payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
336          * the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
337          * newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
338          * must not contain multiple paths as multi-path payments require a recipient-provided
339          * payment_secret.
340          * If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
341          * bit set (either as required or as available). If multiple paths are present in the Route,
342          * we assume the invoice had the basic_mpp feature set.
343          * 
344          * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
345          */
346         public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
347                 long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
348                 Reference.reachabilityFence(this);
349                 Reference.reachabilityFence(route);
350                 Reference.reachabilityFence(payment_hash);
351                 Reference.reachabilityFence(payment_secret);
352                 if (ret >= 0 && ret <= 4096) { return null; }
353                 Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
354                 if (this != null) { this.ptrs_to.add(route); };
355                 return ret_hu_conv;
356         }
357
358         /**
359          * Retries a payment along the given [`Route`].
360          * 
361          * Errors returned are a superset of those returned from [`send_payment`], so see
362          * [`send_payment`] documentation for more details on errors. This method will also error if the
363          * retry amount puts the payment more than 10% over the payment's total amount, if the payment
364          * for the given `payment_id` cannot be found (likely due to timeout or success), or if
365          * further retries have been disabled with [`abandon_payment`].
366          * 
367          * [`send_payment`]: [`ChannelManager::send_payment`]
368          * [`abandon_payment`]: [`ChannelManager::abandon_payment`]
369          */
370         public Result_NonePaymentSendFailureZ retry_payment(Route route, byte[] payment_id) {
371                 long ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_id, 32));
372                 Reference.reachabilityFence(this);
373                 Reference.reachabilityFence(route);
374                 Reference.reachabilityFence(payment_id);
375                 if (ret >= 0 && ret <= 4096) { return null; }
376                 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
377                 if (this != null) { this.ptrs_to.add(route); };
378                 return ret_hu_conv;
379         }
380
381         /**
382          * Signals that no further retries for the given payment will occur.
383          * 
384          * After this method returns, any future calls to [`retry_payment`] for the given `payment_id`
385          * will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated,
386          * an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining
387          * pending HTLCs for this payment.
388          * 
389          * Note that calling this method does *not* prevent a payment from succeeding. You must still
390          * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
391          * determine the ultimate status of a payment.
392          * 
393          * [`retry_payment`]: Self::retry_payment
394          * [`Event::PaymentFailed`]: events::Event::PaymentFailed
395          * [`Event::PaymentSent`]: events::Event::PaymentSent
396          */
397         public void abandon_payment(byte[] payment_id) {
398                 bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
399                 Reference.reachabilityFence(this);
400                 Reference.reachabilityFence(payment_id);
401         }
402
403         /**
404          * Send a spontaneous payment, which is a payment that does not require the recipient to have
405          * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
406          * the preimage, it must be a cryptographically secure random value that no intermediate node
407          * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
408          * never reach the recipient.
409          * 
410          * See [`send_payment`] documentation for more details on the return value of this function.
411          * 
412          * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
413          * [`send_payment`] for more information about the risks of duplicate preimage usage.
414          * 
415          * Note that `route` must have exactly one path.
416          * 
417          * [`send_payment`]: Self::send_payment
418          * 
419          * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
420          */
421         public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
422                 long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
423                 Reference.reachabilityFence(this);
424                 Reference.reachabilityFence(route);
425                 Reference.reachabilityFence(payment_preimage);
426                 if (ret >= 0 && ret <= 4096) { return null; }
427                 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
428                 if (this != null) { this.ptrs_to.add(route); };
429                 return ret_hu_conv;
430         }
431
432         /**
433          * Send a payment that is probing the given route for liquidity. We calculate the
434          * [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
435          * us to easily discern them from real payments.
436          */
437         public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_probe(RouteHop[] hops) {
438                 long ret = bindings.ChannelManager_send_probe(this.ptr, hops != null ? Arrays.stream(hops).mapToLong(hops_conv_10 -> hops_conv_10 == null ? 0 : hops_conv_10.ptr).toArray() : null);
439                 Reference.reachabilityFence(this);
440                 Reference.reachabilityFence(hops);
441                 if (ret >= 0 && ret <= 4096) { return null; }
442                 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
443                 for (RouteHop hops_conv_10: hops) { if (this != null) { this.ptrs_to.add(hops_conv_10); }; };
444                 return ret_hu_conv;
445         }
446
447         /**
448          * Call this upon creation of a funding transaction for the given channel.
449          * 
450          * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
451          * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
452          * 
453          * Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
454          * across the p2p network.
455          * 
456          * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
457          * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
458          * 
459          * May panic if the output found in the funding transaction is duplicative with some other
460          * channel (note that this should be trivially prevented by using unique funding transaction
461          * keys per-channel).
462          * 
463          * Do NOT broadcast the funding transaction yourself. When we have safely received our
464          * counterparty's signature the funding transaction will automatically be broadcast via the
465          * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
466          * 
467          * Note that this includes RBF or similar transaction replacement strategies - lightning does
468          * not currently support replacing a funding transaction on an existing channel. Instead,
469          * create a new channel with a conflicting funding transaction.
470          * 
471          * Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
472          * the wallet software generating the funding transaction to apply anti-fee sniping as
473          * implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
474          * for more details.
475          * 
476          * [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
477          * [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
478          */
479         public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] counterparty_node_id, byte[] funding_transaction) {
480                 long ret = bindings.ChannelManager_funding_transaction_generated(this.ptr, InternalUtils.check_arr_len(temporary_channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33), funding_transaction);
481                 Reference.reachabilityFence(this);
482                 Reference.reachabilityFence(temporary_channel_id);
483                 Reference.reachabilityFence(counterparty_node_id);
484                 Reference.reachabilityFence(funding_transaction);
485                 if (ret >= 0 && ret <= 4096) { return null; }
486                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
487                 return ret_hu_conv;
488         }
489
490         /**
491          * Atomically updates the [`ChannelConfig`] for the given channels.
492          * 
493          * Once the updates are applied, each eligible channel (advertised with a known short channel
494          * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
495          * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
496          * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
497          * 
498          * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
499          * `counterparty_node_id` is provided.
500          * 
501          * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
502          * below [`MIN_CLTV_EXPIRY_DELTA`].
503          * 
504          * If an error is returned, none of the updates should be considered applied.
505          * 
506          * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
507          * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
508          * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
509          * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
510          * [`ChannelUpdate`]: msgs::ChannelUpdate
511          * [`ChannelUnavailable`]: APIError::ChannelUnavailable
512          * [`APIMisuseError`]: APIError::APIMisuseError
513          */
514         public Result_NoneAPIErrorZ update_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, ChannelConfig config) {
515                 long ret = bindings.ChannelManager_update_channel_config(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33), channel_ids != null ? Arrays.stream(channel_ids).map(channel_ids_conv_8 -> InternalUtils.check_arr_len(channel_ids_conv_8, 32)).toArray(byte[][]::new) : null, config == null ? 0 : config.ptr);
516                 Reference.reachabilityFence(this);
517                 Reference.reachabilityFence(counterparty_node_id);
518                 Reference.reachabilityFence(channel_ids);
519                 Reference.reachabilityFence(config);
520                 if (ret >= 0 && ret <= 4096) { return null; }
521                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
522                 if (this != null) { this.ptrs_to.add(config); };
523                 return ret_hu_conv;
524         }
525
526         /**
527          * Processes HTLCs which are pending waiting on random forward delay.
528          * 
529          * Should only really ever be called in response to a PendingHTLCsForwardable event.
530          * Will likely generate further events.
531          */
532         public void process_pending_htlc_forwards() {
533                 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
534                 Reference.reachabilityFence(this);
535         }
536
537         /**
538          * Performs actions which should happen on startup and roughly once per minute thereafter.
539          * 
540          * This currently includes:
541          * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
542          * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
543          * than a minute, informing the network that they should no longer attempt to route over
544          * the channel.
545          * Expiring a channel's previous `ChannelConfig` if necessary to only allow forwarding HTLCs
546          * with the current `ChannelConfig`.
547          * 
548          * Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
549          * estimate fetches.
550          */
551         public void timer_tick_occurred() {
552                 bindings.ChannelManager_timer_tick_occurred(this.ptr);
553                 Reference.reachabilityFence(this);
554         }
555
556         /**
557          * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
558          * after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
559          * along the path (including in our own channel on which we received it).
560          * 
561          * Note that in some cases around unclean shutdown, it is possible the payment may have
562          * already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
563          * second copy of) the [`events::Event::PaymentReceived`] event. Alternatively, the payment
564          * may have already been failed automatically by LDK if it was nearing its expiration time.
565          * 
566          * While LDK will never claim a payment automatically on your behalf (i.e. without you calling
567          * [`ChannelManager::claim_funds`]), you should still monitor for
568          * [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
569          * startup during which time claims that were in-progress at shutdown may be replayed.
570          */
571         public void fail_htlc_backwards(byte[] payment_hash) {
572                 bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
573                 Reference.reachabilityFence(this);
574                 Reference.reachabilityFence(payment_hash);
575         }
576
577         /**
578          * Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
579          * [`MessageSendEvent`]s needed to claim the payment.
580          * 
581          * Note that calling this method does *not* guarantee that the payment has been claimed. You
582          * must* wait for an [`Event::PaymentClaimed`] event which upon a successful claim will be
583          * provided to your [`EventHandler`] when [`process_pending_events`] is next called.
584          * 
585          * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
586          * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
587          * event matches your expectation. If you fail to do so and call this method, you may provide
588          * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
589          * 
590          * [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
591          * [`Event::PaymentClaimed`]: crate::util::events::Event::PaymentClaimed
592          * [`process_pending_events`]: EventsProvider::process_pending_events
593          * [`create_inbound_payment`]: Self::create_inbound_payment
594          * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
595          * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
596          */
597         public void claim_funds(byte[] payment_preimage) {
598                 bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
599                 Reference.reachabilityFence(this);
600                 Reference.reachabilityFence(payment_preimage);
601         }
602
603         /**
604          * Gets the node_id held by this ChannelManager
605          */
606         public byte[] get_our_node_id() {
607                 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
608                 Reference.reachabilityFence(this);
609                 return ret;
610         }
611
612         /**
613          * Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
614          * 
615          * The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
616          * and the `counterparty_node_id` parameter is the id of the peer which has requested to open
617          * the channel.
618          * 
619          * The `user_channel_id` parameter will be provided back in
620          * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
621          * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
622          * 
623          * Note that this method will return an error and reject the channel, if it requires support
624          * for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
625          * used to accept such channels.
626          * 
627          * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
628          * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
629          */
630         public Result_NoneAPIErrorZ accept_inbound_channel(byte[] temporary_channel_id, byte[] counterparty_node_id, long user_channel_id) {
631                 long ret = bindings.ChannelManager_accept_inbound_channel(this.ptr, InternalUtils.check_arr_len(temporary_channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33), user_channel_id);
632                 Reference.reachabilityFence(this);
633                 Reference.reachabilityFence(temporary_channel_id);
634                 Reference.reachabilityFence(counterparty_node_id);
635                 Reference.reachabilityFence(user_channel_id);
636                 if (ret >= 0 && ret <= 4096) { return null; }
637                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
638                 return ret_hu_conv;
639         }
640
641         /**
642          * Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
643          * it as confirmed immediately.
644          * 
645          * The `user_channel_id` parameter will be provided back in
646          * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
647          * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
648          * 
649          * Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
650          * and (if the counterparty agrees), enables forwarding of payments immediately.
651          * 
652          * This fully trusts that the counterparty has honestly and correctly constructed the funding
653          * transaction and blindly assumes that it will eventually confirm.
654          * 
655          * If it does not confirm before we decide to close the channel, or if the funding transaction
656          * does not pay to the correct script the correct amount, *you will lose funds*.
657          * 
658          * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
659          * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
660          */
661         public Result_NoneAPIErrorZ accept_inbound_channel_from_trusted_peer_0conf(byte[] temporary_channel_id, byte[] counterparty_node_id, long user_channel_id) {
662                 long ret = bindings.ChannelManager_accept_inbound_channel_from_trusted_peer_0conf(this.ptr, InternalUtils.check_arr_len(temporary_channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33), user_channel_id);
663                 Reference.reachabilityFence(this);
664                 Reference.reachabilityFence(temporary_channel_id);
665                 Reference.reachabilityFence(counterparty_node_id);
666                 Reference.reachabilityFence(user_channel_id);
667                 if (ret >= 0 && ret <= 4096) { return null; }
668                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
669                 return ret_hu_conv;
670         }
671
672         /**
673          * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
674          * to pay us.
675          * 
676          * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
677          * [`PaymentHash`] and [`PaymentPreimage`] for you.
678          * 
679          * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
680          * will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
681          * passed directly to [`claim_funds`].
682          * 
683          * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
684          * 
685          * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
686          * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
687          * 
688          * # Note
689          * 
690          * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
691          * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
692          * 
693          * Errors if `min_value_msat` is greater than total bitcoin supply.
694          * 
695          * [`claim_funds`]: Self::claim_funds
696          * [`PaymentReceived`]: events::Event::PaymentReceived
697          * [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
698          * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
699          */
700         public Result_C2Tuple_PaymentHashPaymentSecretZNoneZ create_inbound_payment(Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
701                 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs);
702                 Reference.reachabilityFence(this);
703                 Reference.reachabilityFence(min_value_msat);
704                 Reference.reachabilityFence(invoice_expiry_delta_secs);
705                 if (ret >= 0 && ret <= 4096) { return null; }
706                 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
707                 return ret_hu_conv;
708         }
709
710         /**
711          * Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
712          * serialized state with LDK node(s) running 0.0.103 and earlier.
713          * 
714          * May panic if `invoice_expiry_delta_secs` is greater than one year.
715          * 
716          * # Note
717          * This method is deprecated and will be removed soon.
718          * 
719          * [`create_inbound_payment`]: Self::create_inbound_payment
720          */
721         public Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ create_inbound_payment_legacy(Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
722                 long ret = bindings.ChannelManager_create_inbound_payment_legacy(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs);
723                 Reference.reachabilityFence(this);
724                 Reference.reachabilityFence(min_value_msat);
725                 Reference.reachabilityFence(invoice_expiry_delta_secs);
726                 if (ret >= 0 && ret <= 4096) { return null; }
727                 Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ.constr_from_ptr(ret);
728                 return ret_hu_conv;
729         }
730
731         /**
732          * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
733          * stored external to LDK.
734          * 
735          * A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
736          * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
737          * the `min_value_msat` provided here, if one is provided.
738          * 
739          * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
740          * note that LDK will not stop you from registering duplicate payment hashes for inbound
741          * payments.
742          * 
743          * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
744          * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
745          * before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
746          * sender \"proof-of-payment\" unless they have paid the required amount.
747          * 
748          * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
749          * in excess of the current time. This should roughly match the expiry time set in the invoice.
750          * After this many seconds, we will remove the inbound payment, resulting in any attempts to
751          * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
752          * invoices when no timeout is set.
753          * 
754          * Note that we use block header time to time-out pending inbound payments (with some margin
755          * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
756          * accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
757          * If you need exact expiry semantics, you should enforce them upon receipt of
758          * [`PaymentReceived`].
759          * 
760          * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
761          * set to at least [`MIN_FINAL_CLTV_EXPIRY`].
762          * 
763          * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
764          * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
765          * 
766          * # Note
767          * 
768          * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
769          * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
770          * 
771          * Errors if `min_value_msat` is greater than total bitcoin supply.
772          * 
773          * [`create_inbound_payment`]: Self::create_inbound_payment
774          * [`PaymentReceived`]: events::Event::PaymentReceived
775          */
776         public Result_PaymentSecretNoneZ create_inbound_payment_for_hash(byte[] payment_hash, Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
777                 long ret = bindings.ChannelManager_create_inbound_payment_for_hash(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), min_value_msat.ptr, invoice_expiry_delta_secs);
778                 Reference.reachabilityFence(this);
779                 Reference.reachabilityFence(payment_hash);
780                 Reference.reachabilityFence(min_value_msat);
781                 Reference.reachabilityFence(invoice_expiry_delta_secs);
782                 if (ret >= 0 && ret <= 4096) { return null; }
783                 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
784                 return ret_hu_conv;
785         }
786
787         /**
788          * Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
789          * serialized state with LDK node(s) running 0.0.103 and earlier.
790          * 
791          * May panic if `invoice_expiry_delta_secs` is greater than one year.
792          * 
793          * # Note
794          * This method is deprecated and will be removed soon.
795          * 
796          * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
797          */
798         public Result_PaymentSecretAPIErrorZ create_inbound_payment_for_hash_legacy(byte[] payment_hash, Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
799                 long ret = bindings.ChannelManager_create_inbound_payment_for_hash_legacy(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), min_value_msat.ptr, invoice_expiry_delta_secs);
800                 Reference.reachabilityFence(this);
801                 Reference.reachabilityFence(payment_hash);
802                 Reference.reachabilityFence(min_value_msat);
803                 Reference.reachabilityFence(invoice_expiry_delta_secs);
804                 if (ret >= 0 && ret <= 4096) { return null; }
805                 Result_PaymentSecretAPIErrorZ ret_hu_conv = Result_PaymentSecretAPIErrorZ.constr_from_ptr(ret);
806                 return ret_hu_conv;
807         }
808
809         /**
810          * Gets an LDK-generated payment preimage from a payment hash and payment secret that were
811          * previously returned from [`create_inbound_payment`].
812          * 
813          * [`create_inbound_payment`]: Self::create_inbound_payment
814          */
815         public Result_PaymentPreimageAPIErrorZ get_payment_preimage(byte[] payment_hash, byte[] payment_secret) {
816                 long ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
817                 Reference.reachabilityFence(this);
818                 Reference.reachabilityFence(payment_hash);
819                 Reference.reachabilityFence(payment_secret);
820                 if (ret >= 0 && ret <= 4096) { return null; }
821                 Result_PaymentPreimageAPIErrorZ ret_hu_conv = Result_PaymentPreimageAPIErrorZ.constr_from_ptr(ret);
822                 return ret_hu_conv;
823         }
824
825         /**
826          * Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
827          * are used when constructing the phantom invoice's route hints.
828          * 
829          * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
830          */
831         public long get_phantom_scid() {
832                 long ret = bindings.ChannelManager_get_phantom_scid(this.ptr);
833                 Reference.reachabilityFence(this);
834                 return ret;
835         }
836
837         /**
838          * Gets route hints for use in receiving [phantom node payments].
839          * 
840          * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
841          */
842         public PhantomRouteHints get_phantom_route_hints() {
843                 long ret = bindings.ChannelManager_get_phantom_route_hints(this.ptr);
844                 Reference.reachabilityFence(this);
845                 if (ret >= 0 && ret <= 4096) { return null; }
846                 org.ldk.structs.PhantomRouteHints ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomRouteHints(null, ret); }
847                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
848                 return ret_hu_conv;
849         }
850
851         /**
852          * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
853          * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
854          */
855         public MessageSendEventsProvider as_MessageSendEventsProvider() {
856                 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
857                 Reference.reachabilityFence(this);
858                 if (ret >= 0 && ret <= 4096) { return null; }
859                 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
860                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
861                 return ret_hu_conv;
862         }
863
864         /**
865          * Constructs a new EventsProvider which calls the relevant methods on this_arg.
866          * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
867          */
868         public EventsProvider as_EventsProvider() {
869                 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
870                 Reference.reachabilityFence(this);
871                 if (ret >= 0 && ret <= 4096) { return null; }
872                 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
873                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
874                 return ret_hu_conv;
875         }
876
877         /**
878          * Constructs a new Listen which calls the relevant methods on this_arg.
879          * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
880          */
881         public Listen as_Listen() {
882                 long ret = bindings.ChannelManager_as_Listen(this.ptr);
883                 Reference.reachabilityFence(this);
884                 if (ret >= 0 && ret <= 4096) { return null; }
885                 Listen ret_hu_conv = new Listen(null, ret);
886                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
887                 return ret_hu_conv;
888         }
889
890         /**
891          * Constructs a new Confirm which calls the relevant methods on this_arg.
892          * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
893          */
894         public Confirm as_Confirm() {
895                 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
896                 Reference.reachabilityFence(this);
897                 if (ret >= 0 && ret <= 4096) { return null; }
898                 Confirm ret_hu_conv = new Confirm(null, ret);
899                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
900                 return ret_hu_conv;
901         }
902
903         /**
904          * Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
905          * indicating whether persistence is necessary. Only one listener on
906          * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
907          * up.
908          * 
909          * Note that this method is not available with the `no-std` feature.
910          */
911         public boolean await_persistable_update_timeout(long max_wait) {
912                 boolean ret = bindings.ChannelManager_await_persistable_update_timeout(this.ptr, max_wait);
913                 Reference.reachabilityFence(this);
914                 Reference.reachabilityFence(max_wait);
915                 return ret;
916         }
917
918         /**
919          * Blocks until ChannelManager needs to be persisted. Only one listener on
920          * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
921          * up.
922          */
923         public void await_persistable_update() {
924                 bindings.ChannelManager_await_persistable_update(this.ptr);
925                 Reference.reachabilityFence(this);
926         }
927
928         /**
929          * Gets a [`Future`] that completes when a persistable update is available. Note that
930          * callbacks registered on the [`Future`] MUST NOT call back into this [`ChannelManager`] and
931          * should instead register actions to be taken later.
932          */
933         public Future get_persistable_update_future() {
934                 long ret = bindings.ChannelManager_get_persistable_update_future(this.ptr);
935                 Reference.reachabilityFence(this);
936                 if (ret >= 0 && ret <= 4096) { return null; }
937                 org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); }
938                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
939                 return ret_hu_conv;
940         }
941
942         /**
943          * Gets the latest best block which was connected either via the [`chain::Listen`] or
944          * [`chain::Confirm`] interfaces.
945          */
946         public BestBlock current_best_block() {
947                 long ret = bindings.ChannelManager_current_best_block(this.ptr);
948                 Reference.reachabilityFence(this);
949                 if (ret >= 0 && ret <= 4096) { return null; }
950                 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
951                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
952                 return ret_hu_conv;
953         }
954
955         /**
956          * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
957          * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
958          */
959         public ChannelMessageHandler as_ChannelMessageHandler() {
960                 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
961                 Reference.reachabilityFence(this);
962                 if (ret >= 0 && ret <= 4096) { return null; }
963                 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
964                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
965                 return ret_hu_conv;
966         }
967
968         /**
969          * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
970          */
971         public byte[] write() {
972                 byte[] ret = bindings.ChannelManager_write(this.ptr);
973                 Reference.reachabilityFence(this);
974                 return ret;
975         }
976
977         /**
978          * Constructs a new Payer which calls the relevant methods on this_arg.
979          * This copies the `inner` pointer in this_arg and thus the returned Payer must be freed before this_arg is
980          */
981         public Payer as_Payer() {
982                 long ret = bindings.ChannelManager_as_Payer(this.ptr);
983                 Reference.reachabilityFence(this);
984                 if (ret >= 0 && ret <= 4096) { return null; }
985                 Payer ret_hu_conv = new Payer(null, ret);
986                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
987                 return ret_hu_conv;
988         }
989
990 }