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 write each monitor update out to disk before
25 * returning from [`chain::Watch::watch_channel`]/[`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 * [`ChannelMonitor`] 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 connected. You should get the best block tip before using the manager.
33 * See [`chain::Listen`] and [`chain::Confirm`] for more details.
35 * Note that `ChannelManager` is responsible for tracking liveness of its channels and generating
36 * [`ChannelUpdate`] messages informing peers that the channel is temporarily disabled. To avoid
37 * spam due to quick disconnection/reconnection, updates are not sent until the channel has been
38 * offline for a full minute. In order to track this, you must call
39 * [`timer_tick_occurred`] roughly once per minute, though it doesn't have to be perfect.
41 * To avoid trivial DoS issues, `ChannelManager` limits the number of inbound connections and
42 * inbound channels without confirmed funding transactions. This may result in nodes which we do
43 * not have a channel with being unable to connect to us or open new channels with us if we have
44 * many peers with unfunded channels.
46 * Because it is an indication of trust, inbound channels which we've accepted as 0conf are
47 * exempted from the count of unfunded channels. Similarly, outbound channels and connections are
48 * never limited. Please ensure you limit the count of such channels yourself.
50 * Rather than using a plain `ChannelManager`, it is preferable to use either a [`SimpleArcChannelManager`]
51 * a [`SimpleRefChannelManager`], for conciseness. See their documentation for more details, but
52 * essentially you should default to using a [`SimpleRefChannelManager`], and use a
53 * [`SimpleArcChannelManager`] when you require a `ChannelManager` with a static lifetime, such as when
54 * you're using lightning-net-tokio.
56 * [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
57 * [`funding_created`]: msgs::FundingCreated
58 * [`funding_transaction_generated`]: Self::funding_transaction_generated
59 * [`BlockHash`]: bitcoin::hash_types::BlockHash
60 * [`update_channel`]: chain::Watch::update_channel
61 * [`ChannelUpdate`]: msgs::ChannelUpdate
62 * [`timer_tick_occurred`]: Self::timer_tick_occurred
63 * [`read`]: ReadableArgs::read
65 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
66 public class ChannelManager extends CommonBase {
67 ChannelManager(Object _dummy, long ptr) { super(ptr); }
68 @Override @SuppressWarnings("deprecation")
69 protected void finalize() throws Throwable {
71 if (ptr != 0) { bindings.ChannelManager_free(ptr); }
75 * Constructs a new `ChannelManager` to hold several channels and route between them.
77 * The current time or latest block header time can be provided as the `current_timestamp`.
79 * This is the main \"logic hub\" for all channel-related actions, and implements
80 * [`ChannelMessageHandler`].
82 * Non-proportional fees are fixed according to our risk using the provided fee estimator.
84 * Users need to notify the new `ChannelManager` when a new block is connected or
85 * disconnected using its [`block_connected`] and [`block_disconnected`] methods, starting
86 * from after [`params.best_block.block_hash`]. See [`chain::Listen`] and [`chain::Confirm`] for
89 * [`block_connected`]: chain::Listen::block_connected
90 * [`block_disconnected`]: chain::Listen::block_disconnected
91 * [`params.best_block.block_hash`]: chain::BestBlock::block_hash
93 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) {
94 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);
95 Reference.reachabilityFence(fee_est);
96 Reference.reachabilityFence(chain_monitor);
97 Reference.reachabilityFence(tx_broadcaster);
98 Reference.reachabilityFence(router);
99 Reference.reachabilityFence(logger);
100 Reference.reachabilityFence(entropy_source);
101 Reference.reachabilityFence(node_signer);
102 Reference.reachabilityFence(signer_provider);
103 Reference.reachabilityFence(config);
104 Reference.reachabilityFence(params);
105 Reference.reachabilityFence(current_timestamp);
106 if (ret >= 0 && ret <= 4096) { return null; }
107 org.ldk.structs.ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManager(null, ret); }
108 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
109 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(fee_est); };
110 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(chain_monitor); };
111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(tx_broadcaster); };
112 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(router); };
113 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
115 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
116 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(signer_provider); };
117 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(config); };
118 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(params); };
123 * Gets the current configuration applied to all new channels.
125 public UserConfig get_current_default_configuration() {
126 long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
127 Reference.reachabilityFence(this);
128 if (ret >= 0 && ret <= 4096) { return null; }
129 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
130 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
135 * Creates a new outbound channel to the given remote node and with the given value.
137 * `user_channel_id` will be provided back as in
138 * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
139 * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
140 * randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
141 * is simply copied to events and otherwise ignored.
143 * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
144 * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
146 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be opened due to failing to
147 * generate a shutdown scriptpubkey or destination script set by
148 * [`SignerProvider::get_shutdown_scriptpubkey`] or [`SignerProvider::get_destination_script`].
150 * Note that we do not check if you are currently connected to the given peer. If no
151 * connection is available, the outbound `open_channel` message may fail to send, resulting in
152 * the channel eventually being silently forgotten (dropped on reload).
154 * Returns the new Channel's temporary `channel_id`. This ID will appear as
155 * [`Event::FundingGenerationReady::temporary_channel_id`] and in
156 * [`ChannelDetails::channel_id`] until after
157 * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
158 * one derived from the funding transaction's TXID. If the counterparty rejects the channel
159 * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
161 * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
162 * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
163 * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
165 * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
167 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) {
168 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);
169 Reference.reachabilityFence(this);
170 Reference.reachabilityFence(their_network_key);
171 Reference.reachabilityFence(channel_value_satoshis);
172 Reference.reachabilityFence(push_msat);
173 Reference.reachabilityFence(user_channel_id);
174 Reference.reachabilityFence(override_config);
175 if (ret >= 0 && ret <= 4096) { return null; }
176 Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
177 if (this != null) { this.ptrs_to.add(override_config); };
182 * Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for
185 public ChannelDetails[] list_channels() {
186 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
187 Reference.reachabilityFence(this);
188 int ret_conv_16_len = ret.length;
189 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
190 for (int q = 0; q < ret_conv_16_len; q++) {
191 long ret_conv_16 = ret[q];
192 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); }
193 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
194 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
196 return ret_conv_16_arr;
200 * Gets the list of usable channels, in random order. Useful as an argument to
201 * [`Router::find_route`] to ensure non-announced channels are used.
203 * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
204 * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
207 public ChannelDetails[] list_usable_channels() {
208 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
209 Reference.reachabilityFence(this);
210 int ret_conv_16_len = ret.length;
211 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
212 for (int q = 0; q < ret_conv_16_len; q++) {
213 long ret_conv_16 = ret[q];
214 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); }
215 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
216 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
218 return ret_conv_16_arr;
222 * Gets the list of channels we have with a given counterparty, in random order.
224 public ChannelDetails[] list_channels_with_counterparty(byte[] counterparty_node_id) {
225 long[] ret = bindings.ChannelManager_list_channels_with_counterparty(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33));
226 Reference.reachabilityFence(this);
227 Reference.reachabilityFence(counterparty_node_id);
228 int ret_conv_16_len = ret.length;
229 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
230 for (int q = 0; q < ret_conv_16_len; q++) {
231 long ret_conv_16 = ret[q];
232 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); }
233 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
234 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
236 return ret_conv_16_arr;
240 * Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
241 * successful path, or have unresolved HTLCs.
243 * This can be useful for payments that may have been prepared, but ultimately not sent, as a
244 * result of a crash. If such a payment exists, is not listed here, and an
245 * [`Event::PaymentSent`] has not been received, you may consider resending the payment.
247 * [`Event::PaymentSent`]: events::Event::PaymentSent
249 public RecentPaymentDetails[] list_recent_payments() {
250 long[] ret = bindings.ChannelManager_list_recent_payments(this.ptr);
251 Reference.reachabilityFence(this);
252 int ret_conv_22_len = ret.length;
253 RecentPaymentDetails[] ret_conv_22_arr = new RecentPaymentDetails[ret_conv_22_len];
254 for (int w = 0; w < ret_conv_22_len; w++) {
255 long ret_conv_22 = ret[w];
256 org.ldk.structs.RecentPaymentDetails ret_conv_22_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret_conv_22);
257 if (ret_conv_22_hu_conv != null) { ret_conv_22_hu_conv.ptrs_to.add(this); };
258 ret_conv_22_arr[w] = ret_conv_22_hu_conv;
260 return ret_conv_22_arr;
264 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
265 * will be accepted on the given channel, and after additional timeout/the closing of all
266 * pending HTLCs, the channel will be closed on chain.
268 * If we are the channel initiator, we will pay between our [`Background`] and
269 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
271 * If our counterparty is the channel initiator, we will require a channel closing
272 * transaction feerate of at least our [`Background`] feerate or the feerate which
273 * would appear on a force-closure transaction, whichever is lower. We will allow our
274 * counterparty to pay as much fee as they'd like, however.
276 * May generate a [`SendShutdown`] message event on success, which should be relayed.
278 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
279 * generate a shutdown scriptpubkey or destination script set by
280 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
283 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
284 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
285 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
286 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
288 public Result_NoneAPIErrorZ close_channel(byte[] channel_id, byte[] counterparty_node_id) {
289 long ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
290 Reference.reachabilityFence(this);
291 Reference.reachabilityFence(channel_id);
292 Reference.reachabilityFence(counterparty_node_id);
293 if (ret >= 0 && ret <= 4096) { return null; }
294 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
299 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
300 * will be accepted on the given channel, and after additional timeout/the closing of all
301 * pending HTLCs, the channel will be closed on chain.
303 * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
304 * the channel being closed or not:
305 * If we are the channel initiator, we will pay at least this feerate on the closing
306 * transaction. The upper-bound is set by
307 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
308 * estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
309 * If our counterparty is the channel initiator, we will refuse to accept a channel closure
310 * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
311 * will appear on a force-closure transaction, whichever is lower).
313 * The `shutdown_script` provided will be used as the `scriptPubKey` for the closing transaction.
314 * Will fail if a shutdown script has already been set for this channel by
315 * ['ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`]. The given shutdown script must
316 * also be compatible with our and the counterparty's features.
318 * May generate a [`SendShutdown`] message event on success, which should be relayed.
320 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
321 * generate a shutdown scriptpubkey or destination script set by
322 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
325 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
326 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
327 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
328 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
330 * Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None
332 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) {
333 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);
334 Reference.reachabilityFence(this);
335 Reference.reachabilityFence(channel_id);
336 Reference.reachabilityFence(counterparty_node_id);
337 Reference.reachabilityFence(target_feerate_sats_per_1000_weight);
338 Reference.reachabilityFence(shutdown_script);
339 if (ret >= 0 && ret <= 4096) { return null; }
340 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
341 if (this != null) { this.ptrs_to.add(target_feerate_sats_per_1000_weight); };
342 if (this != null) { this.ptrs_to.add(shutdown_script); };
347 * Force closes a channel, immediately broadcasting the latest local transaction(s) and
348 * rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
349 * the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
352 public Result_NoneAPIErrorZ force_close_broadcasting_latest_txn(byte[] channel_id, byte[] counterparty_node_id) {
353 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));
354 Reference.reachabilityFence(this);
355 Reference.reachabilityFence(channel_id);
356 Reference.reachabilityFence(counterparty_node_id);
357 if (ret >= 0 && ret <= 4096) { return null; }
358 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
363 * Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
364 * the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
365 * `counterparty_node_id` isn't the counterparty of the corresponding channel.
367 * You can always get the latest local transaction(s) to broadcast from
368 * [`ChannelMonitor::get_latest_holder_commitment_txn`].
370 public Result_NoneAPIErrorZ force_close_without_broadcasting_txn(byte[] channel_id, byte[] counterparty_node_id) {
371 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));
372 Reference.reachabilityFence(this);
373 Reference.reachabilityFence(channel_id);
374 Reference.reachabilityFence(counterparty_node_id);
375 if (ret >= 0 && ret <= 4096) { return null; }
376 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
381 * Force close all channels, immediately broadcasting the latest local commitment transaction
382 * for each to the chain and rejecting new HTLCs on each.
384 public void force_close_all_channels_broadcasting_latest_txn() {
385 bindings.ChannelManager_force_close_all_channels_broadcasting_latest_txn(this.ptr);
386 Reference.reachabilityFence(this);
390 * Force close all channels rejecting new HTLCs on each but without broadcasting the latest
391 * local transaction(s).
393 public void force_close_all_channels_without_broadcasting_txn() {
394 bindings.ChannelManager_force_close_all_channels_without_broadcasting_txn(this.ptr);
395 Reference.reachabilityFence(this);
399 * Sends a payment along a given route.
401 * Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
402 * fields for more info.
404 * May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
405 * [`PeerManager::process_events`]).
407 * # Avoiding Duplicate Payments
409 * If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
410 * method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
411 * is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
412 * [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
413 * second payment with the same [`PaymentId`].
415 * Thus, in order to ensure duplicate payments are not sent, you should implement your own
416 * tracking of payments, including state to indicate once a payment has completed. Because you
417 * should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
418 * consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
419 * [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
421 * Additionally, in the scenario where we begin the process of sending a payment, but crash
422 * before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
423 * using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
424 * [`ChannelManager::list_recent_payments`] for more information.
426 * # Possible Error States on [`PaymentSendFailure`]
428 * Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
429 * each entry matching the corresponding-index entry in the route paths, see
430 * [`PaymentSendFailure`] for more info.
432 * In general, a path may raise:
433 * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
434 * node public key) is specified.
435 * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
436 * (including due to previous monitor update failure or new permanent monitor update
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 retries 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.
491 * If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
492 * as there are no remaining pending HTLCs for this payment.
494 * Note that calling this method does *not* prevent a payment from succeeding. You must still
495 * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
496 * determine the ultimate status of a payment.
498 * If an [`Event::PaymentFailed`] event is generated and we restart without this
499 * [`ChannelManager`] having been persisted, another [`Event::PaymentFailed`] may be generated.
501 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
502 * [`Event::PaymentSent`]: events::Event::PaymentSent
504 public void abandon_payment(byte[] payment_id) {
505 bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
506 Reference.reachabilityFence(this);
507 Reference.reachabilityFence(payment_id);
511 * Send a spontaneous payment, which is a payment that does not require the recipient to have
512 * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
513 * the preimage, it must be a cryptographically secure random value that no intermediate node
514 * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
515 * never reach the recipient.
517 * See [`send_payment`] documentation for more details on the return value of this function
518 * and idempotency guarantees provided by the [`PaymentId`] key.
520 * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
521 * [`send_payment`] for more information about the risks of duplicate preimage usage.
523 * [`send_payment`]: Self::send_payment
525 public Result_PaymentHashPaymentSendFailureZ send_spontaneous_payment(org.ldk.structs.Route route, org.ldk.structs.Option_PaymentPreimageZ payment_preimage, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id) {
526 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));
527 Reference.reachabilityFence(this);
528 Reference.reachabilityFence(route);
529 Reference.reachabilityFence(payment_preimage);
530 Reference.reachabilityFence(recipient_onion);
531 Reference.reachabilityFence(payment_id);
532 if (ret >= 0 && ret <= 4096) { return null; }
533 Result_PaymentHashPaymentSendFailureZ ret_hu_conv = Result_PaymentHashPaymentSendFailureZ.constr_from_ptr(ret);
534 if (this != null) { this.ptrs_to.add(route); };
535 if (this != null) { this.ptrs_to.add(payment_preimage); };
536 if (this != null) { this.ptrs_to.add(recipient_onion); };
541 * Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
542 * based on `route_params` and retry failed payment paths based on `retry_strategy`.
544 * See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
547 * [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
549 public Result_PaymentHashRetryableSendFailureZ send_spontaneous_payment_with_retry(org.ldk.structs.Option_PaymentPreimageZ payment_preimage, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id, org.ldk.structs.RouteParameters route_params, org.ldk.structs.Retry retry_strategy) {
550 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);
551 Reference.reachabilityFence(this);
552 Reference.reachabilityFence(payment_preimage);
553 Reference.reachabilityFence(recipient_onion);
554 Reference.reachabilityFence(payment_id);
555 Reference.reachabilityFence(route_params);
556 Reference.reachabilityFence(retry_strategy);
557 if (ret >= 0 && ret <= 4096) { return null; }
558 Result_PaymentHashRetryableSendFailureZ ret_hu_conv = Result_PaymentHashRetryableSendFailureZ.constr_from_ptr(ret);
559 if (this != null) { this.ptrs_to.add(payment_preimage); };
560 if (this != null) { this.ptrs_to.add(recipient_onion); };
561 if (this != null) { this.ptrs_to.add(route_params); };
562 if (this != null) { this.ptrs_to.add(retry_strategy); };
567 * Send a payment that is probing the given route for liquidity. We calculate the
568 * [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
569 * us to easily discern them from real payments.
571 public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_probe(org.ldk.structs.Path path) {
572 long ret = bindings.ChannelManager_send_probe(this.ptr, path == null ? 0 : path.ptr);
573 Reference.reachabilityFence(this);
574 Reference.reachabilityFence(path);
575 if (ret >= 0 && ret <= 4096) { return null; }
576 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
577 if (this != null) { this.ptrs_to.add(path); };
582 * Call this upon creation of a funding transaction for the given channel.
584 * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
585 * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
587 * Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
588 * across the p2p network.
590 * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
591 * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
593 * May panic if the output found in the funding transaction is duplicative with some other
594 * channel (note that this should be trivially prevented by using unique funding transaction
597 * Do NOT broadcast the funding transaction yourself. When we have safely received our
598 * counterparty's signature the funding transaction will automatically be broadcast via the
599 * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
601 * Note that this includes RBF or similar transaction replacement strategies - lightning does
602 * not currently support replacing a funding transaction on an existing channel. Instead,
603 * create a new channel with a conflicting funding transaction.
605 * Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
606 * the wallet software generating the funding transaction to apply anti-fee sniping as
607 * implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
610 * [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
611 * [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
613 public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] counterparty_node_id, byte[] funding_transaction) {
614 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);
615 Reference.reachabilityFence(this);
616 Reference.reachabilityFence(temporary_channel_id);
617 Reference.reachabilityFence(counterparty_node_id);
618 Reference.reachabilityFence(funding_transaction);
619 if (ret >= 0 && ret <= 4096) { return null; }
620 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
625 * Atomically applies partial updates to the [`ChannelConfig`] of the given channels.
627 * Once the updates are applied, each eligible channel (advertised with a known short channel
628 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
629 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
630 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
632 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
633 * `counterparty_node_id` is provided.
635 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
636 * below [`MIN_CLTV_EXPIRY_DELTA`].
638 * If an error is returned, none of the updates should be considered applied.
640 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
641 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
642 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
643 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
644 * [`ChannelUpdate`]: msgs::ChannelUpdate
645 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
646 * [`APIMisuseError`]: APIError::APIMisuseError
648 public Result_NoneAPIErrorZ update_partial_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfigUpdate config_update) {
649 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);
650 Reference.reachabilityFence(this);
651 Reference.reachabilityFence(counterparty_node_id);
652 Reference.reachabilityFence(channel_ids);
653 Reference.reachabilityFence(config_update);
654 if (ret >= 0 && ret <= 4096) { return null; }
655 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
656 if (this != null) { this.ptrs_to.add(config_update); };
661 * Atomically updates the [`ChannelConfig`] for the given channels.
663 * Once the updates are applied, each eligible channel (advertised with a known short channel
664 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
665 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
666 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
668 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
669 * `counterparty_node_id` is provided.
671 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
672 * below [`MIN_CLTV_EXPIRY_DELTA`].
674 * If an error is returned, none of the updates should be considered applied.
676 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
677 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
678 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
679 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
680 * [`ChannelUpdate`]: msgs::ChannelUpdate
681 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
682 * [`APIMisuseError`]: APIError::APIMisuseError
684 public Result_NoneAPIErrorZ update_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfig config) {
685 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);
686 Reference.reachabilityFence(this);
687 Reference.reachabilityFence(counterparty_node_id);
688 Reference.reachabilityFence(channel_ids);
689 Reference.reachabilityFence(config);
690 if (ret >= 0 && ret <= 4096) { return null; }
691 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
692 if (this != null) { this.ptrs_to.add(config); };
697 * Attempts to forward an intercepted HTLC over the provided channel id and with the provided
698 * amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
700 * Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
701 * channel to a receiving node if the node lacks sufficient inbound liquidity.
703 * To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
704 * [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
705 * receiver's invoice route hints. These route hints will signal to LDK to generate an
706 * [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
707 * [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
709 * Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
710 * you from forwarding more than you received. See
711 * [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
714 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
717 * [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
718 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
719 * [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
721 public Result_NoneAPIErrorZ forward_intercepted_htlc(byte[] intercept_id, byte[] next_hop_channel_id, byte[] next_node_id, long amt_to_forward_msat) {
722 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);
723 Reference.reachabilityFence(this);
724 Reference.reachabilityFence(intercept_id);
725 Reference.reachabilityFence(next_hop_channel_id);
726 Reference.reachabilityFence(next_node_id);
727 Reference.reachabilityFence(amt_to_forward_msat);
728 if (ret >= 0 && ret <= 4096) { return null; }
729 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
734 * Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
735 * an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
737 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
740 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
742 public Result_NoneAPIErrorZ fail_intercepted_htlc(byte[] intercept_id) {
743 long ret = bindings.ChannelManager_fail_intercepted_htlc(this.ptr, InternalUtils.check_arr_len(intercept_id, 32));
744 Reference.reachabilityFence(this);
745 Reference.reachabilityFence(intercept_id);
746 if (ret >= 0 && ret <= 4096) { return null; }
747 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
752 * Processes HTLCs which are pending waiting on random forward delay.
754 * Should only really ever be called in response to a PendingHTLCsForwardable event.
755 * Will likely generate further events.
757 public void process_pending_htlc_forwards() {
758 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
759 Reference.reachabilityFence(this);
763 * Performs actions which should happen on startup and roughly once per minute thereafter.
765 * This currently includes:
766 * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
767 * Broadcasting [`ChannelUpdate`] messages if we've been disconnected from our peer for more
768 * than a minute, informing the network that they should no longer attempt to route over
770 * Expiring a channel's previous [`ChannelConfig`] if necessary to only allow forwarding HTLCs
771 * with the current [`ChannelConfig`].
772 * Removing peers which have disconnected but and no longer have any channels.
773 * Force-closing and removing channels which have not completed establishment in a timely manner.
775 * Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
778 * [`ChannelUpdate`]: msgs::ChannelUpdate
779 * [`ChannelConfig`]: crate::util::config::ChannelConfig
781 public void timer_tick_occurred() {
782 bindings.ChannelManager_timer_tick_occurred(this.ptr);
783 Reference.reachabilityFence(this);
787 * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
788 * after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
789 * along the path (including in our own channel on which we received it).
791 * Note that in some cases around unclean shutdown, it is possible the payment may have
792 * already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
793 * second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
794 * may have already been failed automatically by LDK if it was nearing its expiration time.
796 * While LDK will never claim a payment automatically on your behalf (i.e. without you calling
797 * [`ChannelManager::claim_funds`]), you should still monitor for
798 * [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
799 * startup during which time claims that were in-progress at shutdown may be replayed.
801 public void fail_htlc_backwards(byte[] payment_hash) {
802 bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
803 Reference.reachabilityFence(this);
804 Reference.reachabilityFence(payment_hash);
808 * This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
809 * reason for the failure.
811 * See [`FailureCode`] for valid failure codes.
813 public void fail_htlc_backwards_with_reason(byte[] payment_hash, org.ldk.enums.FailureCode failure_code) {
814 bindings.ChannelManager_fail_htlc_backwards_with_reason(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), failure_code);
815 Reference.reachabilityFence(this);
816 Reference.reachabilityFence(payment_hash);
817 Reference.reachabilityFence(failure_code);
821 * Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
822 * [`MessageSendEvent`]s needed to claim the payment.
824 * This method is guaranteed to ensure the payment has been claimed but only if the current
825 * height is strictly below [`Event::PaymentClaimable::claim_deadline`]. To avoid race
826 * conditions, you should wait for an [`Event::PaymentClaimed`] before considering the payment
827 * successful. It will generally be available in the next [`process_pending_events`] call.
829 * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
830 * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
831 * event matches your expectation. If you fail to do so and call this method, you may provide
832 * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
834 * [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
835 * [`Event::PaymentClaimable::claim_deadline`]: crate::events::Event::PaymentClaimable::claim_deadline
836 * [`Event::PaymentClaimed`]: crate::events::Event::PaymentClaimed
837 * [`process_pending_events`]: EventsProvider::process_pending_events
838 * [`create_inbound_payment`]: Self::create_inbound_payment
839 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
841 public void claim_funds(byte[] payment_preimage) {
842 bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
843 Reference.reachabilityFence(this);
844 Reference.reachabilityFence(payment_preimage);
848 * Gets the node_id held by this ChannelManager
850 public byte[] get_our_node_id() {
851 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
852 Reference.reachabilityFence(this);
857 * Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
859 * The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
860 * and the `counterparty_node_id` parameter is the id of the peer which has requested to open
863 * The `user_channel_id` parameter will be provided back in
864 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
865 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
867 * Note that this method will return an error and reject the channel, if it requires support
868 * for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
869 * used to accept such channels.
871 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
872 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
874 public Result_NoneAPIErrorZ accept_inbound_channel(byte[] temporary_channel_id, byte[] counterparty_node_id, org.ldk.util.UInt128 user_channel_id) {
875 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());
876 Reference.reachabilityFence(this);
877 Reference.reachabilityFence(temporary_channel_id);
878 Reference.reachabilityFence(counterparty_node_id);
879 Reference.reachabilityFence(user_channel_id);
880 if (ret >= 0 && ret <= 4096) { return null; }
881 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
886 * Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
887 * it as confirmed immediately.
889 * The `user_channel_id` parameter will be provided back in
890 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
891 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
893 * Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
894 * and (if the counterparty agrees), enables forwarding of payments immediately.
896 * This fully trusts that the counterparty has honestly and correctly constructed the funding
897 * transaction and blindly assumes that it will eventually confirm.
899 * If it does not confirm before we decide to close the channel, or if the funding transaction
900 * does not pay to the correct script the correct amount, *you will lose funds*.
902 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
903 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
905 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) {
906 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());
907 Reference.reachabilityFence(this);
908 Reference.reachabilityFence(temporary_channel_id);
909 Reference.reachabilityFence(counterparty_node_id);
910 Reference.reachabilityFence(user_channel_id);
911 if (ret >= 0 && ret <= 4096) { return null; }
912 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
917 * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
920 * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
921 * [`PaymentHash`] and [`PaymentPreimage`] for you.
923 * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`], which
924 * will have the [`PaymentClaimable::purpose`] be [`PaymentPurpose::InvoicePayment`] with
925 * its [`PaymentPurpose::InvoicePayment::payment_preimage`] field filled in. That should then be
926 * passed directly to [`claim_funds`].
928 * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
930 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
931 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
935 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
936 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
938 * Errors if `min_value_msat` is greater than total bitcoin supply.
940 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
941 * on versions of LDK prior to 0.0.114.
943 * [`claim_funds`]: Self::claim_funds
944 * [`PaymentClaimable`]: events::Event::PaymentClaimable
945 * [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
946 * [`PaymentPurpose::InvoicePayment`]: events::PaymentPurpose::InvoicePayment
947 * [`PaymentPurpose::InvoicePayment::payment_preimage`]: events::PaymentPurpose::InvoicePayment::payment_preimage
948 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
950 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) {
951 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
952 Reference.reachabilityFence(this);
953 Reference.reachabilityFence(min_value_msat);
954 Reference.reachabilityFence(invoice_expiry_delta_secs);
955 Reference.reachabilityFence(min_final_cltv_expiry_delta);
956 if (ret >= 0 && ret <= 4096) { return null; }
957 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
958 if (this != null) { this.ptrs_to.add(min_value_msat); };
959 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry_delta); };
964 * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
965 * stored external to LDK.
967 * A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
968 * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
969 * the `min_value_msat` provided here, if one is provided.
971 * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
972 * note that LDK will not stop you from registering duplicate payment hashes for inbound
975 * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
976 * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
977 * before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
978 * sender \"proof-of-payment\" unless they have paid the required amount.
980 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
981 * in excess of the current time. This should roughly match the expiry time set in the invoice.
982 * After this many seconds, we will remove the inbound payment, resulting in any attempts to
983 * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
984 * invoices when no timeout is set.
986 * Note that we use block header time to time-out pending inbound payments (with some margin
987 * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
988 * accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
989 * If you need exact expiry semantics, you should enforce them upon receipt of
990 * [`PaymentClaimable`].
992 * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
993 * set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
995 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
996 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1000 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1001 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1003 * Errors if `min_value_msat` is greater than total bitcoin supply.
1005 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
1006 * on versions of LDK prior to 0.0.114.
1008 * [`create_inbound_payment`]: Self::create_inbound_payment
1009 * [`PaymentClaimable`]: events::Event::PaymentClaimable
1011 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) {
1012 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);
1013 Reference.reachabilityFence(this);
1014 Reference.reachabilityFence(payment_hash);
1015 Reference.reachabilityFence(min_value_msat);
1016 Reference.reachabilityFence(invoice_expiry_delta_secs);
1017 Reference.reachabilityFence(min_final_cltv_expiry);
1018 if (ret >= 0 && ret <= 4096) { return null; }
1019 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
1020 if (this != null) { this.ptrs_to.add(min_value_msat); };
1021 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry); };
1026 * Gets an LDK-generated payment preimage from a payment hash and payment secret that were
1027 * previously returned from [`create_inbound_payment`].
1029 * [`create_inbound_payment`]: Self::create_inbound_payment
1031 public Result_PaymentPreimageAPIErrorZ get_payment_preimage(byte[] payment_hash, byte[] payment_secret) {
1032 long ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
1033 Reference.reachabilityFence(this);
1034 Reference.reachabilityFence(payment_hash);
1035 Reference.reachabilityFence(payment_secret);
1036 if (ret >= 0 && ret <= 4096) { return null; }
1037 Result_PaymentPreimageAPIErrorZ ret_hu_conv = Result_PaymentPreimageAPIErrorZ.constr_from_ptr(ret);
1042 * Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
1043 * are used when constructing the phantom invoice's route hints.
1045 * [phantom node payments]: crate::sign::PhantomKeysManager
1047 public long get_phantom_scid() {
1048 long ret = bindings.ChannelManager_get_phantom_scid(this.ptr);
1049 Reference.reachabilityFence(this);
1054 * Gets route hints for use in receiving [phantom node payments].
1056 * [phantom node payments]: crate::sign::PhantomKeysManager
1058 public PhantomRouteHints get_phantom_route_hints() {
1059 long ret = bindings.ChannelManager_get_phantom_route_hints(this.ptr);
1060 Reference.reachabilityFence(this);
1061 if (ret >= 0 && ret <= 4096) { return null; }
1062 org.ldk.structs.PhantomRouteHints ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomRouteHints(null, ret); }
1063 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1068 * Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
1069 * used when constructing the route hints for HTLCs intended to be intercepted. See
1070 * [`ChannelManager::forward_intercepted_htlc`].
1072 * Note that this method is not guaranteed to return unique values, you may need to call it a few
1073 * times to get a unique scid.
1075 public long get_intercept_scid() {
1076 long ret = bindings.ChannelManager_get_intercept_scid(this.ptr);
1077 Reference.reachabilityFence(this);
1082 * Gets inflight HTLC information by processing pending outbound payments that are in
1083 * our channels. May be used during pathfinding to account for in-use channel liquidity.
1085 public InFlightHtlcs compute_inflight_htlcs() {
1086 long ret = bindings.ChannelManager_compute_inflight_htlcs(this.ptr);
1087 Reference.reachabilityFence(this);
1088 if (ret >= 0 && ret <= 4096) { return null; }
1089 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
1090 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1095 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1096 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1098 public MessageSendEventsProvider as_MessageSendEventsProvider() {
1099 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
1100 Reference.reachabilityFence(this);
1101 if (ret >= 0 && ret <= 4096) { return null; }
1102 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
1103 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1108 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
1109 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1111 public EventsProvider as_EventsProvider() {
1112 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
1113 Reference.reachabilityFence(this);
1114 if (ret >= 0 && ret <= 4096) { return null; }
1115 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
1116 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1121 * Constructs a new Listen which calls the relevant methods on this_arg.
1122 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1124 public Listen as_Listen() {
1125 long ret = bindings.ChannelManager_as_Listen(this.ptr);
1126 Reference.reachabilityFence(this);
1127 if (ret >= 0 && ret <= 4096) { return null; }
1128 Listen ret_hu_conv = new Listen(null, ret);
1129 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1134 * Constructs a new Confirm which calls the relevant methods on this_arg.
1135 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1137 public Confirm as_Confirm() {
1138 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
1139 Reference.reachabilityFence(this);
1140 if (ret >= 0 && ret <= 4096) { return null; }
1141 Confirm ret_hu_conv = new Confirm(null, ret);
1142 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1147 * Gets a [`Future`] that completes when this [`ChannelManager`] needs to be persisted.
1149 * Note that callbacks registered on the [`Future`] MUST NOT call back into this
1150 * [`ChannelManager`] and should instead register actions to be taken later.
1152 public Future get_persistable_update_future() {
1153 long ret = bindings.ChannelManager_get_persistable_update_future(this.ptr);
1154 Reference.reachabilityFence(this);
1155 if (ret >= 0 && ret <= 4096) { return null; }
1156 org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); }
1157 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1162 * Gets the latest best block which was connected either via the [`chain::Listen`] or
1163 * [`chain::Confirm`] interfaces.
1165 public BestBlock current_best_block() {
1166 long ret = bindings.ChannelManager_current_best_block(this.ptr);
1167 Reference.reachabilityFence(this);
1168 if (ret >= 0 && ret <= 4096) { return null; }
1169 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
1170 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1175 * Fetches the set of [`NodeFeatures`] flags which are provided by or required by
1176 * [`ChannelManager`].
1178 public NodeFeatures node_features() {
1179 long ret = bindings.ChannelManager_node_features(this.ptr);
1180 Reference.reachabilityFence(this);
1181 if (ret >= 0 && ret <= 4096) { return null; }
1182 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
1183 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1188 * Fetches the set of [`ChannelFeatures`] flags which are provided by or required by
1189 * [`ChannelManager`].
1191 public ChannelFeatures channel_features() {
1192 long ret = bindings.ChannelManager_channel_features(this.ptr);
1193 Reference.reachabilityFence(this);
1194 if (ret >= 0 && ret <= 4096) { return null; }
1195 org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); }
1196 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1201 * Fetches the set of [`ChannelTypeFeatures`] flags which are provided by or required by
1202 * [`ChannelManager`].
1204 public ChannelTypeFeatures channel_type_features() {
1205 long ret = bindings.ChannelManager_channel_type_features(this.ptr);
1206 Reference.reachabilityFence(this);
1207 if (ret >= 0 && ret <= 4096) { return null; }
1208 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
1209 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1214 * Fetches the set of [`InitFeatures`] flags which are provided by or required by
1215 * [`ChannelManager`].
1217 public InitFeatures init_features() {
1218 long ret = bindings.ChannelManager_init_features(this.ptr);
1219 Reference.reachabilityFence(this);
1220 if (ret >= 0 && ret <= 4096) { return null; }
1221 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
1222 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1227 * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1228 * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1230 public ChannelMessageHandler as_ChannelMessageHandler() {
1231 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
1232 Reference.reachabilityFence(this);
1233 if (ret >= 0 && ret <= 4096) { return null; }
1234 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
1235 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1240 * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1242 public byte[] write() {
1243 byte[] ret = bindings.ChannelManager_write(this.ptr);
1244 Reference.reachabilityFence(this);