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