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`] (i.e.,
21 * called [`funding_transaction_generated`] for outbound channels) being closed.
23 * Note that you can be a bit lazier about writing out `ChannelManager` than you can be with
24 * [`ChannelMonitor`]. With [`ChannelMonitor`] you MUST durably write each
25 * [`ChannelMonitorUpdate`] before returning from
26 * [`chain::Watch::watch_channel`]/[`update_channel`] or before completing async writes. With
27 * `ChannelManager`s, writing updates happens out-of-band (and will prevent any other
28 * `ChannelManager` operations from occurring during the serialization process). If the
29 * deserialized version is out-of-date compared to the [`ChannelMonitor`] passed by reference to
30 * [`read`], those channels will be force-closed based on the `ChannelMonitor` state and no funds
31 * will be lost (modulo on-chain transaction fees).
33 * Note that the deserializer is only implemented for `(`[`BlockHash`]`, `[`ChannelManager`]`)`, which
34 * tells you the last block hash which was connected. You should get the best block tip before using the manager.
35 * See [`chain::Listen`] and [`chain::Confirm`] for more details.
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 * [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
59 * [`funding_created`]: msgs::FundingCreated
60 * [`funding_transaction_generated`]: Self::funding_transaction_generated
61 * [`BlockHash`]: bitcoin::hash_types::BlockHash
62 * [`update_channel`]: chain::Watch::update_channel
63 * [`ChannelUpdate`]: msgs::ChannelUpdate
64 * [`timer_tick_occurred`]: Self::timer_tick_occurred
65 * [`read`]: ReadableArgs::read
67 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
68 public class ChannelManager extends CommonBase {
69 ChannelManager(Object _dummy, long ptr) { super(ptr); }
70 @Override @SuppressWarnings("deprecation")
71 protected void finalize() throws Throwable {
73 if (ptr != 0) { bindings.ChannelManager_free(ptr); }
77 * Constructs a new `ChannelManager` to hold several channels and route between them.
79 * The current time or latest block header time can be provided as the `current_timestamp`.
81 * This is the main \"logic hub\" for all channel-related actions, and implements
82 * [`ChannelMessageHandler`].
84 * Non-proportional fees are fixed according to our risk using the provided fee estimator.
86 * Users need to notify the new `ChannelManager` when a new block is connected or
87 * disconnected using its [`block_connected`] and [`block_disconnected`] methods, starting
88 * from after [`params.best_block.block_hash`]. See [`chain::Listen`] and [`chain::Confirm`] for
91 * [`block_connected`]: chain::Listen::block_connected
92 * [`block_disconnected`]: chain::Listen::block_disconnected
93 * [`params.best_block.block_hash`]: chain::BestBlock::block_hash
95 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, int current_timestamp) {
96 long ret = bindings.ChannelManager_new(fee_est.ptr, chain_monitor.ptr, tx_broadcaster.ptr, router.ptr, logger.ptr, entropy_source.ptr, node_signer.ptr, signer_provider.ptr, config == null ? 0 : config.ptr, params == null ? 0 : params.ptr, current_timestamp);
97 Reference.reachabilityFence(fee_est);
98 Reference.reachabilityFence(chain_monitor);
99 Reference.reachabilityFence(tx_broadcaster);
100 Reference.reachabilityFence(router);
101 Reference.reachabilityFence(logger);
102 Reference.reachabilityFence(entropy_source);
103 Reference.reachabilityFence(node_signer);
104 Reference.reachabilityFence(signer_provider);
105 Reference.reachabilityFence(config);
106 Reference.reachabilityFence(params);
107 Reference.reachabilityFence(current_timestamp);
108 if (ret >= 0 && ret <= 4096) { return null; }
109 org.ldk.structs.ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManager(null, ret); }
110 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fee_est); };
112 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_monitor); };
113 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(tx_broadcaster); };
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(router); };
115 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
116 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
117 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
118 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(signer_provider); };
119 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(config); };
120 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(params); };
125 * Gets the current configuration applied to all new channels.
127 public UserConfig get_current_default_configuration() {
128 long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
129 Reference.reachabilityFence(this);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
132 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
137 * Creates a new outbound channel to the given remote node and with the given value.
139 * `user_channel_id` will be provided back as in
140 * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
141 * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
142 * randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
143 * is simply copied to events and otherwise ignored.
145 * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
146 * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
148 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be opened due to failing to
149 * generate a shutdown scriptpubkey or destination script set by
150 * [`SignerProvider::get_shutdown_scriptpubkey`] or [`SignerProvider::get_destination_script`].
152 * Note that we do not check if you are currently connected to the given peer. If no
153 * connection is available, the outbound `open_channel` message may fail to send, resulting in
154 * the channel eventually being silently forgotten (dropped on reload).
156 * Returns the new Channel's temporary `channel_id`. This ID will appear as
157 * [`Event::FundingGenerationReady::temporary_channel_id`] and in
158 * [`ChannelDetails::channel_id`] until after
159 * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
160 * one derived from the funding transaction's TXID. If the counterparty rejects the channel
161 * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
163 * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
164 * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
165 * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
167 * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
169 public Result_ThirtyTwoBytesAPIErrorZ 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) {
170 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);
171 Reference.reachabilityFence(this);
172 Reference.reachabilityFence(their_network_key);
173 Reference.reachabilityFence(channel_value_satoshis);
174 Reference.reachabilityFence(push_msat);
175 Reference.reachabilityFence(user_channel_id);
176 Reference.reachabilityFence(override_config);
177 if (ret >= 0 && ret <= 4096) { return null; }
178 Result_ThirtyTwoBytesAPIErrorZ ret_hu_conv = Result_ThirtyTwoBytesAPIErrorZ.constr_from_ptr(ret);
179 if (this != null) { this.ptrs_to.add(override_config); };
184 * Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for
187 public ChannelDetails[] list_channels() {
188 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
189 Reference.reachabilityFence(this);
190 int ret_conv_16_len = ret.length;
191 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
192 for (int q = 0; q < ret_conv_16_len; q++) {
193 long ret_conv_16 = ret[q];
194 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); }
195 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
196 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
198 return ret_conv_16_arr;
202 * Gets the list of usable channels, in random order. Useful as an argument to
203 * [`Router::find_route`] to ensure non-announced channels are used.
205 * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
206 * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
209 public ChannelDetails[] list_usable_channels() {
210 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
211 Reference.reachabilityFence(this);
212 int ret_conv_16_len = ret.length;
213 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
214 for (int q = 0; q < ret_conv_16_len; q++) {
215 long ret_conv_16 = ret[q];
216 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); }
217 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
218 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
220 return ret_conv_16_arr;
224 * Gets the list of channels we have with a given counterparty, in random order.
226 public ChannelDetails[] list_channels_with_counterparty(byte[] counterparty_node_id) {
227 long[] ret = bindings.ChannelManager_list_channels_with_counterparty(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33));
228 Reference.reachabilityFence(this);
229 Reference.reachabilityFence(counterparty_node_id);
230 int ret_conv_16_len = ret.length;
231 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
232 for (int q = 0; q < ret_conv_16_len; q++) {
233 long ret_conv_16 = ret[q];
234 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); }
235 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
236 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
238 return ret_conv_16_arr;
242 * Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
243 * successful path, or have unresolved HTLCs.
245 * This can be useful for payments that may have been prepared, but ultimately not sent, as a
246 * result of a crash. If such a payment exists, is not listed here, and an
247 * [`Event::PaymentSent`] has not been received, you may consider resending the payment.
249 * [`Event::PaymentSent`]: events::Event::PaymentSent
251 public RecentPaymentDetails[] list_recent_payments() {
252 long[] ret = bindings.ChannelManager_list_recent_payments(this.ptr);
253 Reference.reachabilityFence(this);
254 int ret_conv_22_len = ret.length;
255 RecentPaymentDetails[] ret_conv_22_arr = new RecentPaymentDetails[ret_conv_22_len];
256 for (int w = 0; w < ret_conv_22_len; w++) {
257 long ret_conv_22 = ret[w];
258 org.ldk.structs.RecentPaymentDetails ret_conv_22_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret_conv_22);
259 if (ret_conv_22_hu_conv != null) { ret_conv_22_hu_conv.ptrs_to.add(this); };
260 ret_conv_22_arr[w] = ret_conv_22_hu_conv;
262 return ret_conv_22_arr;
266 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
267 * will be accepted on the given channel, and after additional timeout/the closing of all
268 * pending HTLCs, the channel will be closed on chain.
270 * If we are the channel initiator, we will pay between our [`ChannelCloseMinimum`] and
271 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
273 * If our counterparty is the channel initiator, we will require a channel closing
274 * transaction feerate of at least our [`ChannelCloseMinimum`] feerate or the feerate which
275 * would appear on a force-closure transaction, whichever is lower. We will allow our
276 * counterparty to pay as much fee as they'd like, however.
278 * May generate a [`SendShutdown`] message event on success, which should be relayed.
280 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
281 * generate a shutdown scriptpubkey or destination script set by
282 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
285 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
286 * [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum
287 * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
288 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
290 public Result_NoneAPIErrorZ close_channel(byte[] channel_id, byte[] counterparty_node_id) {
291 long ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
292 Reference.reachabilityFence(this);
293 Reference.reachabilityFence(channel_id);
294 Reference.reachabilityFence(counterparty_node_id);
295 if (ret >= 0 && ret <= 4096) { return null; }
296 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
301 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
302 * will be accepted on the given channel, and after additional timeout/the closing of all
303 * pending HTLCs, the channel will be closed on chain.
305 * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
306 * the channel being closed or not:
307 * If we are the channel initiator, we will pay at least this feerate on the closing
308 * transaction. The upper-bound is set by
309 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
310 * fee estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
311 * If our counterparty is the channel initiator, we will refuse to accept a channel closure
312 * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
313 * will appear on a force-closure transaction, whichever is lower).
315 * The `shutdown_script` provided will be used as the `scriptPubKey` for the closing transaction.
316 * Will fail if a shutdown script has already been set for this channel by
317 * ['ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`]. The given shutdown script must
318 * also be compatible with our and the counterparty's features.
320 * May generate a [`SendShutdown`] message event on success, which should be relayed.
322 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
323 * generate a shutdown scriptpubkey or destination script set by
324 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
327 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
328 * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
329 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
331 * Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None
333 public Result_NoneAPIErrorZ close_channel_with_feerate_and_script(byte[] channel_id, byte[] counterparty_node_id, org.ldk.structs.Option_u32Z target_feerate_sats_per_1000_weight, @Nullable org.ldk.structs.ShutdownScript shutdown_script) {
334 long ret = bindings.ChannelManager_close_channel_with_feerate_and_script(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33), target_feerate_sats_per_1000_weight.ptr, shutdown_script == null ? 0 : shutdown_script.ptr);
335 Reference.reachabilityFence(this);
336 Reference.reachabilityFence(channel_id);
337 Reference.reachabilityFence(counterparty_node_id);
338 Reference.reachabilityFence(target_feerate_sats_per_1000_weight);
339 Reference.reachabilityFence(shutdown_script);
340 if (ret >= 0 && ret <= 4096) { return null; }
341 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
342 if (this != null) { this.ptrs_to.add(target_feerate_sats_per_1000_weight); };
343 if (this != null) { this.ptrs_to.add(shutdown_script); };
348 * Force closes a channel, immediately broadcasting the latest local transaction(s) and
349 * rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
350 * the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
353 public Result_NoneAPIErrorZ force_close_broadcasting_latest_txn(byte[] channel_id, byte[] counterparty_node_id) {
354 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));
355 Reference.reachabilityFence(this);
356 Reference.reachabilityFence(channel_id);
357 Reference.reachabilityFence(counterparty_node_id);
358 if (ret >= 0 && ret <= 4096) { return null; }
359 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
364 * Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
365 * the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
366 * `counterparty_node_id` isn't the counterparty of the corresponding channel.
368 * You can always get the latest local transaction(s) to broadcast from
369 * [`ChannelMonitor::get_latest_holder_commitment_txn`].
371 public Result_NoneAPIErrorZ force_close_without_broadcasting_txn(byte[] channel_id, byte[] counterparty_node_id) {
372 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));
373 Reference.reachabilityFence(this);
374 Reference.reachabilityFence(channel_id);
375 Reference.reachabilityFence(counterparty_node_id);
376 if (ret >= 0 && ret <= 4096) { return null; }
377 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
382 * Force close all channels, immediately broadcasting the latest local commitment transaction
383 * for each to the chain and rejecting new HTLCs on each.
385 public void force_close_all_channels_broadcasting_latest_txn() {
386 bindings.ChannelManager_force_close_all_channels_broadcasting_latest_txn(this.ptr);
387 Reference.reachabilityFence(this);
391 * Force close all channels rejecting new HTLCs on each but without broadcasting the latest
392 * local transaction(s).
394 public void force_close_all_channels_without_broadcasting_txn() {
395 bindings.ChannelManager_force_close_all_channels_without_broadcasting_txn(this.ptr);
396 Reference.reachabilityFence(this);
400 * Sends a payment along a given route.
402 * Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
403 * fields for more info.
405 * May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
406 * [`PeerManager::process_events`]).
408 * # Avoiding Duplicate Payments
410 * If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
411 * method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
412 * is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
413 * [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
414 * second payment with the same [`PaymentId`].
416 * Thus, in order to ensure duplicate payments are not sent, you should implement your own
417 * tracking of payments, including state to indicate once a payment has completed. Because you
418 * should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
419 * consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
420 * [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
422 * Additionally, in the scenario where we begin the process of sending a payment, but crash
423 * before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
424 * using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
425 * [`ChannelManager::list_recent_payments`] for more information.
427 * # Possible Error States on [`PaymentSendFailure`]
429 * Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
430 * each entry matching the corresponding-index entry in the route paths, see
431 * [`PaymentSendFailure`] for more info.
433 * In general, a path may raise:
434 * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
435 * node public key) is specified.
436 * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
437 * closed, doesn't exist, or the peer is currently disconnected.
438 * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
441 * Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
442 * irrevocably committed to on our end. In such a case, do NOT retry the payment with a
443 * different route unless you intend to pay twice!
445 * [`RouteHop`]: crate::routing::router::RouteHop
446 * [`Event::PaymentSent`]: events::Event::PaymentSent
447 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
448 * [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
449 * [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
450 * [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
452 public Result_NonePaymentSendFailureZ send_payment_with_route(org.ldk.structs.Route route, byte[] payment_hash, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id) {
453 long ret = bindings.ChannelManager_send_payment_with_route(this.ptr, route == null ? 0 : route.ptr, InternalUtils.check_arr_len(payment_hash, 32), recipient_onion == null ? 0 : recipient_onion.ptr, InternalUtils.check_arr_len(payment_id, 32));
454 Reference.reachabilityFence(this);
455 Reference.reachabilityFence(route);
456 Reference.reachabilityFence(payment_hash);
457 Reference.reachabilityFence(recipient_onion);
458 Reference.reachabilityFence(payment_id);
459 if (ret >= 0 && ret <= 4096) { return null; }
460 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
461 if (this != null) { this.ptrs_to.add(route); };
462 if (this != null) { this.ptrs_to.add(recipient_onion); };
467 * Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
468 * `route_params` and retry failed payment paths based on `retry_strategy`.
470 public Result_NoneRetryableSendFailureZ send_payment(byte[] payment_hash, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id, org.ldk.structs.RouteParameters route_params, org.ldk.structs.Retry retry_strategy) {
471 long ret = bindings.ChannelManager_send_payment(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), recipient_onion == null ? 0 : recipient_onion.ptr, InternalUtils.check_arr_len(payment_id, 32), route_params == null ? 0 : route_params.ptr, retry_strategy.ptr);
472 Reference.reachabilityFence(this);
473 Reference.reachabilityFence(payment_hash);
474 Reference.reachabilityFence(recipient_onion);
475 Reference.reachabilityFence(payment_id);
476 Reference.reachabilityFence(route_params);
477 Reference.reachabilityFence(retry_strategy);
478 if (ret >= 0 && ret <= 4096) { return null; }
479 Result_NoneRetryableSendFailureZ ret_hu_conv = Result_NoneRetryableSendFailureZ.constr_from_ptr(ret);
480 if (this != null) { this.ptrs_to.add(recipient_onion); };
481 if (this != null) { this.ptrs_to.add(route_params); };
482 if (this != null) { this.ptrs_to.add(retry_strategy); };
487 * Signals that no further attempts for the given payment should occur. Useful if you have a
488 * pending outbound payment with retries remaining, but wish to stop retrying the payment before
489 * retries are exhausted.
493 * If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
494 * as there are no remaining pending HTLCs for this payment.
496 * Note that calling this method does *not* prevent a payment from succeeding. You must still
497 * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
498 * determine the ultimate status of a payment.
500 * # Requested Invoices
502 * In the case of paying a [`Bolt12Invoice`] via [`ChannelManager::pay_for_offer`], abandoning
503 * the payment prior to receiving the invoice will result in an [`Event::InvoiceRequestFailed`]
504 * and prevent any attempts at paying it once received. The other events may only be generated
505 * once the invoice has been received.
509 * If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
510 * [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
511 * [`Event::InvoiceRequestFailed`].
513 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
515 public void abandon_payment(byte[] payment_id) {
516 bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
517 Reference.reachabilityFence(this);
518 Reference.reachabilityFence(payment_id);
522 * Send a spontaneous payment, which is a payment that does not require the recipient to have
523 * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
524 * the preimage, it must be a cryptographically secure random value that no intermediate node
525 * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
526 * never reach the recipient.
528 * See [`send_payment`] documentation for more details on the return value of this function
529 * and idempotency guarantees provided by the [`PaymentId`] key.
531 * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
532 * [`send_payment`] for more information about the risks of duplicate preimage usage.
534 * [`send_payment`]: Self::send_payment
536 public Result_ThirtyTwoBytesPaymentSendFailureZ send_spontaneous_payment(org.ldk.structs.Route route, org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id) {
537 long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr, payment_preimage.ptr, recipient_onion == null ? 0 : recipient_onion.ptr, InternalUtils.check_arr_len(payment_id, 32));
538 Reference.reachabilityFence(this);
539 Reference.reachabilityFence(route);
540 Reference.reachabilityFence(payment_preimage);
541 Reference.reachabilityFence(recipient_onion);
542 Reference.reachabilityFence(payment_id);
543 if (ret >= 0 && ret <= 4096) { return null; }
544 Result_ThirtyTwoBytesPaymentSendFailureZ ret_hu_conv = Result_ThirtyTwoBytesPaymentSendFailureZ.constr_from_ptr(ret);
545 if (this != null) { this.ptrs_to.add(route); };
546 if (this != null) { this.ptrs_to.add(payment_preimage); };
547 if (this != null) { this.ptrs_to.add(recipient_onion); };
552 * Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
553 * based on `route_params` and retry failed payment paths based on `retry_strategy`.
555 * See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
558 * [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
560 public Result_ThirtyTwoBytesRetryableSendFailureZ send_spontaneous_payment_with_retry(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id, org.ldk.structs.RouteParameters route_params, org.ldk.structs.Retry retry_strategy) {
561 long ret = bindings.ChannelManager_send_spontaneous_payment_with_retry(this.ptr, payment_preimage.ptr, recipient_onion == null ? 0 : recipient_onion.ptr, InternalUtils.check_arr_len(payment_id, 32), route_params == null ? 0 : route_params.ptr, retry_strategy.ptr);
562 Reference.reachabilityFence(this);
563 Reference.reachabilityFence(payment_preimage);
564 Reference.reachabilityFence(recipient_onion);
565 Reference.reachabilityFence(payment_id);
566 Reference.reachabilityFence(route_params);
567 Reference.reachabilityFence(retry_strategy);
568 if (ret >= 0 && ret <= 4096) { return null; }
569 Result_ThirtyTwoBytesRetryableSendFailureZ ret_hu_conv = Result_ThirtyTwoBytesRetryableSendFailureZ.constr_from_ptr(ret);
570 if (this != null) { this.ptrs_to.add(payment_preimage); };
571 if (this != null) { this.ptrs_to.add(recipient_onion); };
572 if (this != null) { this.ptrs_to.add(route_params); };
573 if (this != null) { this.ptrs_to.add(retry_strategy); };
578 * Send a payment that is probing the given route for liquidity. We calculate the
579 * [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
580 * us to easily discern them from real payments.
582 public Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ send_probe(org.ldk.structs.Path path) {
583 long ret = bindings.ChannelManager_send_probe(this.ptr, path == null ? 0 : path.ptr);
584 Reference.reachabilityFence(this);
585 Reference.reachabilityFence(path);
586 if (ret >= 0 && ret <= 4096) { return null; }
587 Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ.constr_from_ptr(ret);
588 if (this != null) { this.ptrs_to.add(path); };
593 * Sends payment probes over all paths of a route that would be used to pay the given
594 * amount to the given `node_id`.
596 * See [`ChannelManager::send_preflight_probes`] for more information.
598 public Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ send_spontaneous_preflight_probes(byte[] node_id, long amount_msat, int final_cltv_expiry_delta, org.ldk.structs.Option_u64Z liquidity_limit_multiplier) {
599 long ret = bindings.ChannelManager_send_spontaneous_preflight_probes(this.ptr, InternalUtils.check_arr_len(node_id, 33), amount_msat, final_cltv_expiry_delta, liquidity_limit_multiplier.ptr);
600 Reference.reachabilityFence(this);
601 Reference.reachabilityFence(node_id);
602 Reference.reachabilityFence(amount_msat);
603 Reference.reachabilityFence(final_cltv_expiry_delta);
604 Reference.reachabilityFence(liquidity_limit_multiplier);
605 if (ret >= 0 && ret <= 4096) { return null; }
606 Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ ret_hu_conv = Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ.constr_from_ptr(ret);
607 if (this != null) { this.ptrs_to.add(liquidity_limit_multiplier); };
612 * Sends payment probes over all paths of a route that would be used to pay a route found
613 * according to the given [`RouteParameters`].
615 * This may be used to send \"pre-flight\" probes, i.e., to train our scorer before conducting
616 * the actual payment. Note this is only useful if there likely is sufficient time for the
617 * probe to settle before sending out the actual payment, e.g., when waiting for user
618 * confirmation in a wallet UI.
620 * Otherwise, there is a chance the probe could take up some liquidity needed to complete the
621 * actual payment. Users should therefore be cautious and might avoid sending probes if
622 * liquidity is scarce and/or they don't expect the probe to return before they send the
623 * payment. To mitigate this issue, channels with available liquidity less than the required
624 * amount times the given `liquidity_limit_multiplier` won't be used to send pre-flight
625 * probes. If `None` is given as `liquidity_limit_multiplier`, it defaults to `3`.
627 public Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ send_preflight_probes(org.ldk.structs.RouteParameters route_params, org.ldk.structs.Option_u64Z liquidity_limit_multiplier) {
628 long ret = bindings.ChannelManager_send_preflight_probes(this.ptr, route_params == null ? 0 : route_params.ptr, liquidity_limit_multiplier.ptr);
629 Reference.reachabilityFence(this);
630 Reference.reachabilityFence(route_params);
631 Reference.reachabilityFence(liquidity_limit_multiplier);
632 if (ret >= 0 && ret <= 4096) { return null; }
633 Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ ret_hu_conv = Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ.constr_from_ptr(ret);
634 if (this != null) { this.ptrs_to.add(route_params); };
635 if (this != null) { this.ptrs_to.add(liquidity_limit_multiplier); };
640 * Call this upon creation of a funding transaction for the given channel.
642 * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
643 * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
645 * Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
646 * across the p2p network.
648 * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
649 * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
651 * May panic if the output found in the funding transaction is duplicative with some other
652 * channel (note that this should be trivially prevented by using unique funding transaction
655 * Do NOT broadcast the funding transaction yourself. When we have safely received our
656 * counterparty's signature the funding transaction will automatically be broadcast via the
657 * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
659 * Note that this includes RBF or similar transaction replacement strategies - lightning does
660 * not currently support replacing a funding transaction on an existing channel. Instead,
661 * create a new channel with a conflicting funding transaction.
663 * Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
664 * the wallet software generating the funding transaction to apply anti-fee sniping as
665 * implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
668 * [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
669 * [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
671 public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] counterparty_node_id, byte[] funding_transaction) {
672 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);
673 Reference.reachabilityFence(this);
674 Reference.reachabilityFence(temporary_channel_id);
675 Reference.reachabilityFence(counterparty_node_id);
676 Reference.reachabilityFence(funding_transaction);
677 if (ret >= 0 && ret <= 4096) { return null; }
678 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
683 * Call this upon creation of a batch funding transaction for the given channels.
685 * Return values are identical to [`Self::funding_transaction_generated`], respective to
686 * each individual channel and transaction output.
688 * Do NOT broadcast the funding transaction yourself. This batch funding transcaction
689 * will only be broadcast when we have safely received and persisted the counterparty's
690 * signature for each channel.
692 * If there is an error, all channels in the batch are to be considered closed.
694 public Result_NoneAPIErrorZ batch_funding_transaction_generated(TwoTuple_ThirtyTwoBytesPublicKeyZ[] temporary_channels, byte[] funding_transaction) {
695 long ret = bindings.ChannelManager_batch_funding_transaction_generated(this.ptr, temporary_channels != null ? Arrays.stream(temporary_channels).mapToLong(temporary_channels_conv_35 -> temporary_channels_conv_35 != null ? temporary_channels_conv_35.ptr : 0).toArray() : null, funding_transaction);
696 Reference.reachabilityFence(this);
697 Reference.reachabilityFence(temporary_channels);
698 Reference.reachabilityFence(funding_transaction);
699 if (ret >= 0 && ret <= 4096) { return null; }
700 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
705 * Atomically applies partial updates to the [`ChannelConfig`] of the given channels.
707 * Once the updates are applied, each eligible channel (advertised with a known short channel
708 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
709 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
710 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
712 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
713 * `counterparty_node_id` is provided.
715 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
716 * below [`MIN_CLTV_EXPIRY_DELTA`].
718 * If an error is returned, none of the updates should be considered applied.
720 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
721 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
722 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
723 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
724 * [`ChannelUpdate`]: msgs::ChannelUpdate
725 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
726 * [`APIMisuseError`]: APIError::APIMisuseError
728 public Result_NoneAPIErrorZ update_partial_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfigUpdate config_update) {
729 long ret = bindings.ChannelManager_update_partial_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_update == null ? 0 : config_update.ptr);
730 Reference.reachabilityFence(this);
731 Reference.reachabilityFence(counterparty_node_id);
732 Reference.reachabilityFence(channel_ids);
733 Reference.reachabilityFence(config_update);
734 if (ret >= 0 && ret <= 4096) { return null; }
735 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
736 if (this != null) { this.ptrs_to.add(config_update); };
741 * Atomically updates the [`ChannelConfig`] for the given channels.
743 * Once the updates are applied, each eligible channel (advertised with a known short channel
744 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
745 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
746 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
748 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
749 * `counterparty_node_id` is provided.
751 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
752 * below [`MIN_CLTV_EXPIRY_DELTA`].
754 * If an error is returned, none of the updates should be considered applied.
756 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
757 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
758 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
759 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
760 * [`ChannelUpdate`]: msgs::ChannelUpdate
761 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
762 * [`APIMisuseError`]: APIError::APIMisuseError
764 public Result_NoneAPIErrorZ update_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfig config) {
765 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);
766 Reference.reachabilityFence(this);
767 Reference.reachabilityFence(counterparty_node_id);
768 Reference.reachabilityFence(channel_ids);
769 Reference.reachabilityFence(config);
770 if (ret >= 0 && ret <= 4096) { return null; }
771 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
772 if (this != null) { this.ptrs_to.add(config); };
777 * Attempts to forward an intercepted HTLC over the provided channel id and with the provided
778 * amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
780 * Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
781 * channel to a receiving node if the node lacks sufficient inbound liquidity.
783 * To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
784 * [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
785 * receiver's invoice route hints. These route hints will signal to LDK to generate an
786 * [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
787 * [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
789 * Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
790 * you from forwarding more than you received. See
791 * [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
794 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
797 * [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
798 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
799 * [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
801 public Result_NoneAPIErrorZ forward_intercepted_htlc(byte[] intercept_id, byte[] next_hop_channel_id, byte[] next_node_id, long amt_to_forward_msat) {
802 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);
803 Reference.reachabilityFence(this);
804 Reference.reachabilityFence(intercept_id);
805 Reference.reachabilityFence(next_hop_channel_id);
806 Reference.reachabilityFence(next_node_id);
807 Reference.reachabilityFence(amt_to_forward_msat);
808 if (ret >= 0 && ret <= 4096) { return null; }
809 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
814 * Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
815 * an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
817 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
820 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
822 public Result_NoneAPIErrorZ fail_intercepted_htlc(byte[] intercept_id) {
823 long ret = bindings.ChannelManager_fail_intercepted_htlc(this.ptr, InternalUtils.check_arr_len(intercept_id, 32));
824 Reference.reachabilityFence(this);
825 Reference.reachabilityFence(intercept_id);
826 if (ret >= 0 && ret <= 4096) { return null; }
827 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
832 * Processes HTLCs which are pending waiting on random forward delay.
834 * Should only really ever be called in response to a PendingHTLCsForwardable event.
835 * Will likely generate further events.
837 public void process_pending_htlc_forwards() {
838 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
839 Reference.reachabilityFence(this);
843 * Performs actions which should happen on startup and roughly once per minute thereafter.
845 * This currently includes:
846 * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
847 * Broadcasting [`ChannelUpdate`] messages if we've been disconnected from our peer for more
848 * than a minute, informing the network that they should no longer attempt to route over
850 * Expiring a channel's previous [`ChannelConfig`] if necessary to only allow forwarding HTLCs
851 * with the current [`ChannelConfig`].
852 * Removing peers which have disconnected but and no longer have any channels.
853 * Force-closing and removing channels which have not completed establishment in a timely manner.
854 * Forgetting about stale outbound payments, either those that have already been fulfilled
855 * or those awaiting an invoice that hasn't been delivered in the necessary amount of time.
856 * The latter is determined using the system clock in `std` and the highest seen block time
857 * minus two hours in `no-std`.
859 * Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
862 * [`ChannelUpdate`]: msgs::ChannelUpdate
863 * [`ChannelConfig`]: crate::util::config::ChannelConfig
865 public void timer_tick_occurred() {
866 bindings.ChannelManager_timer_tick_occurred(this.ptr);
867 Reference.reachabilityFence(this);
871 * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
872 * after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
873 * along the path (including in our own channel on which we received it).
875 * Note that in some cases around unclean shutdown, it is possible the payment may have
876 * already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
877 * second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
878 * may have already been failed automatically by LDK if it was nearing its expiration time.
880 * While LDK will never claim a payment automatically on your behalf (i.e. without you calling
881 * [`ChannelManager::claim_funds`]), you should still monitor for
882 * [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
883 * startup during which time claims that were in-progress at shutdown may be replayed.
885 public void fail_htlc_backwards(byte[] payment_hash) {
886 bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
887 Reference.reachabilityFence(this);
888 Reference.reachabilityFence(payment_hash);
892 * This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
893 * reason for the failure.
895 * See [`FailureCode`] for valid failure codes.
897 public void fail_htlc_backwards_with_reason(byte[] payment_hash, org.ldk.structs.FailureCode failure_code) {
898 bindings.ChannelManager_fail_htlc_backwards_with_reason(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), failure_code.ptr);
899 Reference.reachabilityFence(this);
900 Reference.reachabilityFence(payment_hash);
901 Reference.reachabilityFence(failure_code);
902 if (this != null) { this.ptrs_to.add(failure_code); };
906 * Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
907 * [`MessageSendEvent`]s needed to claim the payment.
909 * This method is guaranteed to ensure the payment has been claimed but only if the current
910 * height is strictly below [`Event::PaymentClaimable::claim_deadline`]. To avoid race
911 * conditions, you should wait for an [`Event::PaymentClaimed`] before considering the payment
912 * successful. It will generally be available in the next [`process_pending_events`] call.
914 * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
915 * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
916 * event matches your expectation. If you fail to do so and call this method, you may provide
917 * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
919 * This function will fail the payment if it has custom TLVs with even type numbers, as we
920 * will assume they are unknown. If you intend to accept even custom TLVs, you should use
921 * [`claim_funds_with_known_custom_tlvs`].
923 * [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
924 * [`Event::PaymentClaimable::claim_deadline`]: crate::events::Event::PaymentClaimable::claim_deadline
925 * [`Event::PaymentClaimed`]: crate::events::Event::PaymentClaimed
926 * [`process_pending_events`]: EventsProvider::process_pending_events
927 * [`create_inbound_payment`]: Self::create_inbound_payment
928 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
929 * [`claim_funds_with_known_custom_tlvs`]: Self::claim_funds_with_known_custom_tlvs
931 public void claim_funds(byte[] payment_preimage) {
932 bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
933 Reference.reachabilityFence(this);
934 Reference.reachabilityFence(payment_preimage);
938 * This is a variant of [`claim_funds`] that allows accepting a payment with custom TLVs with
943 * You MUST check you've understood all even TLVs before using this to
944 * claim, otherwise you may unintentionally agree to some protocol you do not understand.
946 * [`claim_funds`]: Self::claim_funds
948 public void claim_funds_with_known_custom_tlvs(byte[] payment_preimage) {
949 bindings.ChannelManager_claim_funds_with_known_custom_tlvs(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
950 Reference.reachabilityFence(this);
951 Reference.reachabilityFence(payment_preimage);
955 * Gets the node_id held by this ChannelManager
957 public byte[] get_our_node_id() {
958 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
959 Reference.reachabilityFence(this);
964 * Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
966 * The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
967 * and the `counterparty_node_id` parameter is the id of the peer which has requested to open
970 * The `user_channel_id` parameter will be provided back in
971 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
972 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
974 * Note that this method will return an error and reject the channel, if it requires support
975 * for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
976 * used to accept such channels.
978 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
979 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
981 public Result_NoneAPIErrorZ accept_inbound_channel(byte[] temporary_channel_id, byte[] counterparty_node_id, org.ldk.util.UInt128 user_channel_id) {
982 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());
983 Reference.reachabilityFence(this);
984 Reference.reachabilityFence(temporary_channel_id);
985 Reference.reachabilityFence(counterparty_node_id);
986 Reference.reachabilityFence(user_channel_id);
987 if (ret >= 0 && ret <= 4096) { return null; }
988 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
993 * Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
994 * it as confirmed immediately.
996 * The `user_channel_id` parameter will be provided back in
997 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
998 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
1000 * Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
1001 * and (if the counterparty agrees), enables forwarding of payments immediately.
1003 * This fully trusts that the counterparty has honestly and correctly constructed the funding
1004 * transaction and blindly assumes that it will eventually confirm.
1006 * If it does not confirm before we decide to close the channel, or if the funding transaction
1007 * does not pay to the correct script the correct amount, *you will lose funds*.
1009 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
1010 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
1012 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) {
1013 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());
1014 Reference.reachabilityFence(this);
1015 Reference.reachabilityFence(temporary_channel_id);
1016 Reference.reachabilityFence(counterparty_node_id);
1017 Reference.reachabilityFence(user_channel_id);
1018 if (ret >= 0 && ret <= 4096) { return null; }
1019 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
1024 * Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
1025 * enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
1026 * [`Bolt12Invoice`] once it is received.
1028 * Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
1029 * the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
1030 * The optional parameters are used in the builder, if `Some`:
1031 * - `quantity` for [`InvoiceRequest::quantity`] which must be set if
1032 * [`Offer::expects_quantity`] is `true`.
1033 * - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
1034 * - `payer_note` for [`InvoiceRequest::payer_note`].
1036 * If `max_total_routing_fee_msat` is not specified, The default from
1037 * [`RouteParameters::from_payment_params_and_value`] is applied.
1041 * The provided `payment_id` is used to ensure that only one invoice is paid for the request
1042 * when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
1045 * To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
1046 * invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
1047 * payment will fail with an [`Event::InvoiceRequestFailed`].
1051 * Uses a one-hop [`BlindedPath`] for the reply path with [`ChannelManager::get_our_node_id`]
1052 * as the introduction node and a derived payer id for payer privacy. As such, currently, the
1053 * node must be announced. Otherwise, there is no way to find a path to the introduction node
1054 * in order to send the [`Bolt12Invoice`].
1058 * Requires a direct connection to an introduction node in [`Offer::paths`] or to
1059 * [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding
1060 * [`Bolt12Invoice::payment_paths`].
1064 * Errors if a duplicate `payment_id` is provided given the caveats in the aforementioned link
1065 * or if the provided parameters are invalid for the offer.
1067 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
1068 * [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
1069 * [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
1070 * [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
1071 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
1072 * [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
1073 * [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
1075 public Result_NoneBolt12SemanticErrorZ pay_for_offer(org.ldk.structs.Offer offer, org.ldk.structs.Option_u64Z quantity, org.ldk.structs.Option_u64Z amount_msats, org.ldk.structs.Option_StrZ payer_note, byte[] payment_id, org.ldk.structs.Retry retry_strategy, org.ldk.structs.Option_u64Z max_total_routing_fee_msat) {
1076 long ret = bindings.ChannelManager_pay_for_offer(this.ptr, offer == null ? 0 : offer.ptr, quantity.ptr, amount_msats.ptr, payer_note.ptr, InternalUtils.check_arr_len(payment_id, 32), retry_strategy.ptr, max_total_routing_fee_msat.ptr);
1077 Reference.reachabilityFence(this);
1078 Reference.reachabilityFence(offer);
1079 Reference.reachabilityFence(quantity);
1080 Reference.reachabilityFence(amount_msats);
1081 Reference.reachabilityFence(payer_note);
1082 Reference.reachabilityFence(payment_id);
1083 Reference.reachabilityFence(retry_strategy);
1084 Reference.reachabilityFence(max_total_routing_fee_msat);
1085 if (ret >= 0 && ret <= 4096) { return null; }
1086 Result_NoneBolt12SemanticErrorZ ret_hu_conv = Result_NoneBolt12SemanticErrorZ.constr_from_ptr(ret);
1087 if (this != null) { this.ptrs_to.add(offer); };
1088 if (this != null) { this.ptrs_to.add(quantity); };
1089 if (this != null) { this.ptrs_to.add(amount_msats); };
1090 if (this != null) { this.ptrs_to.add(payer_note); };
1091 if (this != null) { this.ptrs_to.add(retry_strategy); };
1092 if (this != null) { this.ptrs_to.add(max_total_routing_fee_msat); };
1097 * Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
1100 * The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
1101 * [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding
1102 * [`PaymentPreimage`].
1106 * Requires a direct connection to an introduction node in [`Refund::paths`] or to
1107 * [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each
1108 * node meeting the aforementioned criteria, but there's no guarantee that they will be
1109 * received and no retries will be made.
1111 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
1113 public Result_NoneBolt12SemanticErrorZ request_refund_payment(org.ldk.structs.Refund refund) {
1114 long ret = bindings.ChannelManager_request_refund_payment(this.ptr, refund == null ? 0 : refund.ptr);
1115 Reference.reachabilityFence(this);
1116 Reference.reachabilityFence(refund);
1117 if (ret >= 0 && ret <= 4096) { return null; }
1118 Result_NoneBolt12SemanticErrorZ ret_hu_conv = Result_NoneBolt12SemanticErrorZ.constr_from_ptr(ret);
1119 if (this != null) { this.ptrs_to.add(refund); };
1124 * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1127 * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1128 * [`PaymentHash`] and [`PaymentPreimage`] for you.
1130 * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`], which
1131 * will have the [`PaymentClaimable::purpose`] be [`PaymentPurpose::InvoicePayment`] with
1132 * its [`PaymentPurpose::InvoicePayment::payment_preimage`] field filled in. That should then be
1133 * passed directly to [`claim_funds`].
1135 * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1137 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1138 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1142 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1143 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1145 * Errors if `min_value_msat` is greater than total bitcoin supply.
1147 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
1148 * on versions of LDK prior to 0.0.114.
1150 * [`claim_funds`]: Self::claim_funds
1151 * [`PaymentClaimable`]: events::Event::PaymentClaimable
1152 * [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
1153 * [`PaymentPurpose::InvoicePayment`]: events::PaymentPurpose::InvoicePayment
1154 * [`PaymentPurpose::InvoicePayment::payment_preimage`]: events::PaymentPurpose::InvoicePayment::payment_preimage
1155 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1157 public Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ 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) {
1158 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
1159 Reference.reachabilityFence(this);
1160 Reference.reachabilityFence(min_value_msat);
1161 Reference.reachabilityFence(invoice_expiry_delta_secs);
1162 Reference.reachabilityFence(min_final_cltv_expiry_delta);
1163 if (ret >= 0 && ret <= 4096) { return null; }
1164 Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ ret_hu_conv = Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ.constr_from_ptr(ret);
1165 if (this != null) { this.ptrs_to.add(min_value_msat); };
1166 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry_delta); };
1171 * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1172 * stored external to LDK.
1174 * A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
1175 * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1176 * the `min_value_msat` provided here, if one is provided.
1178 * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
1179 * note that LDK will not stop you from registering duplicate payment hashes for inbound
1182 * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1183 * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1184 * before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
1185 * sender \"proof-of-payment\" unless they have paid the required amount.
1187 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1188 * in excess of the current time. This should roughly match the expiry time set in the invoice.
1189 * After this many seconds, we will remove the inbound payment, resulting in any attempts to
1190 * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1191 * invoices when no timeout is set.
1193 * Note that we use block header time to time-out pending inbound payments (with some margin
1194 * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1195 * accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
1196 * If you need exact expiry semantics, you should enforce them upon receipt of
1197 * [`PaymentClaimable`].
1199 * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
1200 * set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
1202 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1203 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1207 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1208 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1210 * Errors if `min_value_msat` is greater than total bitcoin supply.
1212 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
1213 * on versions of LDK prior to 0.0.114.
1215 * [`create_inbound_payment`]: Self::create_inbound_payment
1216 * [`PaymentClaimable`]: events::Event::PaymentClaimable
1218 public Result_ThirtyTwoBytesNoneZ 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) {
1219 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);
1220 Reference.reachabilityFence(this);
1221 Reference.reachabilityFence(payment_hash);
1222 Reference.reachabilityFence(min_value_msat);
1223 Reference.reachabilityFence(invoice_expiry_delta_secs);
1224 Reference.reachabilityFence(min_final_cltv_expiry);
1225 if (ret >= 0 && ret <= 4096) { return null; }
1226 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
1227 if (this != null) { this.ptrs_to.add(min_value_msat); };
1228 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry); };
1233 * Gets an LDK-generated payment preimage from a payment hash and payment secret that were
1234 * previously returned from [`create_inbound_payment`].
1236 * [`create_inbound_payment`]: Self::create_inbound_payment
1238 public Result_ThirtyTwoBytesAPIErrorZ get_payment_preimage(byte[] payment_hash, byte[] payment_secret) {
1239 long ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
1240 Reference.reachabilityFence(this);
1241 Reference.reachabilityFence(payment_hash);
1242 Reference.reachabilityFence(payment_secret);
1243 if (ret >= 0 && ret <= 4096) { return null; }
1244 Result_ThirtyTwoBytesAPIErrorZ ret_hu_conv = Result_ThirtyTwoBytesAPIErrorZ.constr_from_ptr(ret);
1249 * Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
1250 * are used when constructing the phantom invoice's route hints.
1252 * [phantom node payments]: crate::sign::PhantomKeysManager
1254 public long get_phantom_scid() {
1255 long ret = bindings.ChannelManager_get_phantom_scid(this.ptr);
1256 Reference.reachabilityFence(this);
1261 * Gets route hints for use in receiving [phantom node payments].
1263 * [phantom node payments]: crate::sign::PhantomKeysManager
1265 public PhantomRouteHints get_phantom_route_hints() {
1266 long ret = bindings.ChannelManager_get_phantom_route_hints(this.ptr);
1267 Reference.reachabilityFence(this);
1268 if (ret >= 0 && ret <= 4096) { return null; }
1269 org.ldk.structs.PhantomRouteHints ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomRouteHints(null, ret); }
1270 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1275 * Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
1276 * used when constructing the route hints for HTLCs intended to be intercepted. See
1277 * [`ChannelManager::forward_intercepted_htlc`].
1279 * Note that this method is not guaranteed to return unique values, you may need to call it a few
1280 * times to get a unique scid.
1282 public long get_intercept_scid() {
1283 long ret = bindings.ChannelManager_get_intercept_scid(this.ptr);
1284 Reference.reachabilityFence(this);
1289 * Gets inflight HTLC information by processing pending outbound payments that are in
1290 * our channels. May be used during pathfinding to account for in-use channel liquidity.
1292 public InFlightHtlcs compute_inflight_htlcs() {
1293 long ret = bindings.ChannelManager_compute_inflight_htlcs(this.ptr);
1294 Reference.reachabilityFence(this);
1295 if (ret >= 0 && ret <= 4096) { return null; }
1296 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
1297 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1302 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1303 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1305 public MessageSendEventsProvider as_MessageSendEventsProvider() {
1306 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
1307 Reference.reachabilityFence(this);
1308 if (ret >= 0 && ret <= 4096) { return null; }
1309 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
1310 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1315 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
1316 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1318 public EventsProvider as_EventsProvider() {
1319 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
1320 Reference.reachabilityFence(this);
1321 if (ret >= 0 && ret <= 4096) { return null; }
1322 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
1323 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1328 * Constructs a new Listen which calls the relevant methods on this_arg.
1329 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1331 public Listen as_Listen() {
1332 long ret = bindings.ChannelManager_as_Listen(this.ptr);
1333 Reference.reachabilityFence(this);
1334 if (ret >= 0 && ret <= 4096) { return null; }
1335 Listen ret_hu_conv = new Listen(null, ret);
1336 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1341 * Constructs a new Confirm which calls the relevant methods on this_arg.
1342 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1344 public Confirm as_Confirm() {
1345 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
1346 Reference.reachabilityFence(this);
1347 if (ret >= 0 && ret <= 4096) { return null; }
1348 Confirm ret_hu_conv = new Confirm(null, ret);
1349 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1354 * Gets a [`Future`] that completes when this [`ChannelManager`] may need to be persisted or
1355 * may have events that need processing.
1357 * In order to check if this [`ChannelManager`] needs persisting, call
1358 * [`Self::get_and_clear_needs_persistence`].
1360 * Note that callbacks registered on the [`Future`] MUST NOT call back into this
1361 * [`ChannelManager`] and should instead register actions to be taken later.
1363 public Future get_event_or_persistence_needed_future() {
1364 long ret = bindings.ChannelManager_get_event_or_persistence_needed_future(this.ptr);
1365 Reference.reachabilityFence(this);
1366 if (ret >= 0 && ret <= 4096) { return null; }
1367 org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); }
1368 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1373 * Returns true if this [`ChannelManager`] needs to be persisted.
1375 public boolean get_and_clear_needs_persistence() {
1376 boolean ret = bindings.ChannelManager_get_and_clear_needs_persistence(this.ptr);
1377 Reference.reachabilityFence(this);
1382 * Gets the latest best block which was connected either via the [`chain::Listen`] or
1383 * [`chain::Confirm`] interfaces.
1385 public BestBlock current_best_block() {
1386 long ret = bindings.ChannelManager_current_best_block(this.ptr);
1387 Reference.reachabilityFence(this);
1388 if (ret >= 0 && ret <= 4096) { return null; }
1389 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
1390 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1395 * Fetches the set of [`NodeFeatures`] flags that are provided by or required by
1396 * [`ChannelManager`].
1398 public NodeFeatures node_features() {
1399 long ret = bindings.ChannelManager_node_features(this.ptr);
1400 Reference.reachabilityFence(this);
1401 if (ret >= 0 && ret <= 4096) { return null; }
1402 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
1403 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1408 * Fetches the set of [`ChannelFeatures`] flags that are provided by or required by
1409 * [`ChannelManager`].
1411 public ChannelFeatures channel_features() {
1412 long ret = bindings.ChannelManager_channel_features(this.ptr);
1413 Reference.reachabilityFence(this);
1414 if (ret >= 0 && ret <= 4096) { return null; }
1415 org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); }
1416 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1421 * Fetches the set of [`ChannelTypeFeatures`] flags that are provided by or required by
1422 * [`ChannelManager`].
1424 public ChannelTypeFeatures channel_type_features() {
1425 long ret = bindings.ChannelManager_channel_type_features(this.ptr);
1426 Reference.reachabilityFence(this);
1427 if (ret >= 0 && ret <= 4096) { return null; }
1428 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
1429 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1434 * Fetches the set of [`InitFeatures`] flags that are provided by or required by
1435 * [`ChannelManager`].
1437 public InitFeatures init_features() {
1438 long ret = bindings.ChannelManager_init_features(this.ptr);
1439 Reference.reachabilityFence(this);
1440 if (ret >= 0 && ret <= 4096) { return null; }
1441 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
1442 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1447 * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1448 * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1450 public ChannelMessageHandler as_ChannelMessageHandler() {
1451 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
1452 Reference.reachabilityFence(this);
1453 if (ret >= 0 && ret <= 4096) { return null; }
1454 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
1455 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1460 * Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
1461 * This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
1463 public OffersMessageHandler as_OffersMessageHandler() {
1464 long ret = bindings.ChannelManager_as_OffersMessageHandler(this.ptr);
1465 Reference.reachabilityFence(this);
1466 if (ret >= 0 && ret <= 4096) { return null; }
1467 OffersMessageHandler ret_hu_conv = new OffersMessageHandler(null, ret);
1468 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1473 * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1475 public byte[] write() {
1476 byte[] ret = bindings.ChannelManager_write(this.ptr);
1477 Reference.reachabilityFence(this);