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 * If `temporary_channel_id` is specified, it will be used as the temporary channel ID of the
157 * channel. Otherwise, a random one will be generated for you.
159 * Returns the new Channel's temporary `channel_id`. This ID will appear as
160 * [`Event::FundingGenerationReady::temporary_channel_id`] and in
161 * [`ChannelDetails::channel_id`] until after
162 * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
163 * one derived from the funding transaction's TXID. If the counterparty rejects the channel
164 * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
166 * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
167 * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
168 * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
170 * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
172 public Result_ThirtyTwoBytesAPIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, org.ldk.util.UInt128 user_channel_id, org.ldk.structs.Option_ThirtyTwoBytesZ temporary_channel_id, @Nullable org.ldk.structs.UserConfig override_config) {
173 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(), temporary_channel_id.ptr, override_config == null ? 0 : override_config.ptr);
174 Reference.reachabilityFence(this);
175 Reference.reachabilityFence(their_network_key);
176 Reference.reachabilityFence(channel_value_satoshis);
177 Reference.reachabilityFence(push_msat);
178 Reference.reachabilityFence(user_channel_id);
179 Reference.reachabilityFence(temporary_channel_id);
180 Reference.reachabilityFence(override_config);
181 if (ret >= 0 && ret <= 4096) { return null; }
182 Result_ThirtyTwoBytesAPIErrorZ ret_hu_conv = Result_ThirtyTwoBytesAPIErrorZ.constr_from_ptr(ret);
183 if (this != null) { this.ptrs_to.add(temporary_channel_id); };
184 if (this != null) { this.ptrs_to.add(override_config); };
189 * Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for
192 public ChannelDetails[] list_channels() {
193 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
194 Reference.reachabilityFence(this);
195 int ret_conv_16_len = ret.length;
196 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
197 for (int q = 0; q < ret_conv_16_len; q++) {
198 long ret_conv_16 = ret[q];
199 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); }
200 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
201 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
203 return ret_conv_16_arr;
207 * Gets the list of usable channels, in random order. Useful as an argument to
208 * [`Router::find_route`] to ensure non-announced channels are used.
210 * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
211 * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
214 public ChannelDetails[] list_usable_channels() {
215 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
216 Reference.reachabilityFence(this);
217 int ret_conv_16_len = ret.length;
218 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
219 for (int q = 0; q < ret_conv_16_len; q++) {
220 long ret_conv_16 = ret[q];
221 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); }
222 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
223 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
225 return ret_conv_16_arr;
229 * Gets the list of channels we have with a given counterparty, in random order.
231 public ChannelDetails[] list_channels_with_counterparty(byte[] counterparty_node_id) {
232 long[] ret = bindings.ChannelManager_list_channels_with_counterparty(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33));
233 Reference.reachabilityFence(this);
234 Reference.reachabilityFence(counterparty_node_id);
235 int ret_conv_16_len = ret.length;
236 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
237 for (int q = 0; q < ret_conv_16_len; q++) {
238 long ret_conv_16 = ret[q];
239 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); }
240 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.add(this); };
241 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
243 return ret_conv_16_arr;
247 * Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
248 * successful path, or have unresolved HTLCs.
250 * This can be useful for payments that may have been prepared, but ultimately not sent, as a
251 * result of a crash. If such a payment exists, is not listed here, and an
252 * [`Event::PaymentSent`] has not been received, you may consider resending the payment.
254 * [`Event::PaymentSent`]: events::Event::PaymentSent
256 public RecentPaymentDetails[] list_recent_payments() {
257 long[] ret = bindings.ChannelManager_list_recent_payments(this.ptr);
258 Reference.reachabilityFence(this);
259 int ret_conv_22_len = ret.length;
260 RecentPaymentDetails[] ret_conv_22_arr = new RecentPaymentDetails[ret_conv_22_len];
261 for (int w = 0; w < ret_conv_22_len; w++) {
262 long ret_conv_22 = ret[w];
263 org.ldk.structs.RecentPaymentDetails ret_conv_22_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret_conv_22);
264 if (ret_conv_22_hu_conv != null) { ret_conv_22_hu_conv.ptrs_to.add(this); };
265 ret_conv_22_arr[w] = ret_conv_22_hu_conv;
267 return ret_conv_22_arr;
271 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
272 * will be accepted on the given channel, and after additional timeout/the closing of all
273 * pending HTLCs, the channel will be closed on chain.
275 * If we are the channel initiator, we will pay between our [`ChannelCloseMinimum`] and
276 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
278 * If our counterparty is the channel initiator, we will require a channel closing
279 * transaction feerate of at least our [`ChannelCloseMinimum`] feerate or the feerate which
280 * would appear on a force-closure transaction, whichever is lower. We will allow our
281 * counterparty to pay as much fee as they'd like, however.
283 * May generate a [`SendShutdown`] message event on success, which should be relayed.
285 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
286 * generate a shutdown scriptpubkey or destination script set by
287 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
290 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
291 * [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum
292 * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
293 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
295 public Result_NoneAPIErrorZ close_channel(byte[] channel_id, byte[] counterparty_node_id) {
296 long ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
297 Reference.reachabilityFence(this);
298 Reference.reachabilityFence(channel_id);
299 Reference.reachabilityFence(counterparty_node_id);
300 if (ret >= 0 && ret <= 4096) { return null; }
301 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
306 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
307 * will be accepted on the given channel, and after additional timeout/the closing of all
308 * pending HTLCs, the channel will be closed on chain.
310 * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
311 * the channel being closed or not:
312 * If we are the channel initiator, we will pay at least this feerate on the closing
313 * transaction. The upper-bound is set by
314 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`NonAnchorChannelFee`]
315 * fee estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
316 * If our counterparty is the channel initiator, we will refuse to accept a channel closure
317 * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
318 * will appear on a force-closure transaction, whichever is lower).
320 * The `shutdown_script` provided will be used as the `scriptPubKey` for the closing transaction.
321 * Will fail if a shutdown script has already been set for this channel by
322 * ['ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`]. The given shutdown script must
323 * also be compatible with our and the counterparty's features.
325 * May generate a [`SendShutdown`] message event on success, which should be relayed.
327 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
328 * generate a shutdown scriptpubkey or destination script set by
329 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
332 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
333 * [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee
334 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
336 * Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None
338 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) {
339 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);
340 Reference.reachabilityFence(this);
341 Reference.reachabilityFence(channel_id);
342 Reference.reachabilityFence(counterparty_node_id);
343 Reference.reachabilityFence(target_feerate_sats_per_1000_weight);
344 Reference.reachabilityFence(shutdown_script);
345 if (ret >= 0 && ret <= 4096) { return null; }
346 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
347 if (this != null) { this.ptrs_to.add(target_feerate_sats_per_1000_weight); };
348 if (this != null) { this.ptrs_to.add(shutdown_script); };
353 * Force closes a channel, immediately broadcasting the latest local transaction(s) and
354 * rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
355 * the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
358 public Result_NoneAPIErrorZ force_close_broadcasting_latest_txn(byte[] channel_id, byte[] counterparty_node_id) {
359 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));
360 Reference.reachabilityFence(this);
361 Reference.reachabilityFence(channel_id);
362 Reference.reachabilityFence(counterparty_node_id);
363 if (ret >= 0 && ret <= 4096) { return null; }
364 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
369 * Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
370 * the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
371 * `counterparty_node_id` isn't the counterparty of the corresponding channel.
373 * You can always get the latest local transaction(s) to broadcast from
374 * [`ChannelMonitor::get_latest_holder_commitment_txn`].
376 public Result_NoneAPIErrorZ force_close_without_broadcasting_txn(byte[] channel_id, byte[] counterparty_node_id) {
377 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));
378 Reference.reachabilityFence(this);
379 Reference.reachabilityFence(channel_id);
380 Reference.reachabilityFence(counterparty_node_id);
381 if (ret >= 0 && ret <= 4096) { return null; }
382 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
387 * Force close all channels, immediately broadcasting the latest local commitment transaction
388 * for each to the chain and rejecting new HTLCs on each.
390 public void force_close_all_channels_broadcasting_latest_txn() {
391 bindings.ChannelManager_force_close_all_channels_broadcasting_latest_txn(this.ptr);
392 Reference.reachabilityFence(this);
396 * Force close all channels rejecting new HTLCs on each but without broadcasting the latest
397 * local transaction(s).
399 public void force_close_all_channels_without_broadcasting_txn() {
400 bindings.ChannelManager_force_close_all_channels_without_broadcasting_txn(this.ptr);
401 Reference.reachabilityFence(this);
405 * Sends a payment along a given route.
407 * Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
408 * fields for more info.
410 * May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
411 * [`PeerManager::process_events`]).
413 * # Avoiding Duplicate Payments
415 * If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
416 * method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
417 * is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
418 * [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
419 * second payment with the same [`PaymentId`].
421 * Thus, in order to ensure duplicate payments are not sent, you should implement your own
422 * tracking of payments, including state to indicate once a payment has completed. Because you
423 * should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
424 * consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
425 * [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
427 * Additionally, in the scenario where we begin the process of sending a payment, but crash
428 * before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
429 * using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
430 * [`ChannelManager::list_recent_payments`] for more information.
432 * # Possible Error States on [`PaymentSendFailure`]
434 * Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
435 * each entry matching the corresponding-index entry in the route paths, see
436 * [`PaymentSendFailure`] for more info.
438 * In general, a path may raise:
439 * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
440 * node public key) is specified.
441 * [`APIError::ChannelUnavailable`] if the next-hop channel is not available as it has been
442 * closed, doesn't exist, or the peer is currently disconnected.
443 * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
446 * Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
447 * irrevocably committed to on our end. In such a case, do NOT retry the payment with a
448 * different route unless you intend to pay twice!
450 * [`RouteHop`]: crate::routing::router::RouteHop
451 * [`Event::PaymentSent`]: events::Event::PaymentSent
452 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
453 * [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
454 * [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
455 * [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
457 public Result_NonePaymentSendFailureZ send_payment_with_route(org.ldk.structs.Route route, byte[] payment_hash, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id) {
458 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));
459 Reference.reachabilityFence(this);
460 Reference.reachabilityFence(route);
461 Reference.reachabilityFence(payment_hash);
462 Reference.reachabilityFence(recipient_onion);
463 Reference.reachabilityFence(payment_id);
464 if (ret >= 0 && ret <= 4096) { return null; }
465 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
466 if (this != null) { this.ptrs_to.add(route); };
467 if (this != null) { this.ptrs_to.add(recipient_onion); };
472 * Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
473 * `route_params` and retry failed payment paths based on `retry_strategy`.
475 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) {
476 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);
477 Reference.reachabilityFence(this);
478 Reference.reachabilityFence(payment_hash);
479 Reference.reachabilityFence(recipient_onion);
480 Reference.reachabilityFence(payment_id);
481 Reference.reachabilityFence(route_params);
482 Reference.reachabilityFence(retry_strategy);
483 if (ret >= 0 && ret <= 4096) { return null; }
484 Result_NoneRetryableSendFailureZ ret_hu_conv = Result_NoneRetryableSendFailureZ.constr_from_ptr(ret);
485 if (this != null) { this.ptrs_to.add(recipient_onion); };
486 if (this != null) { this.ptrs_to.add(route_params); };
487 if (this != null) { this.ptrs_to.add(retry_strategy); };
492 * Signals that no further attempts for the given payment should occur. Useful if you have a
493 * pending outbound payment with retries remaining, but wish to stop retrying the payment before
494 * retries are exhausted.
498 * If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
499 * as there are no remaining pending HTLCs for this payment.
501 * Note that calling this method does *not* prevent a payment from succeeding. You must still
502 * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
503 * determine the ultimate status of a payment.
505 * # Requested Invoices
507 * In the case of paying a [`Bolt12Invoice`] via [`ChannelManager::pay_for_offer`], abandoning
508 * the payment prior to receiving the invoice will result in an [`Event::InvoiceRequestFailed`]
509 * and prevent any attempts at paying it once received. The other events may only be generated
510 * once the invoice has been received.
514 * If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
515 * [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
516 * [`Event::InvoiceRequestFailed`].
518 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
520 public void abandon_payment(byte[] payment_id) {
521 bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
522 Reference.reachabilityFence(this);
523 Reference.reachabilityFence(payment_id);
527 * Send a spontaneous payment, which is a payment that does not require the recipient to have
528 * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
529 * the preimage, it must be a cryptographically secure random value that no intermediate node
530 * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
531 * never reach the recipient.
533 * See [`send_payment`] documentation for more details on the return value of this function
534 * and idempotency guarantees provided by the [`PaymentId`] key.
536 * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
537 * [`send_payment`] for more information about the risks of duplicate preimage usage.
539 * [`send_payment`]: Self::send_payment
541 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) {
542 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));
543 Reference.reachabilityFence(this);
544 Reference.reachabilityFence(route);
545 Reference.reachabilityFence(payment_preimage);
546 Reference.reachabilityFence(recipient_onion);
547 Reference.reachabilityFence(payment_id);
548 if (ret >= 0 && ret <= 4096) { return null; }
549 Result_ThirtyTwoBytesPaymentSendFailureZ ret_hu_conv = Result_ThirtyTwoBytesPaymentSendFailureZ.constr_from_ptr(ret);
550 if (this != null) { this.ptrs_to.add(route); };
551 if (this != null) { this.ptrs_to.add(payment_preimage); };
552 if (this != null) { this.ptrs_to.add(recipient_onion); };
557 * Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
558 * based on `route_params` and retry failed payment paths based on `retry_strategy`.
560 * See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
563 * [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
565 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) {
566 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);
567 Reference.reachabilityFence(this);
568 Reference.reachabilityFence(payment_preimage);
569 Reference.reachabilityFence(recipient_onion);
570 Reference.reachabilityFence(payment_id);
571 Reference.reachabilityFence(route_params);
572 Reference.reachabilityFence(retry_strategy);
573 if (ret >= 0 && ret <= 4096) { return null; }
574 Result_ThirtyTwoBytesRetryableSendFailureZ ret_hu_conv = Result_ThirtyTwoBytesRetryableSendFailureZ.constr_from_ptr(ret);
575 if (this != null) { this.ptrs_to.add(payment_preimage); };
576 if (this != null) { this.ptrs_to.add(recipient_onion); };
577 if (this != null) { this.ptrs_to.add(route_params); };
578 if (this != null) { this.ptrs_to.add(retry_strategy); };
583 * Send a payment that is probing the given route for liquidity. We calculate the
584 * [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
585 * us to easily discern them from real payments.
587 public Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ send_probe(org.ldk.structs.Path path) {
588 long ret = bindings.ChannelManager_send_probe(this.ptr, path == null ? 0 : path.ptr);
589 Reference.reachabilityFence(this);
590 Reference.reachabilityFence(path);
591 if (ret >= 0 && ret <= 4096) { return null; }
592 Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ.constr_from_ptr(ret);
593 if (this != null) { this.ptrs_to.add(path); };
598 * Sends payment probes over all paths of a route that would be used to pay the given
599 * amount to the given `node_id`.
601 * See [`ChannelManager::send_preflight_probes`] for more information.
603 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) {
604 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);
605 Reference.reachabilityFence(this);
606 Reference.reachabilityFence(node_id);
607 Reference.reachabilityFence(amount_msat);
608 Reference.reachabilityFence(final_cltv_expiry_delta);
609 Reference.reachabilityFence(liquidity_limit_multiplier);
610 if (ret >= 0 && ret <= 4096) { return null; }
611 Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ ret_hu_conv = Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ.constr_from_ptr(ret);
612 if (this != null) { this.ptrs_to.add(liquidity_limit_multiplier); };
617 * Sends payment probes over all paths of a route that would be used to pay a route found
618 * according to the given [`RouteParameters`].
620 * This may be used to send \"pre-flight\" probes, i.e., to train our scorer before conducting
621 * the actual payment. Note this is only useful if there likely is sufficient time for the
622 * probe to settle before sending out the actual payment, e.g., when waiting for user
623 * confirmation in a wallet UI.
625 * Otherwise, there is a chance the probe could take up some liquidity needed to complete the
626 * actual payment. Users should therefore be cautious and might avoid sending probes if
627 * liquidity is scarce and/or they don't expect the probe to return before they send the
628 * payment. To mitigate this issue, channels with available liquidity less than the required
629 * amount times the given `liquidity_limit_multiplier` won't be used to send pre-flight
630 * probes. If `None` is given as `liquidity_limit_multiplier`, it defaults to `3`.
632 public Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ send_preflight_probes(org.ldk.structs.RouteParameters route_params, org.ldk.structs.Option_u64Z liquidity_limit_multiplier) {
633 long ret = bindings.ChannelManager_send_preflight_probes(this.ptr, route_params == null ? 0 : route_params.ptr, liquidity_limit_multiplier.ptr);
634 Reference.reachabilityFence(this);
635 Reference.reachabilityFence(route_params);
636 Reference.reachabilityFence(liquidity_limit_multiplier);
637 if (ret >= 0 && ret <= 4096) { return null; }
638 Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ ret_hu_conv = Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ.constr_from_ptr(ret);
639 if (this != null) { this.ptrs_to.add(route_params); };
640 if (this != null) { this.ptrs_to.add(liquidity_limit_multiplier); };
645 * Call this upon creation of a funding transaction for the given channel.
647 * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
648 * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
650 * Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
651 * across the p2p network.
653 * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
654 * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
656 * May panic if the output found in the funding transaction is duplicative with some other
657 * channel (note that this should be trivially prevented by using unique funding transaction
660 * Do NOT broadcast the funding transaction yourself. When we have safely received our
661 * counterparty's signature the funding transaction will automatically be broadcast via the
662 * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
664 * Note that this includes RBF or similar transaction replacement strategies - lightning does
665 * not currently support replacing a funding transaction on an existing channel. Instead,
666 * create a new channel with a conflicting funding transaction.
668 * Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
669 * the wallet software generating the funding transaction to apply anti-fee sniping as
670 * implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
673 * [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
674 * [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
676 public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] counterparty_node_id, byte[] funding_transaction) {
677 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);
678 Reference.reachabilityFence(this);
679 Reference.reachabilityFence(temporary_channel_id);
680 Reference.reachabilityFence(counterparty_node_id);
681 Reference.reachabilityFence(funding_transaction);
682 if (ret >= 0 && ret <= 4096) { return null; }
683 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
688 * Call this upon creation of a batch funding transaction for the given channels.
690 * Return values are identical to [`Self::funding_transaction_generated`], respective to
691 * each individual channel and transaction output.
693 * Do NOT broadcast the funding transaction yourself. This batch funding transaction
694 * will only be broadcast when we have safely received and persisted the counterparty's
695 * signature for each channel.
697 * If there is an error, all channels in the batch are to be considered closed.
699 public Result_NoneAPIErrorZ batch_funding_transaction_generated(TwoTuple_ThirtyTwoBytesPublicKeyZ[] temporary_channels, byte[] funding_transaction) {
700 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);
701 Reference.reachabilityFence(this);
702 Reference.reachabilityFence(temporary_channels);
703 Reference.reachabilityFence(funding_transaction);
704 if (ret >= 0 && ret <= 4096) { return null; }
705 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
710 * Atomically applies partial updates to the [`ChannelConfig`] of the given channels.
712 * Once the updates are applied, each eligible channel (advertised with a known short channel
713 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
714 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
715 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
717 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
718 * `counterparty_node_id` is provided.
720 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
721 * below [`MIN_CLTV_EXPIRY_DELTA`].
723 * If an error is returned, none of the updates should be considered applied.
725 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
726 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
727 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
728 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
729 * [`ChannelUpdate`]: msgs::ChannelUpdate
730 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
731 * [`APIMisuseError`]: APIError::APIMisuseError
733 public Result_NoneAPIErrorZ update_partial_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfigUpdate config_update) {
734 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);
735 Reference.reachabilityFence(this);
736 Reference.reachabilityFence(counterparty_node_id);
737 Reference.reachabilityFence(channel_ids);
738 Reference.reachabilityFence(config_update);
739 if (ret >= 0 && ret <= 4096) { return null; }
740 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
741 if (this != null) { this.ptrs_to.add(config_update); };
746 * Atomically updates the [`ChannelConfig`] for the given channels.
748 * Once the updates are applied, each eligible channel (advertised with a known short channel
749 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
750 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
751 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
753 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
754 * `counterparty_node_id` is provided.
756 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
757 * below [`MIN_CLTV_EXPIRY_DELTA`].
759 * If an error is returned, none of the updates should be considered applied.
761 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
762 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
763 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
764 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
765 * [`ChannelUpdate`]: msgs::ChannelUpdate
766 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
767 * [`APIMisuseError`]: APIError::APIMisuseError
769 public Result_NoneAPIErrorZ update_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfig config) {
770 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);
771 Reference.reachabilityFence(this);
772 Reference.reachabilityFence(counterparty_node_id);
773 Reference.reachabilityFence(channel_ids);
774 Reference.reachabilityFence(config);
775 if (ret >= 0 && ret <= 4096) { return null; }
776 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
777 if (this != null) { this.ptrs_to.add(config); };
782 * Attempts to forward an intercepted HTLC over the provided channel id and with the provided
783 * amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
785 * Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
786 * channel to a receiving node if the node lacks sufficient inbound liquidity.
788 * To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
789 * [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
790 * receiver's invoice route hints. These route hints will signal to LDK to generate an
791 * [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
792 * [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
794 * Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
795 * you from forwarding more than you received. See
796 * [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
799 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
802 * [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
803 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
804 * [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
806 public Result_NoneAPIErrorZ forward_intercepted_htlc(byte[] intercept_id, byte[] next_hop_channel_id, byte[] next_node_id, long amt_to_forward_msat) {
807 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);
808 Reference.reachabilityFence(this);
809 Reference.reachabilityFence(intercept_id);
810 Reference.reachabilityFence(next_hop_channel_id);
811 Reference.reachabilityFence(next_node_id);
812 Reference.reachabilityFence(amt_to_forward_msat);
813 if (ret >= 0 && ret <= 4096) { return null; }
814 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
819 * Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
820 * an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
822 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
825 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
827 public Result_NoneAPIErrorZ fail_intercepted_htlc(byte[] intercept_id) {
828 long ret = bindings.ChannelManager_fail_intercepted_htlc(this.ptr, InternalUtils.check_arr_len(intercept_id, 32));
829 Reference.reachabilityFence(this);
830 Reference.reachabilityFence(intercept_id);
831 if (ret >= 0 && ret <= 4096) { return null; }
832 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
837 * Processes HTLCs which are pending waiting on random forward delay.
839 * Should only really ever be called in response to a PendingHTLCsForwardable event.
840 * Will likely generate further events.
842 public void process_pending_htlc_forwards() {
843 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
844 Reference.reachabilityFence(this);
848 * Performs actions which should happen on startup and roughly once per minute thereafter.
850 * This currently includes:
851 * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
852 * Broadcasting [`ChannelUpdate`] messages if we've been disconnected from our peer for more
853 * than a minute, informing the network that they should no longer attempt to route over
855 * Expiring a channel's previous [`ChannelConfig`] if necessary to only allow forwarding HTLCs
856 * with the current [`ChannelConfig`].
857 * Removing peers which have disconnected but and no longer have any channels.
858 * Force-closing and removing channels which have not completed establishment in a timely manner.
859 * Forgetting about stale outbound payments, either those that have already been fulfilled
860 * or those awaiting an invoice that hasn't been delivered in the necessary amount of time.
861 * The latter is determined using the system clock in `std` and the highest seen block time
862 * minus two hours in `no-std`.
864 * Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
867 * [`ChannelUpdate`]: msgs::ChannelUpdate
868 * [`ChannelConfig`]: crate::util::config::ChannelConfig
870 public void timer_tick_occurred() {
871 bindings.ChannelManager_timer_tick_occurred(this.ptr);
872 Reference.reachabilityFence(this);
876 * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
877 * after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
878 * along the path (including in our own channel on which we received it).
880 * Note that in some cases around unclean shutdown, it is possible the payment may have
881 * already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
882 * second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
883 * may have already been failed automatically by LDK if it was nearing its expiration time.
885 * While LDK will never claim a payment automatically on your behalf (i.e. without you calling
886 * [`ChannelManager::claim_funds`]), you should still monitor for
887 * [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
888 * startup during which time claims that were in-progress at shutdown may be replayed.
890 public void fail_htlc_backwards(byte[] payment_hash) {
891 bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
892 Reference.reachabilityFence(this);
893 Reference.reachabilityFence(payment_hash);
897 * This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
898 * reason for the failure.
900 * See [`FailureCode`] for valid failure codes.
902 public void fail_htlc_backwards_with_reason(byte[] payment_hash, org.ldk.structs.FailureCode failure_code) {
903 bindings.ChannelManager_fail_htlc_backwards_with_reason(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), failure_code.ptr);
904 Reference.reachabilityFence(this);
905 Reference.reachabilityFence(payment_hash);
906 Reference.reachabilityFence(failure_code);
907 if (this != null) { this.ptrs_to.add(failure_code); };
911 * Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
912 * [`MessageSendEvent`]s needed to claim the payment.
914 * This method is guaranteed to ensure the payment has been claimed but only if the current
915 * height is strictly below [`Event::PaymentClaimable::claim_deadline`]. To avoid race
916 * conditions, you should wait for an [`Event::PaymentClaimed`] before considering the payment
917 * successful. It will generally be available in the next [`process_pending_events`] call.
919 * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
920 * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
921 * event matches your expectation. If you fail to do so and call this method, you may provide
922 * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
924 * This function will fail the payment if it has custom TLVs with even type numbers, as we
925 * will assume they are unknown. If you intend to accept even custom TLVs, you should use
926 * [`claim_funds_with_known_custom_tlvs`].
928 * [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
929 * [`Event::PaymentClaimable::claim_deadline`]: crate::events::Event::PaymentClaimable::claim_deadline
930 * [`Event::PaymentClaimed`]: crate::events::Event::PaymentClaimed
931 * [`process_pending_events`]: EventsProvider::process_pending_events
932 * [`create_inbound_payment`]: Self::create_inbound_payment
933 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
934 * [`claim_funds_with_known_custom_tlvs`]: Self::claim_funds_with_known_custom_tlvs
936 public void claim_funds(byte[] payment_preimage) {
937 bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
938 Reference.reachabilityFence(this);
939 Reference.reachabilityFence(payment_preimage);
943 * This is a variant of [`claim_funds`] that allows accepting a payment with custom TLVs with
948 * You MUST check you've understood all even TLVs before using this to
949 * claim, otherwise you may unintentionally agree to some protocol you do not understand.
951 * [`claim_funds`]: Self::claim_funds
953 public void claim_funds_with_known_custom_tlvs(byte[] payment_preimage) {
954 bindings.ChannelManager_claim_funds_with_known_custom_tlvs(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
955 Reference.reachabilityFence(this);
956 Reference.reachabilityFence(payment_preimage);
960 * Gets the node_id held by this ChannelManager
962 public byte[] get_our_node_id() {
963 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
964 Reference.reachabilityFence(this);
969 * Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
971 * The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
972 * and the `counterparty_node_id` parameter is the id of the peer which has requested to open
975 * The `user_channel_id` parameter will be provided back in
976 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
977 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
979 * Note that this method will return an error and reject the channel, if it requires support
980 * for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
981 * used to accept such channels.
983 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
984 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
986 public Result_NoneAPIErrorZ accept_inbound_channel(byte[] temporary_channel_id, byte[] counterparty_node_id, org.ldk.util.UInt128 user_channel_id) {
987 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());
988 Reference.reachabilityFence(this);
989 Reference.reachabilityFence(temporary_channel_id);
990 Reference.reachabilityFence(counterparty_node_id);
991 Reference.reachabilityFence(user_channel_id);
992 if (ret >= 0 && ret <= 4096) { return null; }
993 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
998 * Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
999 * it as confirmed immediately.
1001 * The `user_channel_id` parameter will be provided back in
1002 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
1003 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
1005 * Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
1006 * and (if the counterparty agrees), enables forwarding of payments immediately.
1008 * This fully trusts that the counterparty has honestly and correctly constructed the funding
1009 * transaction and blindly assumes that it will eventually confirm.
1011 * If it does not confirm before we decide to close the channel, or if the funding transaction
1012 * does not pay to the correct script the correct amount, *you will lose funds*.
1014 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
1015 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
1017 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) {
1018 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());
1019 Reference.reachabilityFence(this);
1020 Reference.reachabilityFence(temporary_channel_id);
1021 Reference.reachabilityFence(counterparty_node_id);
1022 Reference.reachabilityFence(user_channel_id);
1023 if (ret >= 0 && ret <= 4096) { return null; }
1024 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
1029 * Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
1030 * enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
1031 * [`Bolt12Invoice`] once it is received.
1033 * Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
1034 * the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
1035 * The optional parameters are used in the builder, if `Some`:
1036 * - `quantity` for [`InvoiceRequest::quantity`] which must be set if
1037 * [`Offer::expects_quantity`] is `true`.
1038 * - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
1039 * - `payer_note` for [`InvoiceRequest::payer_note`].
1041 * If `max_total_routing_fee_msat` is not specified, The default from
1042 * [`RouteParameters::from_payment_params_and_value`] is applied.
1046 * The provided `payment_id` is used to ensure that only one invoice is paid for the request
1047 * when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
1050 * To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
1051 * invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
1052 * payment will fail with an [`Event::InvoiceRequestFailed`].
1056 * Uses a one-hop [`BlindedPath`] for the reply path with [`ChannelManager::get_our_node_id`]
1057 * as the introduction node and a derived payer id for payer privacy. As such, currently, the
1058 * node must be announced. Otherwise, there is no way to find a path to the introduction node
1059 * in order to send the [`Bolt12Invoice`].
1063 * Requires a direct connection to an introduction node in [`Offer::paths`] or to
1064 * [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding
1065 * [`Bolt12Invoice::payment_paths`].
1070 * - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
1071 * - the provided parameters are invalid for the offer,
1072 * - the parameterized [`Router`] is unable to create a blinded reply path for the invoice
1075 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
1076 * [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
1077 * [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
1078 * [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
1079 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
1080 * [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
1081 * [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
1083 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) {
1084 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);
1085 Reference.reachabilityFence(this);
1086 Reference.reachabilityFence(offer);
1087 Reference.reachabilityFence(quantity);
1088 Reference.reachabilityFence(amount_msats);
1089 Reference.reachabilityFence(payer_note);
1090 Reference.reachabilityFence(payment_id);
1091 Reference.reachabilityFence(retry_strategy);
1092 Reference.reachabilityFence(max_total_routing_fee_msat);
1093 if (ret >= 0 && ret <= 4096) { return null; }
1094 Result_NoneBolt12SemanticErrorZ ret_hu_conv = Result_NoneBolt12SemanticErrorZ.constr_from_ptr(ret);
1095 if (this != null) { this.ptrs_to.add(offer); };
1096 if (this != null) { this.ptrs_to.add(quantity); };
1097 if (this != null) { this.ptrs_to.add(amount_msats); };
1098 if (this != null) { this.ptrs_to.add(payer_note); };
1099 if (this != null) { this.ptrs_to.add(retry_strategy); };
1100 if (this != null) { this.ptrs_to.add(max_total_routing_fee_msat); };
1105 * Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
1108 * The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
1109 * [`BlindedPath`] containing the [`PaymentSecret`] needed to reconstruct the corresponding
1110 * [`PaymentPreimage`].
1114 * Requires a direct connection to an introduction node in [`Refund::paths`] or to
1115 * [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each
1116 * node meeting the aforementioned criteria, but there's no guarantee that they will be
1117 * received and no retries will be made.
1121 * Errors if the parameterized [`Router`] is unable to create a blinded payment path or reply
1122 * path for the invoice.
1124 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
1126 public Result_NoneBolt12SemanticErrorZ request_refund_payment(org.ldk.structs.Refund refund) {
1127 long ret = bindings.ChannelManager_request_refund_payment(this.ptr, refund == null ? 0 : refund.ptr);
1128 Reference.reachabilityFence(this);
1129 Reference.reachabilityFence(refund);
1130 if (ret >= 0 && ret <= 4096) { return null; }
1131 Result_NoneBolt12SemanticErrorZ ret_hu_conv = Result_NoneBolt12SemanticErrorZ.constr_from_ptr(ret);
1132 if (this != null) { this.ptrs_to.add(refund); };
1137 * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
1140 * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1141 * [`PaymentHash`] and [`PaymentPreimage`] for you.
1143 * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`], which
1144 * will have the [`PaymentClaimable::purpose`] be [`PaymentPurpose::InvoicePayment`] with
1145 * its [`PaymentPurpose::InvoicePayment::payment_preimage`] field filled in. That should then be
1146 * passed directly to [`claim_funds`].
1148 * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
1150 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1151 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1155 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1156 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1158 * Errors if `min_value_msat` is greater than total bitcoin supply.
1160 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
1161 * on versions of LDK prior to 0.0.114.
1163 * [`claim_funds`]: Self::claim_funds
1164 * [`PaymentClaimable`]: events::Event::PaymentClaimable
1165 * [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
1166 * [`PaymentPurpose::InvoicePayment`]: events::PaymentPurpose::InvoicePayment
1167 * [`PaymentPurpose::InvoicePayment::payment_preimage`]: events::PaymentPurpose::InvoicePayment::payment_preimage
1168 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1170 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) {
1171 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
1172 Reference.reachabilityFence(this);
1173 Reference.reachabilityFence(min_value_msat);
1174 Reference.reachabilityFence(invoice_expiry_delta_secs);
1175 Reference.reachabilityFence(min_final_cltv_expiry_delta);
1176 if (ret >= 0 && ret <= 4096) { return null; }
1177 Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ ret_hu_conv = Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ.constr_from_ptr(ret);
1178 if (this != null) { this.ptrs_to.add(min_value_msat); };
1179 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry_delta); };
1184 * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
1185 * stored external to LDK.
1187 * A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
1188 * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
1189 * the `min_value_msat` provided here, if one is provided.
1191 * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
1192 * note that LDK will not stop you from registering duplicate payment hashes for inbound
1195 * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
1196 * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
1197 * before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
1198 * sender \"proof-of-payment\" unless they have paid the required amount.
1200 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
1201 * in excess of the current time. This should roughly match the expiry time set in the invoice.
1202 * After this many seconds, we will remove the inbound payment, resulting in any attempts to
1203 * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
1204 * invoices when no timeout is set.
1206 * Note that we use block header time to time-out pending inbound payments (with some margin
1207 * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
1208 * accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
1209 * If you need exact expiry semantics, you should enforce them upon receipt of
1210 * [`PaymentClaimable`].
1212 * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
1213 * set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
1215 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1216 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1220 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
1221 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
1223 * Errors if `min_value_msat` is greater than total bitcoin supply.
1225 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
1226 * on versions of LDK prior to 0.0.114.
1228 * [`create_inbound_payment`]: Self::create_inbound_payment
1229 * [`PaymentClaimable`]: events::Event::PaymentClaimable
1231 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) {
1232 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);
1233 Reference.reachabilityFence(this);
1234 Reference.reachabilityFence(payment_hash);
1235 Reference.reachabilityFence(min_value_msat);
1236 Reference.reachabilityFence(invoice_expiry_delta_secs);
1237 Reference.reachabilityFence(min_final_cltv_expiry);
1238 if (ret >= 0 && ret <= 4096) { return null; }
1239 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
1240 if (this != null) { this.ptrs_to.add(min_value_msat); };
1241 if (this != null) { this.ptrs_to.add(min_final_cltv_expiry); };
1246 * Gets an LDK-generated payment preimage from a payment hash and payment secret that were
1247 * previously returned from [`create_inbound_payment`].
1249 * [`create_inbound_payment`]: Self::create_inbound_payment
1251 public Result_ThirtyTwoBytesAPIErrorZ get_payment_preimage(byte[] payment_hash, byte[] payment_secret) {
1252 long ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
1253 Reference.reachabilityFence(this);
1254 Reference.reachabilityFence(payment_hash);
1255 Reference.reachabilityFence(payment_secret);
1256 if (ret >= 0 && ret <= 4096) { return null; }
1257 Result_ThirtyTwoBytesAPIErrorZ ret_hu_conv = Result_ThirtyTwoBytesAPIErrorZ.constr_from_ptr(ret);
1262 * Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
1263 * are used when constructing the phantom invoice's route hints.
1265 * [phantom node payments]: crate::sign::PhantomKeysManager
1267 public long get_phantom_scid() {
1268 long ret = bindings.ChannelManager_get_phantom_scid(this.ptr);
1269 Reference.reachabilityFence(this);
1274 * Gets route hints for use in receiving [phantom node payments].
1276 * [phantom node payments]: crate::sign::PhantomKeysManager
1278 public PhantomRouteHints get_phantom_route_hints() {
1279 long ret = bindings.ChannelManager_get_phantom_route_hints(this.ptr);
1280 Reference.reachabilityFence(this);
1281 if (ret >= 0 && ret <= 4096) { return null; }
1282 org.ldk.structs.PhantomRouteHints ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomRouteHints(null, ret); }
1283 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1288 * Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
1289 * used when constructing the route hints for HTLCs intended to be intercepted. See
1290 * [`ChannelManager::forward_intercepted_htlc`].
1292 * Note that this method is not guaranteed to return unique values, you may need to call it a few
1293 * times to get a unique scid.
1295 public long get_intercept_scid() {
1296 long ret = bindings.ChannelManager_get_intercept_scid(this.ptr);
1297 Reference.reachabilityFence(this);
1302 * Gets inflight HTLC information by processing pending outbound payments that are in
1303 * our channels. May be used during pathfinding to account for in-use channel liquidity.
1305 public InFlightHtlcs compute_inflight_htlcs() {
1306 long ret = bindings.ChannelManager_compute_inflight_htlcs(this.ptr);
1307 Reference.reachabilityFence(this);
1308 if (ret >= 0 && ret <= 4096) { return null; }
1309 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
1310 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1315 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1316 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1318 public MessageSendEventsProvider as_MessageSendEventsProvider() {
1319 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
1320 Reference.reachabilityFence(this);
1321 if (ret >= 0 && ret <= 4096) { return null; }
1322 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
1323 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1328 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
1329 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1331 public EventsProvider as_EventsProvider() {
1332 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
1333 Reference.reachabilityFence(this);
1334 if (ret >= 0 && ret <= 4096) { return null; }
1335 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
1336 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1341 * Constructs a new Listen which calls the relevant methods on this_arg.
1342 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1344 public Listen as_Listen() {
1345 long ret = bindings.ChannelManager_as_Listen(this.ptr);
1346 Reference.reachabilityFence(this);
1347 if (ret >= 0 && ret <= 4096) { return null; }
1348 Listen ret_hu_conv = new Listen(null, ret);
1349 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1354 * Constructs a new Confirm which calls the relevant methods on this_arg.
1355 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1357 public Confirm as_Confirm() {
1358 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
1359 Reference.reachabilityFence(this);
1360 if (ret >= 0 && ret <= 4096) { return null; }
1361 Confirm ret_hu_conv = new Confirm(null, ret);
1362 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1367 * Gets a [`Future`] that completes when this [`ChannelManager`] may need to be persisted or
1368 * may have events that need processing.
1370 * In order to check if this [`ChannelManager`] needs persisting, call
1371 * [`Self::get_and_clear_needs_persistence`].
1373 * Note that callbacks registered on the [`Future`] MUST NOT call back into this
1374 * [`ChannelManager`] and should instead register actions to be taken later.
1376 public Future get_event_or_persistence_needed_future() {
1377 long ret = bindings.ChannelManager_get_event_or_persistence_needed_future(this.ptr);
1378 Reference.reachabilityFence(this);
1379 if (ret >= 0 && ret <= 4096) { return null; }
1380 org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); }
1381 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1386 * Returns true if this [`ChannelManager`] needs to be persisted.
1388 public boolean get_and_clear_needs_persistence() {
1389 boolean ret = bindings.ChannelManager_get_and_clear_needs_persistence(this.ptr);
1390 Reference.reachabilityFence(this);
1395 * Gets the latest best block which was connected either via the [`chain::Listen`] or
1396 * [`chain::Confirm`] interfaces.
1398 public BestBlock current_best_block() {
1399 long ret = bindings.ChannelManager_current_best_block(this.ptr);
1400 Reference.reachabilityFence(this);
1401 if (ret >= 0 && ret <= 4096) { return null; }
1402 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
1403 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1408 * Fetches the set of [`NodeFeatures`] flags that are provided by or required by
1409 * [`ChannelManager`].
1411 public NodeFeatures node_features() {
1412 long ret = bindings.ChannelManager_node_features(this.ptr);
1413 Reference.reachabilityFence(this);
1414 if (ret >= 0 && ret <= 4096) { return null; }
1415 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
1416 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1421 * Fetches the set of [`ChannelFeatures`] flags that are provided by or required by
1422 * [`ChannelManager`].
1424 public ChannelFeatures channel_features() {
1425 long ret = bindings.ChannelManager_channel_features(this.ptr);
1426 Reference.reachabilityFence(this);
1427 if (ret >= 0 && ret <= 4096) { return null; }
1428 org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); }
1429 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1434 * Fetches the set of [`ChannelTypeFeatures`] flags that are provided by or required by
1435 * [`ChannelManager`].
1437 public ChannelTypeFeatures channel_type_features() {
1438 long ret = bindings.ChannelManager_channel_type_features(this.ptr);
1439 Reference.reachabilityFence(this);
1440 if (ret >= 0 && ret <= 4096) { return null; }
1441 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
1442 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1447 * Fetches the set of [`InitFeatures`] flags that are provided by or required by
1448 * [`ChannelManager`].
1450 public InitFeatures init_features() {
1451 long ret = bindings.ChannelManager_init_features(this.ptr);
1452 Reference.reachabilityFence(this);
1453 if (ret >= 0 && ret <= 4096) { return null; }
1454 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
1455 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1460 * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1461 * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1463 public ChannelMessageHandler as_ChannelMessageHandler() {
1464 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
1465 Reference.reachabilityFence(this);
1466 if (ret >= 0 && ret <= 4096) { return null; }
1467 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
1468 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1473 * Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
1474 * This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
1476 public OffersMessageHandler as_OffersMessageHandler() {
1477 long ret = bindings.ChannelManager_as_OffersMessageHandler(this.ptr);
1478 Reference.reachabilityFence(this);
1479 if (ret >= 0 && ret <= 4096) { return null; }
1480 OffersMessageHandler ret_hu_conv = new OffersMessageHandler(null, ret);
1481 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
1486 * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1488 public byte[] write() {
1489 byte[] ret = bindings.ChannelManager_write(this.ptr);
1490 Reference.reachabilityFence(this);