6 namespace org { namespace ldk { namespace structs {
10 * Manager which keeps track of a number of channels and sends messages to the appropriate
11 * channel, also tracking HTLC preimages and forwarding onion packets appropriately.
13 * Implements [`ChannelMessageHandler`], handling the multi-channel parts and passing things through
14 * to individual Channels.
16 * Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
17 * all peers during write/read (though does not modify this instance, only the instance being
18 * serialized). This will result in any channels which have not yet exchanged [`funding_created`] (i.e.,
19 * called [`funding_transaction_generated`] for outbound channels) being closed.
21 * Note that you can be a bit lazier about writing out `ChannelManager` than you can be with
22 * [`ChannelMonitor`]. With [`ChannelMonitor`] you MUST write each monitor update out to disk before
23 * returning from [`chain::Watch::watch_channel`]/[`update_channel`], with ChannelManagers, writing updates
24 * happens out-of-band (and will prevent any other `ChannelManager` operations from occurring during
25 * the serialization process). If the deserialized version is out-of-date compared to the
26 * [`ChannelMonitor`] passed by reference to [`read`], those channels will be force-closed based on the
27 * `ChannelMonitor` state and no funds will be lost (mod on-chain transaction fees).
29 * Note that the deserializer is only implemented for `(`[`BlockHash`]`, `[`ChannelManager`]`)`, which
30 * tells you the last block hash which was connected. You should get the best block tip before using the manager.
31 * See [`chain::Listen`] and [`chain::Confirm`] for more details.
33 * Note that `ChannelManager` is responsible for tracking liveness of its channels and generating
34 * [`ChannelUpdate`] messages informing peers that the channel is temporarily disabled. To avoid
35 * spam due to quick disconnection/reconnection, updates are not sent until the channel has been
36 * offline for a full minute. In order to track this, you must call
37 * [`timer_tick_occurred`] roughly once per minute, though it doesn't have to be perfect.
39 * To avoid trivial DoS issues, `ChannelManager` limits the number of inbound connections and
40 * inbound channels without confirmed funding transactions. This may result in nodes which we do
41 * not have a channel with being unable to connect to us or open new channels with us if we have
42 * many peers with unfunded channels.
44 * Because it is an indication of trust, inbound channels which we've accepted as 0conf are
45 * exempted from the count of unfunded channels. Similarly, outbound channels and connections are
46 * never limited. Please ensure you limit the count of such channels yourself.
48 * Rather than using a plain `ChannelManager`, it is preferable to use either a [`SimpleArcChannelManager`]
49 * a [`SimpleRefChannelManager`], for conciseness. See their documentation for more details, but
50 * essentially you should default to using a [`SimpleRefChannelManager`], and use a
51 * [`SimpleArcChannelManager`] when you require a `ChannelManager` with a static lifetime, such as when
52 * you're using lightning-net-tokio.
54 * [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
55 * [`funding_created`]: msgs::FundingCreated
56 * [`funding_transaction_generated`]: Self::funding_transaction_generated
57 * [`BlockHash`]: bitcoin::hash_types::BlockHash
58 * [`update_channel`]: chain::Watch::update_channel
59 * [`ChannelUpdate`]: msgs::ChannelUpdate
60 * [`timer_tick_occurred`]: Self::timer_tick_occurred
61 * [`read`]: ReadableArgs::read
63 public class ChannelManager : CommonBase {
64 internal ChannelManager(object _dummy, long ptr) : base(ptr) { }
66 if (ptr != 0) { bindings.ChannelManager_free(ptr); }
70 * Constructs a new `ChannelManager` to hold several channels and route between them.
72 * The current time or latest block header time can be provided as the `current_timestamp`.
74 * This is the main \"logic hub\" for all channel-related actions, and implements
75 * [`ChannelMessageHandler`].
77 * Non-proportional fees are fixed according to our risk using the provided fee estimator.
79 * Users need to notify the new `ChannelManager` when a new block is connected or
80 * disconnected using its [`block_connected`] and [`block_disconnected`] methods, starting
81 * from after [`params.best_block.block_hash`]. See [`chain::Listen`] and [`chain::Confirm`] for
84 * [`block_connected`]: chain::Listen::block_connected
85 * [`block_disconnected`]: chain::Listen::block_disconnected
86 * [`params.best_block.block_hash`]: chain::BestBlock::block_hash
88 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) {
89 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);
90 GC.KeepAlive(fee_est);
91 GC.KeepAlive(chain_monitor);
92 GC.KeepAlive(tx_broadcaster);
95 GC.KeepAlive(entropy_source);
96 GC.KeepAlive(node_signer);
97 GC.KeepAlive(signer_provider);
99 GC.KeepAlive(_params);
100 GC.KeepAlive(current_timestamp);
101 if (ret >= 0 && ret <= 4096) { return null; }
102 org.ldk.structs.ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelManager(null, ret); }
103 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
104 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(fee_est); };
105 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(chain_monitor); };
106 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(tx_broadcaster); };
107 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(router); };
108 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
109 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(entropy_source); };
110 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(node_signer); };
111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(signer_provider); };
112 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(config); };
113 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(_params); };
118 * Gets the current configuration applied to all new channels.
120 public UserConfig get_current_default_configuration() {
121 long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
123 if (ret >= 0 && ret <= 4096) { return null; }
124 org.ldk.structs.UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UserConfig(null, ret); }
125 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
130 * Creates a new outbound channel to the given remote node and with the given value.
132 * `user_channel_id` will be provided back as in
133 * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
134 * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
135 * randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
136 * is simply copied to events and otherwise ignored.
138 * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
139 * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
141 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be opened due to failing to
142 * generate a shutdown scriptpubkey or destination script set by
143 * [`SignerProvider::get_shutdown_scriptpubkey`] or [`SignerProvider::get_destination_script`].
145 * Note that we do not check if you are currently connected to the given peer. If no
146 * connection is available, the outbound `open_channel` message may fail to send, resulting in
147 * the channel eventually being silently forgotten (dropped on reload).
149 * Returns the new Channel's temporary `channel_id`. This ID will appear as
150 * [`Event::FundingGenerationReady::temporary_channel_id`] and in
151 * [`ChannelDetails::channel_id`] until after
152 * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
153 * one derived from the funding transaction's TXID. If the counterparty rejects the channel
154 * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
156 * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
157 * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
158 * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
160 * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
162 public Result__u832APIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, org.ldk.util.UInt128 user_channel_id, org.ldk.structs.UserConfig override_config) {
163 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);
165 GC.KeepAlive(their_network_key);
166 GC.KeepAlive(channel_value_satoshis);
167 GC.KeepAlive(push_msat);
168 GC.KeepAlive(user_channel_id);
169 GC.KeepAlive(override_config);
170 if (ret >= 0 && ret <= 4096) { return null; }
171 Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
172 if (this != null) { this.ptrs_to.AddLast(override_config); };
177 * Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for
180 public ChannelDetails[] list_channels() {
181 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
183 int ret_conv_16_len = ret.Length;
184 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
185 for (int q = 0; q < ret_conv_16_len; q++) {
186 long ret_conv_16 = ret[q];
187 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); }
188 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.AddLast(this); };
189 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
191 return ret_conv_16_arr;
195 * Gets the list of usable channels, in random order. Useful as an argument to
196 * [`Router::find_route`] to ensure non-announced channels are used.
198 * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
199 * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
202 public ChannelDetails[] list_usable_channels() {
203 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
205 int ret_conv_16_len = ret.Length;
206 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
207 for (int q = 0; q < ret_conv_16_len; q++) {
208 long ret_conv_16 = ret[q];
209 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); }
210 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.AddLast(this); };
211 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
213 return ret_conv_16_arr;
217 * Gets the list of channels we have with a given counterparty, in random order.
219 public ChannelDetails[] list_channels_with_counterparty(byte[] counterparty_node_id) {
220 long[] ret = bindings.ChannelManager_list_channels_with_counterparty(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33));
222 GC.KeepAlive(counterparty_node_id);
223 int ret_conv_16_len = ret.Length;
224 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret_conv_16_len];
225 for (int q = 0; q < ret_conv_16_len; q++) {
226 long ret_conv_16 = ret[q];
227 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); }
228 if (ret_conv_16_hu_conv != null) { ret_conv_16_hu_conv.ptrs_to.AddLast(this); };
229 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
231 return ret_conv_16_arr;
235 * Returns in an undefined order recent payments that -- if not fulfilled -- have yet to find a
236 * successful path, or have unresolved HTLCs.
238 * This can be useful for payments that may have been prepared, but ultimately not sent, as a
239 * result of a crash. If such a payment exists, is not listed here, and an
240 * [`Event::PaymentSent`] has not been received, you may consider resending the payment.
242 * [`Event::PaymentSent`]: events::Event::PaymentSent
244 public RecentPaymentDetails[] list_recent_payments() {
245 long[] ret = bindings.ChannelManager_list_recent_payments(this.ptr);
247 int ret_conv_22_len = ret.Length;
248 RecentPaymentDetails[] ret_conv_22_arr = new RecentPaymentDetails[ret_conv_22_len];
249 for (int w = 0; w < ret_conv_22_len; w++) {
250 long ret_conv_22 = ret[w];
251 org.ldk.structs.RecentPaymentDetails ret_conv_22_hu_conv = org.ldk.structs.RecentPaymentDetails.constr_from_ptr(ret_conv_22);
252 if (ret_conv_22_hu_conv != null) { ret_conv_22_hu_conv.ptrs_to.AddLast(this); };
253 ret_conv_22_arr[w] = ret_conv_22_hu_conv;
255 return ret_conv_22_arr;
259 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
260 * will be accepted on the given channel, and after additional timeout/the closing of all
261 * pending HTLCs, the channel will be closed on chain.
263 * If we are the channel initiator, we will pay between our [`Background`] and
264 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
266 * If our counterparty is the channel initiator, we will require a channel closing
267 * transaction feerate of at least our [`Background`] feerate or the feerate which
268 * would appear on a force-closure transaction, whichever is lower. We will allow our
269 * counterparty to pay as much fee as they'd like, however.
271 * May generate a [`SendShutdown`] message event on success, which should be relayed.
273 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
274 * generate a shutdown scriptpubkey or destination script set by
275 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
278 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
279 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
280 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
281 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
283 public Result_NoneAPIErrorZ close_channel(byte[] channel_id, byte[] counterparty_node_id) {
284 long ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32), InternalUtils.check_arr_len(counterparty_node_id, 33));
286 GC.KeepAlive(channel_id);
287 GC.KeepAlive(counterparty_node_id);
288 if (ret >= 0 && ret <= 4096) { return null; }
289 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
294 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
295 * will be accepted on the given channel, and after additional timeout/the closing of all
296 * pending HTLCs, the channel will be closed on chain.
298 * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
299 * the channel being closed or not:
300 * If we are the channel initiator, we will pay at least this feerate on the closing
301 * transaction. The upper-bound is set by
302 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
303 * estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
304 * If our counterparty is the channel initiator, we will refuse to accept a channel closure
305 * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
306 * will appear on a force-closure transaction, whichever is lower).
308 * The `shutdown_script` provided will be used as the `scriptPubKey` for the closing transaction.
309 * Will fail if a shutdown script has already been set for this channel by
310 * ['ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`]. The given shutdown script must
311 * also be compatible with our and the counterparty's features.
313 * May generate a [`SendShutdown`] message event on success, which should be relayed.
315 * Raises [`APIError::ChannelUnavailable`] if the channel cannot be closed due to failing to
316 * generate a shutdown scriptpubkey or destination script set by
317 * [`SignerProvider::get_shutdown_scriptpubkey`]. A force-closure may be needed to close the
320 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
321 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
322 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
323 * [`SendShutdown`]: crate::events::MessageSendEvent::SendShutdown
325 * Note that shutdown_script (or a relevant inner pointer) may be NULL or all-0s to represent None
327 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, org.ldk.structs.ShutdownScript shutdown_script) {
328 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);
330 GC.KeepAlive(channel_id);
331 GC.KeepAlive(counterparty_node_id);
332 GC.KeepAlive(target_feerate_sats_per_1000_weight);
333 GC.KeepAlive(shutdown_script);
334 if (ret >= 0 && ret <= 4096) { return null; }
335 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
336 if (this != null) { this.ptrs_to.AddLast(target_feerate_sats_per_1000_weight); };
337 if (this != null) { this.ptrs_to.AddLast(shutdown_script); };
342 * Force closes a channel, immediately broadcasting the latest local transaction(s) and
343 * rejecting new HTLCs on the given channel. Fails if `channel_id` is unknown to
344 * the manager, or if the `counterparty_node_id` isn't the counterparty of the corresponding
347 public Result_NoneAPIErrorZ force_close_broadcasting_latest_txn(byte[] channel_id, byte[] counterparty_node_id) {
348 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));
350 GC.KeepAlive(channel_id);
351 GC.KeepAlive(counterparty_node_id);
352 if (ret >= 0 && ret <= 4096) { return null; }
353 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
358 * Force closes a channel, rejecting new HTLCs on the given channel but skips broadcasting
359 * the latest local transaction(s). Fails if `channel_id` is unknown to the manager, or if the
360 * `counterparty_node_id` isn't the counterparty of the corresponding channel.
362 * You can always get the latest local transaction(s) to broadcast from
363 * [`ChannelMonitor::get_latest_holder_commitment_txn`].
365 public Result_NoneAPIErrorZ force_close_without_broadcasting_txn(byte[] channel_id, byte[] counterparty_node_id) {
366 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));
368 GC.KeepAlive(channel_id);
369 GC.KeepAlive(counterparty_node_id);
370 if (ret >= 0 && ret <= 4096) { return null; }
371 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
376 * Force close all channels, immediately broadcasting the latest local commitment transaction
377 * for each to the chain and rejecting new HTLCs on each.
379 public void force_close_all_channels_broadcasting_latest_txn() {
380 bindings.ChannelManager_force_close_all_channels_broadcasting_latest_txn(this.ptr);
385 * Force close all channels rejecting new HTLCs on each but without broadcasting the latest
386 * local transaction(s).
388 public void force_close_all_channels_without_broadcasting_txn() {
389 bindings.ChannelManager_force_close_all_channels_without_broadcasting_txn(this.ptr);
394 * Sends a payment along a given route.
396 * Value parameters are provided via the last hop in route, see documentation for [`RouteHop`]
397 * fields for more info.
399 * May generate [`UpdateHTLCs`] message(s) event on success, which should be relayed (e.g. via
400 * [`PeerManager::process_events`]).
402 * # Avoiding Duplicate Payments
404 * If a pending payment is currently in-flight with the same [`PaymentId`] provided, this
405 * method will error with an [`APIError::InvalidRoute`]. Note, however, that once a payment
406 * is no longer pending (either via [`ChannelManager::abandon_payment`], or handling of an
407 * [`Event::PaymentSent`] or [`Event::PaymentFailed`]) LDK will not stop you from sending a
408 * second payment with the same [`PaymentId`].
410 * Thus, in order to ensure duplicate payments are not sent, you should implement your own
411 * tracking of payments, including state to indicate once a payment has completed. Because you
412 * should also ensure that [`PaymentHash`]es are not re-used, for simplicity, you should
413 * consider using the [`PaymentHash`] as the key for tracking payments. In that case, the
414 * [`PaymentId`] should be a copy of the [`PaymentHash`] bytes.
416 * Additionally, in the scenario where we begin the process of sending a payment, but crash
417 * before `send_payment` returns (or prior to [`ChannelMonitorUpdate`] persistence if you're
418 * using [`ChannelMonitorUpdateStatus::InProgress`]), the payment may be lost on restart. See
419 * [`ChannelManager::list_recent_payments`] for more information.
421 * # Possible Error States on [`PaymentSendFailure`]
423 * Each path may have a different return value, and [`PaymentSendFailure`] may return a `Vec` with
424 * each entry matching the corresponding-index entry in the route paths, see
425 * [`PaymentSendFailure`] for more info.
427 * In general, a path may raise:
428 * [`APIError::InvalidRoute`] when an invalid route or forwarding parameter (cltv_delta, fee,
429 * node public key) is specified.
430 * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
431 * (including due to previous monitor update failure or new permanent monitor update
433 * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
436 * Note that depending on the type of the [`PaymentSendFailure`] the HTLC may have been
437 * irrevocably committed to on our end. In such a case, do NOT retry the payment with a
438 * different route unless you intend to pay twice!
440 * [`RouteHop`]: crate::routing::router::RouteHop
441 * [`Event::PaymentSent`]: events::Event::PaymentSent
442 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
443 * [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
444 * [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events
445 * [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress
447 public Result_NonePaymentSendFailureZ send_payment_with_route(org.ldk.structs.Route route, byte[] payment_hash, org.ldk.structs.RecipientOnionFields recipient_onion, byte[] payment_id) {
448 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));
451 GC.KeepAlive(payment_hash);
452 GC.KeepAlive(recipient_onion);
453 GC.KeepAlive(payment_id);
454 if (ret >= 0 && ret <= 4096) { return null; }
455 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
456 if (this != null) { this.ptrs_to.AddLast(route); };
457 if (this != null) { this.ptrs_to.AddLast(recipient_onion); };
462 * Similar to [`ChannelManager::send_payment_with_route`], but will automatically find a route based on
463 * `route_params` and retry failed payment paths based on `retry_strategy`.
465 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) {
466 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);
468 GC.KeepAlive(payment_hash);
469 GC.KeepAlive(recipient_onion);
470 GC.KeepAlive(payment_id);
471 GC.KeepAlive(route_params);
472 GC.KeepAlive(retry_strategy);
473 if (ret >= 0 && ret <= 4096) { return null; }
474 Result_NoneRetryableSendFailureZ ret_hu_conv = Result_NoneRetryableSendFailureZ.constr_from_ptr(ret);
475 if (this != null) { this.ptrs_to.AddLast(recipient_onion); };
476 if (this != null) { this.ptrs_to.AddLast(route_params); };
477 if (this != null) { this.ptrs_to.AddLast(retry_strategy); };
482 * Signals that no further retries for the given payment should occur. Useful if you have a
483 * pending outbound payment with retries remaining, but wish to stop retrying the payment before
484 * retries are exhausted.
486 * If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
487 * as there are no remaining pending HTLCs for this payment.
489 * Note that calling this method does *not* prevent a payment from succeeding. You must still
490 * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
491 * determine the ultimate status of a payment.
493 * If an [`Event::PaymentFailed`] event is generated and we restart without this
494 * [`ChannelManager`] having been persisted, another [`Event::PaymentFailed`] may be generated.
496 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
497 * [`Event::PaymentSent`]: events::Event::PaymentSent
499 public void abandon_payment(byte[] payment_id) {
500 bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
502 GC.KeepAlive(payment_id);
506 * Send a spontaneous payment, which is a payment that does not require the recipient to have
507 * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
508 * the preimage, it must be a cryptographically secure random value that no intermediate node
509 * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
510 * never reach the recipient.
512 * See [`send_payment`] documentation for more details on the return value of this function
513 * and idempotency guarantees provided by the [`PaymentId`] key.
515 * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
516 * [`send_payment`] for more information about the risks of duplicate preimage usage.
518 * [`send_payment`]: Self::send_payment
520 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) {
521 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));
524 GC.KeepAlive(payment_preimage);
525 GC.KeepAlive(recipient_onion);
526 GC.KeepAlive(payment_id);
527 if (ret >= 0 && ret <= 4096) { return null; }
528 Result_PaymentHashPaymentSendFailureZ ret_hu_conv = Result_PaymentHashPaymentSendFailureZ.constr_from_ptr(ret);
529 if (this != null) { this.ptrs_to.AddLast(route); };
530 if (this != null) { this.ptrs_to.AddLast(payment_preimage); };
531 if (this != null) { this.ptrs_to.AddLast(recipient_onion); };
536 * Similar to [`ChannelManager::send_spontaneous_payment`], but will automatically find a route
537 * based on `route_params` and retry failed payment paths based on `retry_strategy`.
539 * See [`PaymentParameters::for_keysend`] for help in constructing `route_params` for spontaneous
542 * [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
544 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) {
545 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);
547 GC.KeepAlive(payment_preimage);
548 GC.KeepAlive(recipient_onion);
549 GC.KeepAlive(payment_id);
550 GC.KeepAlive(route_params);
551 GC.KeepAlive(retry_strategy);
552 if (ret >= 0 && ret <= 4096) { return null; }
553 Result_PaymentHashRetryableSendFailureZ ret_hu_conv = Result_PaymentHashRetryableSendFailureZ.constr_from_ptr(ret);
554 if (this != null) { this.ptrs_to.AddLast(payment_preimage); };
555 if (this != null) { this.ptrs_to.AddLast(recipient_onion); };
556 if (this != null) { this.ptrs_to.AddLast(route_params); };
557 if (this != null) { this.ptrs_to.AddLast(retry_strategy); };
562 * Send a payment that is probing the given route for liquidity. We calculate the
563 * [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
564 * us to easily discern them from real payments.
566 public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_probe(org.ldk.structs.Path path) {
567 long ret = bindings.ChannelManager_send_probe(this.ptr, path == null ? 0 : path.ptr);
570 if (ret >= 0 && ret <= 4096) { return null; }
571 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
572 if (this != null) { this.ptrs_to.AddLast(path); };
577 * Call this upon creation of a funding transaction for the given channel.
579 * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
580 * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
582 * Returns [`APIError::APIMisuseError`] if the funding transaction is not final for propagation
583 * across the p2p network.
585 * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
586 * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
588 * May panic if the output found in the funding transaction is duplicative with some other
589 * channel (note that this should be trivially prevented by using unique funding transaction
592 * Do NOT broadcast the funding transaction yourself. When we have safely received our
593 * counterparty's signature the funding transaction will automatically be broadcast via the
594 * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
596 * Note that this includes RBF or similar transaction replacement strategies - lightning does
597 * not currently support replacing a funding transaction on an existing channel. Instead,
598 * create a new channel with a conflicting funding transaction.
600 * Note to keep the miner incentives aligned in moving the blockchain forward, we recommend
601 * the wallet software generating the funding transaction to apply anti-fee sniping as
602 * implemented by Bitcoin Core wallet. See <https://bitcoinops.org/en/topics/fee-sniping/>
605 * [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
606 * [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
608 public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] counterparty_node_id, byte[] funding_transaction) {
609 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);
611 GC.KeepAlive(temporary_channel_id);
612 GC.KeepAlive(counterparty_node_id);
613 GC.KeepAlive(funding_transaction);
614 if (ret >= 0 && ret <= 4096) { return null; }
615 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
620 * Atomically applies partial updates to the [`ChannelConfig`] of the given channels.
622 * Once the updates are applied, each eligible channel (advertised with a known short channel
623 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
624 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
625 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
627 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
628 * `counterparty_node_id` is provided.
630 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
631 * below [`MIN_CLTV_EXPIRY_DELTA`].
633 * If an error is returned, none of the updates should be considered applied.
635 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
636 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
637 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
638 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
639 * [`ChannelUpdate`]: msgs::ChannelUpdate
640 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
641 * [`APIMisuseError`]: APIError::APIMisuseError
643 public Result_NoneAPIErrorZ update_partial_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfigUpdate config_update) {
644 long ret = bindings.ChannelManager_update_partial_channel_config(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33), channel_ids != null ? InternalUtils.mapArray(channel_ids, channel_ids_conv_8 => InternalUtils.check_arr_len(channel_ids_conv_8, 32)) : null, config_update == null ? 0 : config_update.ptr);
646 GC.KeepAlive(counterparty_node_id);
647 GC.KeepAlive(channel_ids);
648 GC.KeepAlive(config_update);
649 if (ret >= 0 && ret <= 4096) { return null; }
650 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
651 if (this != null) { this.ptrs_to.AddLast(config_update); };
656 * Atomically updates the [`ChannelConfig`] for the given channels.
658 * Once the updates are applied, each eligible channel (advertised with a known short channel
659 * ID and a change in [`forwarding_fee_proportional_millionths`], [`forwarding_fee_base_msat`],
660 * or [`cltv_expiry_delta`]) has a [`BroadcastChannelUpdate`] event message generated
661 * containing the new [`ChannelUpdate`] message which should be broadcast to the network.
663 * Returns [`ChannelUnavailable`] when a channel is not found or an incorrect
664 * `counterparty_node_id` is provided.
666 * Returns [`APIMisuseError`] when a [`cltv_expiry_delta`] update is to be applied with a value
667 * below [`MIN_CLTV_EXPIRY_DELTA`].
669 * If an error is returned, none of the updates should be considered applied.
671 * [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
672 * [`forwarding_fee_base_msat`]: ChannelConfig::forwarding_fee_base_msat
673 * [`cltv_expiry_delta`]: ChannelConfig::cltv_expiry_delta
674 * [`BroadcastChannelUpdate`]: events::MessageSendEvent::BroadcastChannelUpdate
675 * [`ChannelUpdate`]: msgs::ChannelUpdate
676 * [`ChannelUnavailable`]: APIError::ChannelUnavailable
677 * [`APIMisuseError`]: APIError::APIMisuseError
679 public Result_NoneAPIErrorZ update_channel_config(byte[] counterparty_node_id, byte[][] channel_ids, org.ldk.structs.ChannelConfig config) {
680 long ret = bindings.ChannelManager_update_channel_config(this.ptr, InternalUtils.check_arr_len(counterparty_node_id, 33), channel_ids != null ? InternalUtils.mapArray(channel_ids, channel_ids_conv_8 => InternalUtils.check_arr_len(channel_ids_conv_8, 32)) : null, config == null ? 0 : config.ptr);
682 GC.KeepAlive(counterparty_node_id);
683 GC.KeepAlive(channel_ids);
684 GC.KeepAlive(config);
685 if (ret >= 0 && ret <= 4096) { return null; }
686 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
687 if (this != null) { this.ptrs_to.AddLast(config); };
692 * Attempts to forward an intercepted HTLC over the provided channel id and with the provided
693 * amount to forward. Should only be called in response to an [`HTLCIntercepted`] event.
695 * Intercepted HTLCs can be useful for Lightning Service Providers (LSPs) to open a just-in-time
696 * channel to a receiving node if the node lacks sufficient inbound liquidity.
698 * To make use of intercepted HTLCs, set [`UserConfig::accept_intercept_htlcs`] and use
699 * [`ChannelManager::get_intercept_scid`] to generate short channel id(s) to put in the
700 * receiver's invoice route hints. These route hints will signal to LDK to generate an
701 * [`HTLCIntercepted`] event when it receives the forwarded HTLC, and this method or
702 * [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to the event.
704 * Note that LDK does not enforce fee requirements in `amt_to_forward_msat`, and will not stop
705 * you from forwarding more than you received. See
706 * [`HTLCIntercepted::expected_outbound_amount_msat`] for more on forwarding a different amount
709 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
712 * [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
713 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
714 * [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat
716 public Result_NoneAPIErrorZ forward_intercepted_htlc(byte[] intercept_id, byte[] next_hop_channel_id, byte[] next_node_id, long amt_to_forward_msat) {
717 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);
719 GC.KeepAlive(intercept_id);
720 GC.KeepAlive(next_hop_channel_id);
721 GC.KeepAlive(next_node_id);
722 GC.KeepAlive(amt_to_forward_msat);
723 if (ret >= 0 && ret <= 4096) { return null; }
724 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
729 * Fails the intercepted HTLC indicated by intercept_id. Should only be called in response to
730 * an [`HTLCIntercepted`] event. See [`ChannelManager::forward_intercepted_htlc`].
732 * Errors if the event was not handled in time, in which case the HTLC was automatically failed
735 * [`HTLCIntercepted`]: events::Event::HTLCIntercepted
737 public Result_NoneAPIErrorZ fail_intercepted_htlc(byte[] intercept_id) {
738 long ret = bindings.ChannelManager_fail_intercepted_htlc(this.ptr, InternalUtils.check_arr_len(intercept_id, 32));
740 GC.KeepAlive(intercept_id);
741 if (ret >= 0 && ret <= 4096) { return null; }
742 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
747 * Processes HTLCs which are pending waiting on random forward delay.
749 * Should only really ever be called in response to a PendingHTLCsForwardable event.
750 * Will likely generate further events.
752 public void process_pending_htlc_forwards() {
753 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
758 * Performs actions which should happen on startup and roughly once per minute thereafter.
760 * This currently includes:
761 * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
762 * Broadcasting [`ChannelUpdate`] messages if we've been disconnected from our peer for more
763 * than a minute, informing the network that they should no longer attempt to route over
765 * Expiring a channel's previous [`ChannelConfig`] if necessary to only allow forwarding HTLCs
766 * with the current [`ChannelConfig`].
767 * Removing peers which have disconnected but and no longer have any channels.
768 * Force-closing and removing channels which have not completed establishment in a timely manner.
770 * Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate
773 * [`ChannelUpdate`]: msgs::ChannelUpdate
774 * [`ChannelConfig`]: crate::util::config::ChannelConfig
776 public void timer_tick_occurred() {
777 bindings.ChannelManager_timer_tick_occurred(this.ptr);
782 * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
783 * after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
784 * along the path (including in our own channel on which we received it).
786 * Note that in some cases around unclean shutdown, it is possible the payment may have
787 * already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
788 * second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
789 * may have already been failed automatically by LDK if it was nearing its expiration time.
791 * While LDK will never claim a payment automatically on your behalf (i.e. without you calling
792 * [`ChannelManager::claim_funds`]), you should still monitor for
793 * [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
794 * startup during which time claims that were in-progress at shutdown may be replayed.
796 public void fail_htlc_backwards(byte[] payment_hash) {
797 bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
799 GC.KeepAlive(payment_hash);
803 * This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
804 * reason for the failure.
806 * See [`FailureCode`] for valid failure codes.
808 public void fail_htlc_backwards_with_reason(byte[] payment_hash, FailureCode failure_code) {
809 bindings.ChannelManager_fail_htlc_backwards_with_reason(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), failure_code);
811 GC.KeepAlive(payment_hash);
812 GC.KeepAlive(failure_code);
816 * Provides a payment preimage in response to [`Event::PaymentClaimable`], generating any
817 * [`MessageSendEvent`]s needed to claim the payment.
819 * This method is guaranteed to ensure the payment has been claimed but only if the current
820 * height is strictly below [`Event::PaymentClaimable::claim_deadline`]. To avoid race
821 * conditions, you should wait for an [`Event::PaymentClaimed`] before considering the payment
822 * successful. It will generally be available in the next [`process_pending_events`] call.
824 * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
825 * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentClaimable`
826 * event matches your expectation. If you fail to do so and call this method, you may provide
827 * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
829 * [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
830 * [`Event::PaymentClaimable::claim_deadline`]: crate::events::Event::PaymentClaimable::claim_deadline
831 * [`Event::PaymentClaimed`]: crate::events::Event::PaymentClaimed
832 * [`process_pending_events`]: EventsProvider::process_pending_events
833 * [`create_inbound_payment`]: Self::create_inbound_payment
834 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
836 public void claim_funds(byte[] payment_preimage) {
837 bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
839 GC.KeepAlive(payment_preimage);
843 * Gets the node_id held by this ChannelManager
845 public byte[] get_our_node_id() {
846 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
852 * Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
854 * The `temporary_channel_id` parameter indicates which inbound channel should be accepted,
855 * and the `counterparty_node_id` parameter is the id of the peer which has requested to open
858 * The `user_channel_id` parameter will be provided back in
859 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
860 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
862 * Note that this method will return an error and reject the channel, if it requires support
863 * for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
864 * used to accept such channels.
866 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
867 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
869 public Result_NoneAPIErrorZ accept_inbound_channel(byte[] temporary_channel_id, byte[] counterparty_node_id, org.ldk.util.UInt128 user_channel_id) {
870 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());
872 GC.KeepAlive(temporary_channel_id);
873 GC.KeepAlive(counterparty_node_id);
874 GC.KeepAlive(user_channel_id);
875 if (ret >= 0 && ret <= 4096) { return null; }
876 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
881 * Accepts a request to open a channel after a [`events::Event::OpenChannelRequest`], treating
882 * it as confirmed immediately.
884 * The `user_channel_id` parameter will be provided back in
885 * [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
886 * with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
888 * Unlike [`ChannelManager::accept_inbound_channel`], this method accepts the incoming channel
889 * and (if the counterparty agrees), enables forwarding of payments immediately.
891 * This fully trusts that the counterparty has honestly and correctly constructed the funding
892 * transaction and blindly assumes that it will eventually confirm.
894 * If it does not confirm before we decide to close the channel, or if the funding transaction
895 * does not pay to the correct script the correct amount, *you will lose funds*.
897 * [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
898 * [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
900 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) {
901 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());
903 GC.KeepAlive(temporary_channel_id);
904 GC.KeepAlive(counterparty_node_id);
905 GC.KeepAlive(user_channel_id);
906 if (ret >= 0 && ret <= 4096) { return null; }
907 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
912 * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
915 * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
916 * [`PaymentHash`] and [`PaymentPreimage`] for you.
918 * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentClaimable`], which
919 * will have the [`PaymentClaimable::purpose`] be [`PaymentPurpose::InvoicePayment`] with
920 * its [`PaymentPurpose::InvoicePayment::payment_preimage`] field filled in. That should then be
921 * passed directly to [`claim_funds`].
923 * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
925 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
926 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
930 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
931 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
933 * Errors if `min_value_msat` is greater than total bitcoin supply.
935 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
936 * on versions of LDK prior to 0.0.114.
938 * [`claim_funds`]: Self::claim_funds
939 * [`PaymentClaimable`]: events::Event::PaymentClaimable
940 * [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose
941 * [`PaymentPurpose::InvoicePayment`]: events::PaymentPurpose::InvoicePayment
942 * [`PaymentPurpose::InvoicePayment::payment_preimage`]: events::PaymentPurpose::InvoicePayment::payment_preimage
943 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
945 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) {
946 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
948 GC.KeepAlive(min_value_msat);
949 GC.KeepAlive(invoice_expiry_delta_secs);
950 GC.KeepAlive(min_final_cltv_expiry_delta);
951 if (ret >= 0 && ret <= 4096) { return null; }
952 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
953 if (this != null) { this.ptrs_to.AddLast(min_value_msat); };
954 if (this != null) { this.ptrs_to.AddLast(min_final_cltv_expiry_delta); };
959 * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
960 * stored external to LDK.
962 * A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
963 * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
964 * the `min_value_msat` provided here, if one is provided.
966 * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
967 * note that LDK will not stop you from registering duplicate payment hashes for inbound
970 * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
971 * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
972 * before a [`PaymentClaimable`] event will be generated, ensuring that we do not provide the
973 * sender \"proof-of-payment\" unless they have paid the required amount.
975 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
976 * in excess of the current time. This should roughly match the expiry time set in the invoice.
977 * After this many seconds, we will remove the inbound payment, resulting in any attempts to
978 * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
979 * invoices when no timeout is set.
981 * Note that we use block header time to time-out pending inbound payments (with some margin
982 * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
983 * accept a payment and generate a [`PaymentClaimable`] event for some time after the expiry.
984 * If you need exact expiry semantics, you should enforce them upon receipt of
985 * [`PaymentClaimable`].
987 * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry_delta`
988 * set to at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
990 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
991 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
995 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
996 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
998 * Errors if `min_value_msat` is greater than total bitcoin supply.
1000 * If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
1001 * on versions of LDK prior to 0.0.114.
1003 * [`create_inbound_payment`]: Self::create_inbound_payment
1004 * [`PaymentClaimable`]: events::Event::PaymentClaimable
1006 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) {
1007 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);
1009 GC.KeepAlive(payment_hash);
1010 GC.KeepAlive(min_value_msat);
1011 GC.KeepAlive(invoice_expiry_delta_secs);
1012 GC.KeepAlive(min_final_cltv_expiry);
1013 if (ret >= 0 && ret <= 4096) { return null; }
1014 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
1015 if (this != null) { this.ptrs_to.AddLast(min_value_msat); };
1016 if (this != null) { this.ptrs_to.AddLast(min_final_cltv_expiry); };
1021 * Gets an LDK-generated payment preimage from a payment hash and payment secret that were
1022 * previously returned from [`create_inbound_payment`].
1024 * [`create_inbound_payment`]: Self::create_inbound_payment
1026 public Result_PaymentPreimageAPIErrorZ get_payment_preimage(byte[] payment_hash, byte[] payment_secret) {
1027 long ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
1029 GC.KeepAlive(payment_hash);
1030 GC.KeepAlive(payment_secret);
1031 if (ret >= 0 && ret <= 4096) { return null; }
1032 Result_PaymentPreimageAPIErrorZ ret_hu_conv = Result_PaymentPreimageAPIErrorZ.constr_from_ptr(ret);
1037 * Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
1038 * are used when constructing the phantom invoice's route hints.
1040 * [phantom node payments]: crate::sign::PhantomKeysManager
1042 public long get_phantom_scid() {
1043 long ret = bindings.ChannelManager_get_phantom_scid(this.ptr);
1049 * Gets route hints for use in receiving [phantom node payments].
1051 * [phantom node payments]: crate::sign::PhantomKeysManager
1053 public PhantomRouteHints get_phantom_route_hints() {
1054 long ret = bindings.ChannelManager_get_phantom_route_hints(this.ptr);
1056 if (ret >= 0 && ret <= 4096) { return null; }
1057 org.ldk.structs.PhantomRouteHints ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomRouteHints(null, ret); }
1058 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1063 * Gets a fake short channel id for use in receiving intercepted payments. These fake scids are
1064 * used when constructing the route hints for HTLCs intended to be intercepted. See
1065 * [`ChannelManager::forward_intercepted_htlc`].
1067 * Note that this method is not guaranteed to return unique values, you may need to call it a few
1068 * times to get a unique scid.
1070 public long get_intercept_scid() {
1071 long ret = bindings.ChannelManager_get_intercept_scid(this.ptr);
1077 * Gets inflight HTLC information by processing pending outbound payments that are in
1078 * our channels. May be used during pathfinding to account for in-use channel liquidity.
1080 public InFlightHtlcs compute_inflight_htlcs() {
1081 long ret = bindings.ChannelManager_compute_inflight_htlcs(this.ptr);
1083 if (ret >= 0 && ret <= 4096) { return null; }
1084 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
1085 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1090 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
1091 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
1093 public MessageSendEventsProvider as_MessageSendEventsProvider() {
1094 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
1096 if (ret >= 0 && ret <= 4096) { return null; }
1097 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
1098 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1103 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
1104 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
1106 public EventsProvider as_EventsProvider() {
1107 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
1109 if (ret >= 0 && ret <= 4096) { return null; }
1110 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
1111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1116 * Constructs a new Listen which calls the relevant methods on this_arg.
1117 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
1119 public Listen as_Listen() {
1120 long ret = bindings.ChannelManager_as_Listen(this.ptr);
1122 if (ret >= 0 && ret <= 4096) { return null; }
1123 Listen ret_hu_conv = new Listen(null, ret);
1124 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1129 * Constructs a new Confirm which calls the relevant methods on this_arg.
1130 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
1132 public Confirm as_Confirm() {
1133 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
1135 if (ret >= 0 && ret <= 4096) { return null; }
1136 Confirm ret_hu_conv = new Confirm(null, ret);
1137 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1142 * Gets a [`Future`] that completes when this [`ChannelManager`] needs to be persisted.
1144 * Note that callbacks registered on the [`Future`] MUST NOT call back into this
1145 * [`ChannelManager`] and should instead register actions to be taken later.
1147 public Future get_persistable_update_future() {
1148 long ret = bindings.ChannelManager_get_persistable_update_future(this.ptr);
1150 if (ret >= 0 && ret <= 4096) { return null; }
1151 org.ldk.structs.Future ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Future(null, ret); }
1152 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1157 * Gets the latest best block which was connected either via the [`chain::Listen`] or
1158 * [`chain::Confirm`] interfaces.
1160 public BestBlock current_best_block() {
1161 long ret = bindings.ChannelManager_current_best_block(this.ptr);
1163 if (ret >= 0 && ret <= 4096) { return null; }
1164 org.ldk.structs.BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BestBlock(null, ret); }
1165 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1170 * Fetches the set of [`NodeFeatures`] flags which are provided by or required by
1171 * [`ChannelManager`].
1173 public NodeFeatures node_features() {
1174 long ret = bindings.ChannelManager_node_features(this.ptr);
1176 if (ret >= 0 && ret <= 4096) { return null; }
1177 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
1178 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1183 * Fetches the set of [`ChannelFeatures`] flags which are provided by or required by
1184 * [`ChannelManager`].
1186 public ChannelFeatures channel_features() {
1187 long ret = bindings.ChannelManager_channel_features(this.ptr);
1189 if (ret >= 0 && ret <= 4096) { return null; }
1190 org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); }
1191 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1196 * Fetches the set of [`ChannelTypeFeatures`] flags which are provided by or required by
1197 * [`ChannelManager`].
1199 public ChannelTypeFeatures channel_type_features() {
1200 long ret = bindings.ChannelManager_channel_type_features(this.ptr);
1202 if (ret >= 0 && ret <= 4096) { return null; }
1203 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
1204 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1209 * Fetches the set of [`InitFeatures`] flags which are provided by or required by
1210 * [`ChannelManager`].
1212 public InitFeatures init_features() {
1213 long ret = bindings.ChannelManager_init_features(this.ptr);
1215 if (ret >= 0 && ret <= 4096) { return null; }
1216 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
1217 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1222 * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
1223 * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
1225 public ChannelMessageHandler as_ChannelMessageHandler() {
1226 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
1228 if (ret >= 0 && ret <= 4096) { return null; }
1229 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
1230 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
1235 * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
1237 public byte[] write() {
1238 byte[] ret = bindings.ChannelManager_write(this.ptr);