1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
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.
15 * Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
16 * to individual Channels.
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).
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).
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
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.
43 * To avoid trivial DoS issues, ChannelManager limits the number of inbound connections and
44 * inbound channels without confirmed funding transactions. This may result in nodes which we do
45 * not have a channel with being unable to connect to us or open new channels with us if we have
46 * many peers with unfunded channels.
48 * Because it is an indication of trust, inbound channels which we've accepted as 0conf are
49 * exempted from the count of unfunded channels. Similarly, outbound channels and connections are
50 * never limited. Please ensure you limit the count of such channels yourself.
52 * Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
53 * a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
54 * essentially you should default to using a SimpleRefChannelManager, and use a
55 * SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
56 * you're using lightning-net-tokio.
58 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
59 public class ChannelManager extends CommonBase {
60 ChannelManager(Object _dummy, long ptr) { super(ptr); }
61 @Override @SuppressWarnings("deprecation")
62 protected void finalize() throws Throwable {
64 if (ptr != 0) { bindings.ChannelManager_free(ptr); }
68 * Constructs a new ChannelManager to hold several channels and route between them.
70 * This is the main \"logic hub\" for all channel-related actions, and implements
71 * ChannelMessageHandler.
73 * Non-proportional fees are fixed according to our risk using the provided fee estimator.
75 * Users need to notify the new ChannelManager when a new block is connected or
76 * disconnected using its `block_connected` and `block_disconnected` methods, starting
77 * from after `params.latest_hash`.
79 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.Router router, org.ldk.structs.Logger logger, org.ldk.structs.EntropySource entropy_source, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.SignerProvider signer_provider, org.ldk.structs.UserConfig config, org.ldk.structs.ChainParameters params) {
80 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, router == null ? 0 : router.ptr, logger == null ? 0 : logger.ptr, entropy_source == null ? 0 : entropy_source.ptr, node_signer == null ? 0 : node_signer.ptr, signer_provider == null ? 0 : signer_provider.ptr, config == null ? 0 : config.ptr, params == null ? 0 : params.ptr);
81 Reference.reachabilityFence(fee_est);
82 Reference.reachabilityFence(chain_monitor);
83 Reference.reachabilityFence(tx_broadcaster);
84 Reference.reachabilityFence(router);
85 Reference.reachabilityFence(logger);
86 Reference.reachabilityFence(entropy_source);
87 Reference.reachabilityFence(node_signer);
88 Reference.reachabilityFence(signer_provider);
89 Reference.reachabilityFence(config);
90 Reference.reachabilityFence(params);
91 if (ret >= 0 && ret <= 4096) { return null; }
92 org.ldk.structs.ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManager(null, ret); }
93 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
94 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fee_est); };
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_monitor); };
96 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(tx_broadcaster); };
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(router); };
98 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
99 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
100 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
101 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(signer_provider); };
102 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(config); };
103 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(params); };
108 * Gets the current configuration applied to all new channels.
110 public UserConfig get_current_default_configuration() {
111 long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
112 Reference.reachabilityFence(this);
113 if (ret >= 0 && ret <= 4096) { return null; }
114 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
115 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
120 * Creates a new outbound channel to the given remote node and with the given value.
122 * `user_channel_id` will be provided back as in
123 * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
124 * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
125 * randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
126 * is simply copied to events and otherwise ignored.
128 * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
129 * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
131 * Note that we do not check if you are currently connected to the given peer. If no
132 * connection is available, the outbound `open_channel` message may fail to send, resulting in
133 * the channel eventually being silently forgotten (dropped on reload).
135 * Returns the new Channel's temporary `channel_id`. This ID will appear as
136 * [`Event::FundingGenerationReady::temporary_channel_id`] and in
137 * [`ChannelDetails::channel_id`] until after
138 * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
139 * one derived from the funding transaction's TXID. If the counterparty rejects the channel
140 * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
142 * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
143 * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
144 * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
146 * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
148 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) {
149 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);
150 Reference.reachabilityFence(this);
151 Reference.reachabilityFence(their_network_key);
152 Reference.reachabilityFence(channel_value_satoshis);
153 Reference.reachabilityFence(push_msat);
154 Reference.reachabilityFence(user_channel_id);
155 Reference.reachabilityFence(override_config);
156 if (ret >= 0 && ret <= 4096) { return null; }
157 Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
158 if (this != null) { this.ptrs_to.add(override_config); };
163 * Gets the list of open channels, in random order. See ChannelDetail field documentation for
166 public ChannelDetails[] list_channels() {
167 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
168 Reference.reachabilityFence(this);
169 int ret_conv_16_len = ret.length;
170 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
171 for (int q = 0; q < ret_conv_16_len; q++) {
172 long ret_conv_16 = ret[q];
173 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); }
174 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
175 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
177 return ret_conv_16_arr;
181 * Gets the list of usable channels, in random order. Useful as an argument to
182 * [`Router::find_route`] to ensure non-announced channels are used.
184 * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
185 * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
188 public ChannelDetails[] list_usable_channels() {
189 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
190 Reference.reachabilityFence(this);
191 int ret_conv_16_len = ret.length;
192 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
193 for (int q = 0; q < ret_conv_16_len; q++) {
194 long ret_conv_16 = ret[q];
195 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); }
196 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
197 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
199 return ret_conv_16_arr;
203 * Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
204 * successful path, or have unresolved HTLCs.
206 * This can be useful for payments that may have been prepared, but ultimately not sent, as a
207 * result of a crash. If such a payment exists, is not listed here, and an
208 * [`Event::PaymentSent`] has not been received, you may consider resending the payment.
210 * [`Event::PaymentSent`]: events::Event::PaymentSent
212 public RecentPaymentDetails[] list_recent_payments() {
213 long[] ret = bindings.ChannelManager_list_recent_payments(this.ptr);
214 Reference.reachabilityFence(this);
215 int ret_conv_22_len = ret.length;
216 RecentPaymentDetails[] ret_conv_22_arr = new RecentPaymentDetails[ret_conv_22_len];
217 for (int w = 0; w < ret_conv_22_len; w++) {
218 long ret_conv_22 = ret[w];
219 org.ldk.structs.RecentPaymentDetails ret_conv_22_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret_conv_22);
220 if (ret_conv_22_hu_conv != null) { ret_conv_22_hu_conv.ptrs_to.add(this); };
221 ret_conv_22_arr[w] = ret_conv_22_hu_conv;
223 return ret_conv_22_arr;
227 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
228 * will be accepted on the given channel, and after additional timeout/the closing of all
229 * pending HTLCs, the channel will be closed on chain.
231 * If we are the channel initiator, we will pay between our [`Background`] and
232 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
234 * If our counterparty is the channel initiator, we will require a channel closing
235 * transaction feerate of at least our [`Background`] feerate or the feerate which
236 * would appear on a force-closure transaction, whichever is lower. We will allow our
237 * counterparty to pay as much fee as they'd like, however.
239 * May generate a SendShutdown message event on success, which should be relayed.
241 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
242 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
243 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
245 public Result_NoneAPIErrorZ close_channel(byte[] channel_id, byte[] counterparty_node_id) {
246 long ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
247 Reference.reachabilityFence(this);
248 Reference.reachabilityFence(channel_id);
249 Reference.reachabilityFence(counterparty_node_id);
250 if (ret >= 0 && ret <= 4096) { return null; }
251 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
256 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
257 * will be accepted on the given channel, and after additional timeout/the closing of all
258 * pending HTLCs, the channel will be closed on chain.
260 * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
261 * the channel being closed or not:
262 * If we are the channel initiator, we will pay at least this feerate on the closing
263 * transaction. The upper-bound is set by
264 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
265 * estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
266 * If our counterparty is the channel initiator, we will refuse to accept a channel closure
267 * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
268 * will appear on a force-closure transaction, whichever is lower).
270 * May generate a SendShutdown message event on success, which should be relayed.
272 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
273 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
274 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
276 public Result_NoneAPIErrorZ close_channel_with_target_feerate(byte[] channel_id, byte[] counterparty_node_id, int target_feerate_sats_per_1000_weight) {
277 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);
278 Reference.reachabilityFence(this);
279 Reference.reachabilityFence(channel_id);
280 Reference.reachabilityFence(counterparty_node_id);
281 Reference.reachabilityFence(target_feerate_sats_per_1000_weight);
282 if (ret >= 0 && ret <= 4096) { return null; }
283 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
288 * Force closes a channel, immediately broadcasting the latest local transaction(s) and
289 * rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
290 * the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
293 public Result_NoneAPIErrorZ force_close_broadcasting_latest_txn(byte[] channel_id, byte[] counterparty_node_id) {
294 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));
295 Reference.reachabilityFence(this);
296 Reference.reachabilityFence(channel_id);
297 Reference.reachabilityFence(counterparty_node_id);
298 if (ret >= 0 && ret <= 4096) { return null; }
299 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
304 * Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
305 * the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
306 * `counterparty_node_id` isn't the counterparty of the corresponding channel.
308 * You can always get the latest local transaction(s) to broadcast from
309 * [`ChannelMonitor::get_latest_holder_commitment_txn`].
311 public Result_NoneAPIErrorZ force_close_without_broadcasting_txn(byte[] channel_id, byte[] counterparty_node_id) {
312 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));
313 Reference.reachabilityFence(this);
314 Reference.reachabilityFence(channel_id);
315 Reference.reachabilityFence(counterparty_node_id);
316 if (ret >= 0 && ret <= 4096) { return null; }
317 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
322 * Force close all channels, immediately broadcasting the latest local commitment transaction
323 * for each to the chain and rejecting new HTLCs on each.
325 public void force_close_all_channels_broadcasting_latest_txn() {
326 bindings.ChannelManager_force_close_all_channels_broadcasting_latest_txn(this.ptr);
327 Reference.reachabilityFence(this);
331 * Force close all channels rejecting new HTLCs on each but without broadcasting the latest
332 * local transaction(s).
334 public void force_close_all_channels_without_broadcasting_txn() {
335 bindings.ChannelManager_force_close_all_channels_without_broadcasting_txn(this.ptr);
336 Reference.reachabilityFence(this);
340 * Sends a payment along a given route.
342 * Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
343 * fields for more info.
345 * May generate SendHTLCs message(s) event on success, which should be relayed (e.g. via
346 * [`PeerManager::process_events`]).
348 * # Avoiding Duplicate Payments
350 * If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
351 * method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
352 * is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
353 * [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
354 * second payment with the same [`PaymentId`].
356 * Thus, in order to ensure duplicate payments are not sent, you should implement your own
357 * tracking of payments, including state to indicate once a payment has completed. Because you
358 * should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
359 * consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
360 * [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
362 * Additionally, in the scenario where we begin the process of sending a payment, but crash
363 * before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
364 * using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
365 * [`ChannelManager::list_recent_payments`] for more information.
367 * # Possible Error States on [`PaymentSendFailure`]
369 * Each path may have a different return value, and PaymentSendValue may return a Vec with
370 * each entry matching the corresponding-index entry in the route paths, see
371 * [`PaymentSendFailure`] for more info.
373 * In general, a path may raise:
374 * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
375 * node public key) is specified.
376 * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
377 * (including due to previous monitor update failure or new permanent monitor update
379 * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
382 * Note that depending on the type of the PaymentSendFailure the HTLC may have been
383 * irrevocably committed to on our end. In such a case, do NOT retry the payment with a
384 * different route unless you intend to pay twice!
386 * # A caution on `payment_secret`
388 * `payment_secret` is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
389 * authenticate the sender to the recipient and prevent payment-probing (deanonymization)
390 * attacks. For newer nodes, it will be provided to you in the invoice. If you do not have one,
391 * the [`Route`] must not contain multiple paths as multi-path payments require a
392 * recipient-provided `payment_secret`.
394 * If a `payment_secret` *is* provided, we assume that the invoice had the payment_secret
395 * feature bit set (either as required or as available). If multiple paths are present in the
396 * [`Route`], we assume the invoice had the basic_mpp feature set.
398 * [`Event::PaymentSent`]: events::Event::PaymentSent
399 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
400 * [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
401 * [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
403 * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
405 public Result_NonePaymentSendFailureZ send_payment(org.ldk.structs.Route route, byte[] payment_hash, @Nullable byte[] payment_secret, byte[] payment_id) {
406 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));
407 Reference.reachabilityFence(this);
408 Reference.reachabilityFence(route);
409 Reference.reachabilityFence(payment_hash);
410 Reference.reachabilityFence(payment_secret);
411 Reference.reachabilityFence(payment_id);
412 if (ret >= 0 && ret <= 4096) { return null; }
413 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
414 if (this != null) { this.ptrs_to.add(route); };
419 * Similar to [`ChannelManager::send_payment`], but will automatically find a route based on
420 * `route_params` and retry failed payment paths based on `retry_strategy`.
422 * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
424 public Result_NoneRetryableSendFailureZ send_payment_with_retry(byte[] payment_hash, @Nullable byte[] payment_secret, byte[] payment_id, org.ldk.structs.RouteParameters route_params, org.ldk.structs.Retry retry_strategy) {
425 long ret = bindings.ChannelManager_send_payment_with_retry(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32), InternalUtils.check_arr_len(payment_id, 32), route_params == null ? 0 : route_params.ptr, retry_strategy.ptr);
426 Reference.reachabilityFence(this);
427 Reference.reachabilityFence(payment_hash);
428 Reference.reachabilityFence(payment_secret);
429 Reference.reachabilityFence(payment_id);
430 Reference.reachabilityFence(route_params);
431 Reference.reachabilityFence(retry_strategy);
432 if (ret >= 0 && ret <= 4096) { return null; }
433 Result_NoneRetryableSendFailureZ ret_hu_conv = Result_NoneRetryableSendFailureZ.constr_from_ptr(ret);
434 if (this != null) { this.ptrs_to.add(route_params); };
435 if (this != null) { this.ptrs_to.add(retry_strategy); };
440 * Signals that no further retries for the given payment should occur. Useful if you have a
441 * pending outbound payment with retries remaining, but wish to stop retrying the payment before
442 * retries are exhausted.
444 * If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
445 * as there are no remaining pending HTLCs for this payment.
447 * Note that calling this method does *not* prevent a payment from succeeding. You must still
448 * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
449 * determine the ultimate status of a payment.
451 * If an [`Event::PaymentFailed`] event is generated and we restart without this
452 * [`ChannelManager`] having been persisted, another [`Event::PaymentFailed`] may be generated.
454 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
455 * [`Event::PaymentSent`]: events::Event::PaymentSent
457 public void abandon_payment(byte[] payment_id) {
458 bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
459 Reference.reachabilityFence(this);
460 Reference.reachabilityFence(payment_id);
464 * Send a spontaneous payment, which is a payment that does not require the recipient to have
465 * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
466 * the preimage, it must be a cryptographically secure random value that no intermediate node
467 * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
468 * never reach the recipient.
470 * See [`send_payment`] documentation for more details on the return value of this function
471 * and idempotency guarantees provided by the [`PaymentId`] key.
473 * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
474 * [`send_payment`] for more information about the risks of duplicate preimage usage.
476 * Note that `route` must have exactly one path.
478 * [`send_payment`]: Self::send_payment
480 * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
482 public Result_PaymentHashPaymentSendFailureZ send_spontaneous_payment(org.ldk.structs.Route route, @Nullable byte[] payment_preimage, byte[] payment_id) {
483 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));
484 Reference.reachabilityFence(this);
485 Reference.reachabilityFence(route);
486 Reference.reachabilityFence(payment_preimage);
487 Reference.reachabilityFence(payment_id);
488 if (ret >= 0 && ret <= 4096) { return null; }
489 Result_PaymentHashPaymentSendFailureZ ret_hu_conv = Result_PaymentHashPaymentSendFailureZ.constr_from_ptr(ret);
490 if (this != null) { this.ptrs_to.add(route); };
495 * Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
496 * based on `route_params` and retry failed payment paths based on `retry_strategy`.
498 * See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
501 * [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
503 * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
505 public Result_PaymentHashRetryableSendFailureZ send_spontaneous_payment_with_retry(@Nullable byte[] payment_preimage, byte[] payment_id, org.ldk.structs.RouteParameters route_params, org.ldk.structs.Retry retry_strategy) {
506 long ret = bindings.ChannelManager_send_spontaneous_payment_with_retry(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_id, 32), route_params == null ? 0 : route_params.ptr, retry_strategy.ptr);
507 Reference.reachabilityFence(this);
508 Reference.reachabilityFence(payment_preimage);
509 Reference.reachabilityFence(payment_id);
510 Reference.reachabilityFence(route_params);
511 Reference.reachabilityFence(retry_strategy);
512 if (ret >= 0 && ret <= 4096) { return null; }
513 Result_PaymentHashRetryableSendFailureZ ret_hu_conv = Result_PaymentHashRetryableSendFailureZ.constr_from_ptr(ret);
514 if (this != null) { this.ptrs_to.add(route_params); };
515 if (this != null) { this.ptrs_to.add(retry_strategy); };
520 * Send a payment that is probing the given route for liquidity. We calculate the
521 * [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
522 * us to easily discern them from real payments.
524 public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_probe(RouteHop[] hops) {
525 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);
526 Reference.reachabilityFence(this);
527 Reference.reachabilityFence(hops);
528 if (ret >= 0 && ret <= 4096) { return null; }
529 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
530 for (RouteHop hops_conv_10: hops) { if (this != null) { this.ptrs_to.add(hops_conv_10); }; };
535 * Call this upon creation of a funding transaction for the given channel.
537 * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
538 * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
540 * Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
541 * across the p2p network.
543 * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
544 * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
546 * May panic if the output found in the funding transaction is duplicative with some other
547 * channel (note that this should be trivially prevented by using unique funding transaction
550 * Do NOT broadcast the funding transaction yourself. When we have safely received our
551 * counterparty's signature the funding transaction will automatically be broadcast via the
552 * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
554 * Note that this includes RBF or similar transaction replacement strategies - lightning does
555 * not currently support replacing a funding transaction on an existing channel. Instead,
556 * create a new channel with a conflicting funding transaction.
558 * Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
559 * the wallet software generating the funding transaction to apply anti-fee sniping as
560 * implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
563 * [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
564 * [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
566 public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] counterparty_node_id, byte[] funding_transaction) {
567 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);
568 Reference.reachabilityFence(this);
569 Reference.reachabilityFence(temporary_channel_id);
570 Reference.reachabilityFence(counterparty_node_id);
571 Reference.reachabilityFence(funding_transaction);
572 if (ret >= 0 && ret <= 4096) { return null; }
573 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
578 * Atomically updates the [`ChannelConfig`] for the given channels.
580 * Once the updates are applied, each eligible channel (advertised with a known short channel
581 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
582 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
583 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
585 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
586 * `counterparty_node_id` is provided.
588 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
589 * below [`MIN_CLTV_EXPIRY_DELTA`].
591 * If an error is returned, none of the updates should be considered applied.
593 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
594 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
595 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
596 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
597 * [`ChannelUpdate`]: msgs::ChannelUpdate
598 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
599 * [`APIMisuseError`]: APIError::APIMisuseError
601 public Result_NoneAPIErrorZ update_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfig config) {
602 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);
603 Reference.reachabilityFence(this);
604 Reference.reachabilityFence(counterparty_node_id);
605 Reference.reachabilityFence(channel_ids);
606 Reference.reachabilityFence(config);
607 if (ret >= 0 && ret <= 4096) { return null; }
608 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
609 if (this != null) { this.ptrs_to.add(config); };
614 * Attempts to forward an intercepted HTLC over the provided channel id and with the provided
615 * amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
617 * Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
618 * channel to a receiving node if the node lacks sufficient inbound liquidity.
620 * To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
621 * [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
622 * receiver's invoice route hints. These route hints will signal to LDK to generate an
623 * [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
624 * [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
626 * Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
627 * you from forwarding more than you received.
629 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
632 * [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
633 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
635 public Result_NoneAPIErrorZ forward_intercepted_htlc(byte[] intercept_id, byte[] next_hop_channel_id, byte[] next_node_id, long amt_to_forward_msat) {
636 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);
637 Reference.reachabilityFence(this);
638 Reference.reachabilityFence(intercept_id);
639 Reference.reachabilityFence(next_hop_channel_id);
640 Reference.reachabilityFence(next_node_id);
641 Reference.reachabilityFence(amt_to_forward_msat);
642 if (ret >= 0 && ret <= 4096) { return null; }
643 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
648 * Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
649 * an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
651 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
654 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
656 public Result_NoneAPIErrorZ fail_intercepted_htlc(byte[] intercept_id) {
657 long ret = bindings.ChannelManager_fail_intercepted_htlc(this.ptr, InternalUtils.check_arr_len(intercept_id, 32));
658 Reference.reachabilityFence(this);
659 Reference.reachabilityFence(intercept_id);
660 if (ret >= 0 && ret <= 4096) { return null; }
661 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
666 * Processes HTLCs which are pending waiting on random forward delay.
668 * Should only really ever be called in response to a PendingHTLCsForwardable event.
669 * Will likely generate further events.
671 public void process_pending_htlc_forwards() {
672 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
673 Reference.reachabilityFence(this);
677 * Performs actions which should happen on startup and roughly once per minute thereafter.
679 * This currently includes:
680 * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
681 * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
682 * than a minute, informing the network that they should no longer attempt to route over
684 * Expiring a channel's previous `ChannelConfig` if necessary to only allow forwarding HTLCs
685 * with the current `ChannelConfig`.
686 * Removing peers which have disconnected but and no longer have any channels.
688 * Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
691 public void timer_tick_occurred() {
692 bindings.ChannelManager_timer_tick_occurred(this.ptr);
693 Reference.reachabilityFence(this);
697 * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
698 * after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
699 * along the path (including in our own channel on which we received it).
701 * Note that in some cases around unclean shutdown, it is possible the payment may have
702 * already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
703 * second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
704 * may have already been failed automatically by LDK if it was nearing its expiration time.
706 * While LDK will never claim a payment automatically on your behalf (i.e. without you calling
707 * [`ChannelManager::claim_funds`]), you should still monitor for
708 * [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
709 * startup during which time claims that were in-progress at shutdown may be replayed.
711 public void fail_htlc_backwards(byte[] payment_hash) {
712 bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
713 Reference.reachabilityFence(this);
714 Reference.reachabilityFence(payment_hash);
718 * This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
719 * reason for the failure.
721 * See [`FailureCode`] for valid failure codes.
723 public void fail_htlc_backwards_with_reason(byte[] payment_hash, org.ldk.enums.FailureCode failure_code) {
724 bindings.ChannelManager_fail_htlc_backwards_with_reason(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), failure_code);
725 Reference.reachabilityFence(this);
726 Reference.reachabilityFence(payment_hash);
727 Reference.reachabilityFence(failure_code);
731 * Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
732 * [`MessageSendEvent`]s needed to claim the payment.
734 * Note that calling this method does *not* guarantee that the payment has been claimed. You
735 * must* wait for an [`Event::PaymentClaimed`] event which upon a successful claim will be
736 * provided to your [`EventHandler`] when [`process_pending_events`] is next called.
738 * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
739 * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
740 * event matches your expectation. If you fail to do so and call this method, you may provide
741 * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
743 * [`Event::PaymentClaimable`]: crate::util::events::Event::PaymentClaimable
744 * [`Event::PaymentClaimed`]: crate::util::events::Event::PaymentClaimed
745 * [`process_pending_events`]: EventsProvider::process_pending_events
746 * [`create_inbound_payment`]: Self::create_inbound_payment
747 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
749 public void claim_funds(byte[] payment_preimage) {
750 bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
751 Reference.reachabilityFence(this);
752 Reference.reachabilityFence(payment_preimage);
756 * Gets the node_id held by this ChannelManager
758 public byte[] get_our_node_id() {
759 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
760 Reference.reachabilityFence(this);
765 * Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
767 * The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
768 * and the `counterparty_node_id` parameter is the id of the peer which has requested to open
771 * The `user_channel_id` parameter will be provided back in
772 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
773 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
775 * Note that this method will return an error and reject the channel, if it requires support
776 * for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
777 * used to accept such channels.
779 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
780 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
782 public Result_NoneAPIErrorZ accept_inbound_channel(byte[] temporary_channel_id, byte[] counterparty_node_id, org.ldk.util.UInt128 user_channel_id) {
783 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());
784 Reference.reachabilityFence(this);
785 Reference.reachabilityFence(temporary_channel_id);
786 Reference.reachabilityFence(counterparty_node_id);
787 Reference.reachabilityFence(user_channel_id);
788 if (ret >= 0 && ret <= 4096) { return null; }
789 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
794 * Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
795 * it as confirmed immediately.
797 * The `user_channel_id` parameter will be provided back in
798 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
799 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
801 * Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
802 * and (if the counterparty agrees), enables forwarding of payments immediately.
804 * This fully trusts that the counterparty has honestly and correctly constructed the funding
805 * transaction and blindly assumes that it will eventually confirm.
807 * If it does not confirm before we decide to close the channel, or if the funding transaction
808 * does not pay to the correct script the correct amount, *you will lose funds*.
810 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
811 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
813 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) {
814 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());
815 Reference.reachabilityFence(this);
816 Reference.reachabilityFence(temporary_channel_id);
817 Reference.reachabilityFence(counterparty_node_id);
818 Reference.reachabilityFence(user_channel_id);
819 if (ret >= 0 && ret <= 4096) { return null; }
820 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
825 * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
828 * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
829 * [`PaymentHash`] and [`PaymentPreimage`] for you.
831 * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`], which
832 * will have the [`PaymentClaimable::purpose`] be [`PaymentPurpose::InvoicePayment`] with
833 * its [`PaymentPurpose::InvoicePayment::payment_preimage`] field filled in. That should then be
834 * passed directly to [`claim_funds`].
836 * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
838 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
839 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
843 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
844 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
846 * Errors if `min_value_msat` is greater than total bitcoin supply.
848 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
849 * on versions of LDK prior to 0.0.114.
851 * [`claim_funds`]: Self::claim_funds
852 * [`PaymentClaimable`]: events::Event::PaymentClaimable
853 * [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
854 * [`PaymentPurpose::InvoicePayment`]: events::PaymentPurpose::InvoicePayment
855 * [`PaymentPurpose::InvoicePayment::payment_preimage`]: events::PaymentPurpose::InvoicePayment::payment_preimage
856 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
858 public Result_C2Tuple_PaymentHashPaymentSecretZNoneZ create_inbound_payment(org.ldk.structs.Option_u64Z min_value_msat, int invoice_expiry_delta_secs, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
859 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
860 Reference.reachabilityFence(this);
861 Reference.reachabilityFence(min_value_msat);
862 Reference.reachabilityFence(invoice_expiry_delta_secs);
863 Reference.reachabilityFence(min_final_cltv_expiry_delta);
864 if (ret >= 0 && ret <= 4096) { return null; }
865 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
866 if (this != null) { this.ptrs_to.add(min_value_msat); };
867 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry_delta); };
872 * Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
873 * serialized state with LDK node(s) running 0.0.103 and earlier.
875 * May panic if `invoice_expiry_delta_secs` is greater than one year.
878 * This method is deprecated and will be removed soon.
880 * [`create_inbound_payment`]: Self::create_inbound_payment
882 public Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ create_inbound_payment_legacy(org.ldk.structs.Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
883 long ret = bindings.ChannelManager_create_inbound_payment_legacy(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs);
884 Reference.reachabilityFence(this);
885 Reference.reachabilityFence(min_value_msat);
886 Reference.reachabilityFence(invoice_expiry_delta_secs);
887 if (ret >= 0 && ret <= 4096) { return null; }
888 Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ.constr_from_ptr(ret);
889 if (this != null) { this.ptrs_to.add(min_value_msat); };
894 * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
895 * stored external to LDK.
897 * A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
898 * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
899 * the `min_value_msat` provided here, if one is provided.
901 * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
902 * note that LDK will not stop you from registering duplicate payment hashes for inbound
905 * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
906 * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
907 * before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
908 * sender \"proof-of-payment\" unless they have paid the required amount.
910 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
911 * in excess of the current time. This should roughly match the expiry time set in the invoice.
912 * After this many seconds, we will remove the inbound payment, resulting in any attempts to
913 * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
914 * invoices when no timeout is set.
916 * Note that we use block header time to time-out pending inbound payments (with some margin
917 * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
918 * accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
919 * If you need exact expiry semantics, you should enforce them upon receipt of
920 * [`PaymentClaimable`].
922 * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
923 * set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
925 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
926 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
930 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
931 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
933 * Errors if `min_value_msat` is greater than total bitcoin supply.
935 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
936 * on versions of LDK prior to 0.0.114.
938 * [`create_inbound_payment`]: Self::create_inbound_payment
939 * [`PaymentClaimable`]: events::Event::PaymentClaimable
941 public Result_PaymentSecretNoneZ create_inbound_payment_for_hash(byte[] payment_hash, org.ldk.structs.Option_u64Z min_value_msat, int invoice_expiry_delta_secs, org.ldk.structs.Option_u16Z min_final_cltv_expiry) {
942 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, min_final_cltv_expiry.ptr);
943 Reference.reachabilityFence(this);
944 Reference.reachabilityFence(payment_hash);
945 Reference.reachabilityFence(min_value_msat);
946 Reference.reachabilityFence(invoice_expiry_delta_secs);
947 Reference.reachabilityFence(min_final_cltv_expiry);
948 if (ret >= 0 && ret <= 4096) { return null; }
949 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
950 if (this != null) { this.ptrs_to.add(min_value_msat); };
951 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry); };
956 * Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
957 * serialized state with LDK node(s) running 0.0.103 and earlier.
959 * May panic if `invoice_expiry_delta_secs` is greater than one year.
962 * This method is deprecated and will be removed soon.
964 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
966 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) {
967 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);
968 Reference.reachabilityFence(this);
969 Reference.reachabilityFence(payment_hash);
970 Reference.reachabilityFence(min_value_msat);
971 Reference.reachabilityFence(invoice_expiry_delta_secs);
972 if (ret >= 0 && ret <= 4096) { return null; }
973 Result_PaymentSecretAPIErrorZ ret_hu_conv = Result_PaymentSecretAPIErrorZ.constr_from_ptr(ret);
974 if (this != null) { this.ptrs_to.add(min_value_msat); };
979 * Gets an LDK-generated payment preimage from a payment hash and payment secret that were
980 * previously returned from [`create_inbound_payment`].
982 * [`create_inbound_payment`]: Self::create_inbound_payment
984 public Result_PaymentPreimageAPIErrorZ get_payment_preimage(byte[] payment_hash, byte[] payment_secret) {
985 long ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
986 Reference.reachabilityFence(this);
987 Reference.reachabilityFence(payment_hash);
988 Reference.reachabilityFence(payment_secret);
989 if (ret >= 0 && ret <= 4096) { return null; }
990 Result_PaymentPreimageAPIErrorZ ret_hu_conv = Result_PaymentPreimageAPIErrorZ.constr_from_ptr(ret);
995 * Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
996 * are used when constructing the phantom invoice's route hints.
998 * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
1000 public long get_phantom_scid() {
1001 long ret = bindings.ChannelManager_get_phantom_scid(this.ptr);
1002 Reference.reachabilityFence(this);
1007 * Gets route hints for use in receiving [phantom node payments].
1009 * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
1011 public PhantomRouteHints get_phantom_route_hints() {
1012 long ret = bindings.ChannelManager_get_phantom_route_hints(this.ptr);
1013 Reference.reachabilityFence(this);
1014 if (ret >= 0 && ret <= 4096) { return null; }
1015 org.ldk.structs.PhantomRouteHints ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomRouteHints(null, ret); }
1016 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1021 * Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
1022 * used when constructing the route hints for HTLCs intended to be intercepted. See
1023 * [`ChannelManager::forward_intercepted_htlc`].
1025 * Note that this method is not guaranteed to return unique values, you may need to call it a few
1026 * times to get a unique scid.
1028 public long get_intercept_scid() {
1029 long ret = bindings.ChannelManager_get_intercept_scid(this.ptr);
1030 Reference.reachabilityFence(this);
1035 * Gets inflight HTLC information by processing pending outbound payments that are in
1036 * our channels. May be used during pathfinding to account for in-use channel liquidity.
1038 public InFlightHtlcs compute_inflight_htlcs() {
1039 long ret = bindings.ChannelManager_compute_inflight_htlcs(this.ptr);
1040 Reference.reachabilityFence(this);
1041 if (ret >= 0 && ret <= 4096) { return null; }
1042 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
1043 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1048 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1049 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1051 public MessageSendEventsProvider as_MessageSendEventsProvider() {
1052 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
1053 Reference.reachabilityFence(this);
1054 if (ret >= 0 && ret <= 4096) { return null; }
1055 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
1056 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1061 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
1062 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1064 public EventsProvider as_EventsProvider() {
1065 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
1066 Reference.reachabilityFence(this);
1067 if (ret >= 0 && ret <= 4096) { return null; }
1068 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
1069 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1074 * Constructs a new Listen which calls the relevant methods on this_arg.
1075 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1077 public Listen as_Listen() {
1078 long ret = bindings.ChannelManager_as_Listen(this.ptr);
1079 Reference.reachabilityFence(this);
1080 if (ret >= 0 && ret <= 4096) { return null; }
1081 Listen ret_hu_conv = new Listen(null, ret);
1082 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1087 * Constructs a new Confirm which calls the relevant methods on this_arg.
1088 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1090 public Confirm as_Confirm() {
1091 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
1092 Reference.reachabilityFence(this);
1093 if (ret >= 0 && ret <= 4096) { return null; }
1094 Confirm ret_hu_conv = new Confirm(null, ret);
1095 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1100 * Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
1101 * indicating whether persistence is necessary. Only one listener on
1102 * [`await_persistable_update`], [`await_persistable_update_timeout`], or a future returned by
1103 * [`get_persistable_update_future`] is guaranteed to be woken up.
1105 * Note that this method is not available with the `no-std` feature.
1107 * [`await_persistable_update`]: Self::await_persistable_update
1108 * [`await_persistable_update_timeout`]: Self::await_persistable_update_timeout
1109 * [`get_persistable_update_future`]: Self::get_persistable_update_future
1111 public boolean await_persistable_update_timeout(long max_wait) {
1112 boolean ret = bindings.ChannelManager_await_persistable_update_timeout(this.ptr, max_wait);
1113 Reference.reachabilityFence(this);
1114 Reference.reachabilityFence(max_wait);
1119 * Blocks until ChannelManager needs to be persisted. Only one listener on
1120 * [`await_persistable_update`], `await_persistable_update_timeout`, or a future returned by
1121 * [`get_persistable_update_future`] is guaranteed to be woken up.
1123 * [`await_persistable_update`]: Self::await_persistable_update
1124 * [`get_persistable_update_future`]: Self::get_persistable_update_future
1126 public void await_persistable_update() {
1127 bindings.ChannelManager_await_persistable_update(this.ptr);
1128 Reference.reachabilityFence(this);
1132 * Gets a [`Future`] that completes when a persistable update is available. Note that
1133 * callbacks registered on the [`Future`] MUST NOT call back into this [`ChannelManager`] and
1134 * should instead register actions to be taken later.
1136 public Future get_persistable_update_future() {
1137 long ret = bindings.ChannelManager_get_persistable_update_future(this.ptr);
1138 Reference.reachabilityFence(this);
1139 if (ret >= 0 && ret <= 4096) { return null; }
1140 org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); }
1141 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1146 * Gets the latest best block which was connected either via the [`chain::Listen`] or
1147 * [`chain::Confirm`] interfaces.
1149 public BestBlock current_best_block() {
1150 long ret = bindings.ChannelManager_current_best_block(this.ptr);
1151 Reference.reachabilityFence(this);
1152 if (ret >= 0 && ret <= 4096) { return null; }
1153 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
1154 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1159 * Fetches the set of [`NodeFeatures`] flags which are provided by or required by
1160 * [`ChannelManager`].
1162 public NodeFeatures node_features() {
1163 long ret = bindings.ChannelManager_node_features(this.ptr);
1164 Reference.reachabilityFence(this);
1165 if (ret >= 0 && ret <= 4096) { return null; }
1166 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
1167 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1172 * Fetches the set of [`ChannelFeatures`] flags which are provided by or required by
1173 * [`ChannelManager`].
1175 public ChannelFeatures channel_features() {
1176 long ret = bindings.ChannelManager_channel_features(this.ptr);
1177 Reference.reachabilityFence(this);
1178 if (ret >= 0 && ret <= 4096) { return null; }
1179 org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); }
1180 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1185 * Fetches the set of [`ChannelTypeFeatures`] flags which are provided by or required by
1186 * [`ChannelManager`].
1188 public ChannelTypeFeatures channel_type_features() {
1189 long ret = bindings.ChannelManager_channel_type_features(this.ptr);
1190 Reference.reachabilityFence(this);
1191 if (ret >= 0 && ret <= 4096) { return null; }
1192 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
1193 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1198 * Fetches the set of [`InitFeatures`] flags which are provided by or required by
1199 * [`ChannelManager`].
1201 public InitFeatures init_features() {
1202 long ret = bindings.ChannelManager_init_features(this.ptr);
1203 Reference.reachabilityFence(this);
1204 if (ret >= 0 && ret <= 4096) { return null; }
1205 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
1206 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1211 * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1212 * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1214 public ChannelMessageHandler as_ChannelMessageHandler() {
1215 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
1216 Reference.reachabilityFence(this);
1217 if (ret >= 0 && ret <= 4096) { return null; }
1218 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
1219 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1224 * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1226 public byte[] write() {
1227 byte[] ret = bindings.ChannelManager_write(this.ptr);
1228 Reference.reachabilityFence(this);