Update auto-generated bindings to 0.0.103
[ldk-java] / src / main / java / org / ldk / structs / ChannelManager.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
11  * Manager which keeps track of a number of channels and sends messages to the appropriate
12  * channel, also tracking HTLC preimages and forwarding onion packets appropriately.
13  * 
14  * Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
15  * to individual Channels.
16  * 
17  * Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
18  * all peers during write/read (though does not modify this instance, only the instance being
19  * serialized). This will result in any channels which have not yet exchanged funding_created (ie
20  * called funding_transaction_generated for outbound channels).
21  * 
22  * Note that you can be a bit lazier about writing out ChannelManager than you can be with
23  * ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
24  * returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
25  * happens out-of-band (and will prevent any other ChannelManager operations from occurring during
26  * the serialization process). If the deserialized version is out-of-date compared to the
27  * ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
28  * ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
29  * 
30  * Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
31  * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
32  * the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
33  * block_connected() to step towards your best block) upon deserialization before using the
34  * object!
35  * 
36  * Note that ChannelManager is responsible for tracking liveness of its channels and generating
37  * ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
38  * spam due to quick disconnection/reconnection, updates are not sent until the channel has been
39  * offline for a full minute. In order to track this, you must call
40  * timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
41  * 
42  * Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
43  * a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
44  * essentially you should default to using a SimpleRefChannelManager, and use a
45  * SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
46  * you're using lightning-net-tokio.
47  */
48 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
49 public class ChannelManager extends CommonBase {
50         ChannelManager(Object _dummy, long ptr) { super(ptr); }
51         @Override @SuppressWarnings("deprecation")
52         protected void finalize() throws Throwable {
53                 super.finalize();
54                 if (ptr != 0) { bindings.ChannelManager_free(ptr); }
55         }
56
57         /**
58          * Constructs a new ChannelManager to hold several channels and route between them.
59          * 
60          * This is the main \"logic hub\" for all channel-related actions, and implements
61          * ChannelMessageHandler.
62          * 
63          * Non-proportional fees are fixed according to our risk using the provided fee estimator.
64          * 
65          * panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
66          * 
67          * Users need to notify the new ChannelManager when a new block is connected or
68          * disconnected using its `block_connected` and `block_disconnected` methods, starting
69          * from after `params.latest_hash`.
70          */
71         public static ChannelManager of(FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, ChainParameters params) {
72                 long ret = bindings.ChannelManager_new(fee_est == null ? 0 : fee_est.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, keys_manager == null ? 0 : keys_manager.ptr, config == null ? 0 : config.ptr & ~1, params == null ? 0 : params.ptr & ~1);
73                 if (ret >= 0 && ret <= 4096) { return null; }
74                 ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelManager(null, ret); }
75                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
76                 ret_hu_conv.ptrs_to.add(fee_est);
77                 ret_hu_conv.ptrs_to.add(chain_monitor);
78                 ret_hu_conv.ptrs_to.add(tx_broadcaster);
79                 ret_hu_conv.ptrs_to.add(logger);
80                 ret_hu_conv.ptrs_to.add(keys_manager);
81                 return ret_hu_conv;
82         }
83
84         /**
85          * Gets the current configuration applied to all new channels,  as
86          */
87         public UserConfig get_current_default_configuration() {
88                 long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UserConfig(null, ret); }
91                 ret_hu_conv.ptrs_to.add(this);
92                 return ret_hu_conv;
93         }
94
95         /**
96          * Creates a new outbound channel to the given remote node and with the given value.
97          * 
98          * `user_channel_id` will be provided back as in
99          * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
100          * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
101          * for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
102          * `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
103          * ignored.
104          * 
105          * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
106          * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
107          * 
108          * Note that we do not check if you are currently connected to the given peer. If no
109          * connection is available, the outbound `open_channel` message may fail to send, resulting in
110          * the channel eventually being silently forgotten (dropped on reload).
111          * 
112          * Returns the new Channel's temporary `channel_id`. This ID will appear as
113          * [`Event::FundingGenerationReady::temporary_channel_id`] and in
114          * [`ChannelDetails::channel_id`] until after
115          * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
116          * one derived from the funding transaction's TXID. If the counterparty rejects the channel
117          * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
118          * 
119          * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
120          * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
121          * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
122          * 
123          * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
124          */
125         public Result__u832APIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_channel_id, @Nullable UserConfig override_config) {
126                 long ret = bindings.ChannelManager_create_channel(this.ptr, their_network_key, channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr & ~1);
127                 if (ret >= 0 && ret <= 4096) { return null; }
128                 Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
129                 return ret_hu_conv;
130         }
131
132         /**
133          * Gets the list of open channels, in random order. See ChannelDetail field documentation for
134          * more information.
135          */
136         public ChannelDetails[] list_channels() {
137                 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
138                 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
139                 for (int q = 0; q < ret.length; q++) {
140                         long ret_conv_16 = ret[q];
141                         ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new ChannelDetails(null, ret_conv_16); }
142                         ret_conv_16_hu_conv.ptrs_to.add(this);
143                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
144                 }
145                 return ret_conv_16_arr;
146         }
147
148         /**
149          * Gets the list of usable channels, in random order. Useful as an argument to
150          * get_route to ensure non-announced channels are used.
151          * 
152          * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
153          * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
154          * are.
155          */
156         public ChannelDetails[] list_usable_channels() {
157                 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
158                 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
159                 for (int q = 0; q < ret.length; q++) {
160                         long ret_conv_16 = ret[q];
161                         ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new ChannelDetails(null, ret_conv_16); }
162                         ret_conv_16_hu_conv.ptrs_to.add(this);
163                         ret_conv_16_arr[q] = ret_conv_16_hu_conv;
164                 }
165                 return ret_conv_16_arr;
166         }
167
168         /**
169          * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
170          * will be accepted on the given channel, and after additional timeout/the closing of all
171          * pending HTLCs, the channel will be closed on chain.
172          * 
173          * If we are the channel initiator, we will pay between our [`Background`] and
174          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
175          * estimate.
176          * If our counterparty is the channel initiator, we will require a channel closing
177          * transaction feerate of at least our [`Background`] feerate or the feerate which
178          * would appear on a force-closure transaction, whichever is lower. We will allow our
179          * counterparty to pay as much fee as they'd like, however.
180          * 
181          * May generate a SendShutdown message event on success, which should be relayed.
182          * 
183          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
184          * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
185          * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
186          */
187         public Result_NoneAPIErrorZ close_channel(byte[] channel_id) {
188                 long ret = bindings.ChannelManager_close_channel(this.ptr, channel_id);
189                 if (ret >= 0 && ret <= 4096) { return null; }
190                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
191                 return ret_hu_conv;
192         }
193
194         /**
195          * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
196          * will be accepted on the given channel, and after additional timeout/the closing of all
197          * pending HTLCs, the channel will be closed on chain.
198          * 
199          * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
200          * the channel being closed or not:
201          * If we are the channel initiator, we will pay at least this feerate on the closing
202          * transaction. The upper-bound is set by
203          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
204          * estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
205          * If our counterparty is the channel initiator, we will refuse to accept a channel closure
206          * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
207          * will appear on a force-closure transaction, whichever is lower).
208          * 
209          * May generate a SendShutdown message event on success, which should be relayed.
210          * 
211          * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
212          * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
213          * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
214          */
215         public Result_NoneAPIErrorZ close_channel_with_target_feerate(byte[] channel_id, int target_feerate_sats_per_1000_weight) {
216                 long ret = bindings.ChannelManager_close_channel_with_target_feerate(this.ptr, channel_id, target_feerate_sats_per_1000_weight);
217                 if (ret >= 0 && ret <= 4096) { return null; }
218                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
219                 return ret_hu_conv;
220         }
221
222         /**
223          * Force closes a channel, immediately broadcasting the latest local commitment transaction to
224          * the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
225          */
226         public Result_NoneAPIErrorZ force_close_channel(byte[] channel_id) {
227                 long ret = bindings.ChannelManager_force_close_channel(this.ptr, channel_id);
228                 if (ret >= 0 && ret <= 4096) { return null; }
229                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
230                 return ret_hu_conv;
231         }
232
233         /**
234          * Force close all channels, immediately broadcasting the latest local commitment transaction
235          * for each to the chain and rejecting new HTLCs on each.
236          */
237         public void force_close_all_channels() {
238                 bindings.ChannelManager_force_close_all_channels(this.ptr);
239         }
240
241         /**
242          * Sends a payment along a given route.
243          * 
244          * Value parameters are provided via the last hop in route, see documentation for RouteHop
245          * fields for more info.
246          * 
247          * Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
248          * payment), we don't do anything to stop you! We always try to ensure that if the provided
249          * next hop knows the preimage to payment_hash they can claim an additional amount as
250          * specified in the last hop in the route! Thus, you should probably do your own
251          * payment_preimage tracking (which you should already be doing as they represent \"proof of
252          * payment\") and prevent double-sends yourself.
253          * 
254          * May generate SendHTLCs message(s) event on success, which should be relayed.
255          * 
256          * Each path may have a different return value, and PaymentSendValue may return a Vec with
257          * each entry matching the corresponding-index entry in the route paths, see
258          * PaymentSendFailure for more info.
259          * 
260          * In general, a path may raise:
261          * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
262          * node public key) is specified.
263          * APIError::ChannelUnavailable if the next-hop channel is not available for updates
264          * (including due to previous monitor update failure or new permanent monitor update
265          * failure).
266          * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
267          * relevant updates.
268          * 
269          * Note that depending on the type of the PaymentSendFailure the HTLC may have been
270          * irrevocably committed to on our end. In such a case, do NOT retry the payment with a
271          * different route unless you intend to pay twice!
272          * 
273          * payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
274          * the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
275          * newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
276          * must not contain multiple paths as multi-path payments require a recipient-provided
277          * payment_secret.
278          * If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
279          * bit set (either as required or as available). If multiple paths are present in the Route,
280          * we assume the invoice had the basic_mpp feature set.
281          * 
282          * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
283          */
284         public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
285                 long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_hash, payment_secret);
286                 if (ret >= 0 && ret <= 4096) { return null; }
287                 Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
288                 this.ptrs_to.add(route);
289                 return ret_hu_conv;
290         }
291
292         /**
293          * Retries a payment along the given [`Route`].
294          * 
295          * Errors returned are a superset of those returned from [`send_payment`], so see
296          * [`send_payment`] documentation for more details on errors. This method will also error if the
297          * retry amount puts the payment more than 10% over the payment's total amount, or if the payment
298          * for the given `payment_id` cannot be found (likely due to timeout or success).
299          * 
300          * [`send_payment`]: [`ChannelManager::send_payment`]
301          */
302         public Result_NonePaymentSendFailureZ retry_payment(Route route, byte[] payment_id) {
303                 long ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_id);
304                 if (ret >= 0 && ret <= 4096) { return null; }
305                 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
306                 this.ptrs_to.add(route);
307                 return ret_hu_conv;
308         }
309
310         /**
311          * Send a spontaneous payment, which is a payment that does not require the recipient to have
312          * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
313          * the preimage, it must be a cryptographically secure random value that no intermediate node
314          * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
315          * never reach the recipient.
316          * 
317          * See [`send_payment`] documentation for more details on the return value of this function.
318          * 
319          * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
320          * [`send_payment`] for more information about the risks of duplicate preimage usage.
321          * 
322          * Note that `route` must have exactly one path.
323          * 
324          * [`send_payment`]: Self::send_payment
325          * 
326          * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
327          */
328         public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
329                 long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_preimage);
330                 if (ret >= 0 && ret <= 4096) { return null; }
331                 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
332                 this.ptrs_to.add(route);
333                 return ret_hu_conv;
334         }
335
336         /**
337          * Call this upon creation of a funding transaction for the given channel.
338          * 
339          * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
340          * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
341          * 
342          * Panics if a funding transaction has already been provided for this channel.
343          * 
344          * May panic if the output found in the funding transaction is duplicative with some other
345          * channel (note that this should be trivially prevented by using unique funding transaction
346          * keys per-channel).
347          * 
348          * Do NOT broadcast the funding transaction yourself. When we have safely received our
349          * counterparty's signature the funding transaction will automatically be broadcast via the
350          * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
351          * 
352          * Note that this includes RBF or similar transaction replacement strategies - lightning does
353          * not currently support replacing a funding transaction on an existing channel. Instead,
354          * create a new channel with a conflicting funding transaction.
355          * 
356          * [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
357          */
358         public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] funding_transaction) {
359                 long ret = bindings.ChannelManager_funding_transaction_generated(this.ptr, temporary_channel_id, funding_transaction);
360                 if (ret >= 0 && ret <= 4096) { return null; }
361                 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
362                 return ret_hu_conv;
363         }
364
365         /**
366          * Regenerates channel_announcements and generates a signed node_announcement from the given
367          * arguments, providing them in corresponding events via
368          * [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
369          * on-chain. This effectively re-broadcasts all channel announcements and sends our node
370          * announcement to ensure that the lightning P2P network is aware of the channels we have and
371          * our network addresses.
372          * 
373          * `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
374          * node to humans. They carry no in-protocol meaning.
375          * 
376          * `addresses` represent the set (possibly empty) of socket addresses on which this node
377          * accepts incoming connections. These will be included in the node_announcement, publicly
378          * tying these addresses together and to this node. If you wish to preserve user privacy,
379          * addresses should likely contain only Tor Onion addresses.
380          * 
381          * Panics if `addresses` is absurdly large (more than 500).
382          * 
383          * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
384          */
385         public void broadcast_node_announcement(byte[] rgb, byte[] alias, NetAddress[] addresses) {
386                 bindings.ChannelManager_broadcast_node_announcement(this.ptr, rgb, alias, addresses != null ? Arrays.stream(addresses).mapToLong(addresses_conv_12 -> addresses_conv_12.ptr).toArray() : null);
387         }
388
389         /**
390          * Processes HTLCs which are pending waiting on random forward delay.
391          * 
392          * Should only really ever be called in response to a PendingHTLCsForwardable event.
393          * Will likely generate further events.
394          */
395         public void process_pending_htlc_forwards() {
396                 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
397         }
398
399         /**
400          * Performs actions which should happen on startup and roughly once per minute thereafter.
401          * 
402          * This currently includes:
403          * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
404          * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
405          * than a minute, informing the network that they should no longer attempt to route over
406          * the channel.
407          * 
408          * Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
409          * estimate fetches.
410          */
411         public void timer_tick_occurred() {
412                 bindings.ChannelManager_timer_tick_occurred(this.ptr);
413         }
414
415         /**
416          * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
417          * after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
418          * along the path (including in our own channel on which we received it).
419          * Returns false if no payment was found to fail backwards, true if the process of failing the
420          * HTLC backwards has been started.
421          */
422         public boolean fail_htlc_backwards(byte[] payment_hash) {
423                 boolean ret = bindings.ChannelManager_fail_htlc_backwards(this.ptr, payment_hash);
424                 return ret;
425         }
426
427         /**
428          * Provides a payment preimage in response to a PaymentReceived event, returning true and
429          * generating message events for the net layer to claim the payment, if possible. Thus, you
430          * should probably kick the net layer to go send messages if this returns true!
431          * 
432          * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
433          * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
434          * event matches your expectation. If you fail to do so and call this method, you may provide
435          * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
436          * 
437          * May panic if called except in response to a PaymentReceived event.
438          * 
439          * [`create_inbound_payment`]: Self::create_inbound_payment
440          * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
441          */
442         public boolean claim_funds(byte[] payment_preimage) {
443                 boolean ret = bindings.ChannelManager_claim_funds(this.ptr, payment_preimage);
444                 return ret;
445         }
446
447         /**
448          * Gets the node_id held by this ChannelManager
449          */
450         public byte[] get_our_node_id() {
451                 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
452                 return ret;
453         }
454
455         /**
456          * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
457          * to pay us.
458          * 
459          * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
460          * [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second.
461          * 
462          * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
463          * will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
464          * passed directly to [`claim_funds`].
465          * 
466          * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
467          * 
468          * [`claim_funds`]: Self::claim_funds
469          * [`PaymentReceived`]: events::Event::PaymentReceived
470          * [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
471          * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
472          */
473         public TwoTuple_PaymentHashPaymentSecretZ create_inbound_payment(Option_u64Z min_value_msat, int invoice_expiry_delta_secs, long user_payment_id) {
474                 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, user_payment_id);
475                 if (ret >= 0 && ret <= 4096) { return null; }
476                 TwoTuple_PaymentHashPaymentSecretZ ret_hu_conv = new TwoTuple_PaymentHashPaymentSecretZ(null, ret);
477                 ret_hu_conv.ptrs_to.add(this);
478                 return ret_hu_conv;
479         }
480
481         /**
482          * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
483          * stored external to LDK.
484          * 
485          * A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
486          * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
487          * the `min_value_msat` provided here, if one is provided.
488          * 
489          * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This
490          * method may return an Err if another payment with the same payment_hash is still pending.
491          * 
492          * `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to
493          * allow tracking of which events correspond with which calls to this and
494          * [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply
495          * copied to events and otherwise ignored. It may be used to correlate PaymentReceived events
496          * with invoice metadata stored elsewhere.
497          * 
498          * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
499          * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
500          * before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
501          * sender \"proof-of-payment\" unless they have paid the required amount.
502          * 
503          * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
504          * in excess of the current time. This should roughly match the expiry time set in the invoice.
505          * After this many seconds, we will remove the inbound payment, resulting in any attempts to
506          * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
507          * invoices when no timeout is set.
508          * 
509          * Note that we use block header time to time-out pending inbound payments (with some margin
510          * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
511          * accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
512          * If you need exact expiry semantics, you should enforce them upon receipt of
513          * [`PaymentReceived`].
514          * 
515          * Pending inbound payments are stored in memory and in serialized versions of this
516          * [`ChannelManager`]. If potentially unbounded numbers of inbound payments may exist and
517          * space is limited, you may wish to rate-limit inbound payment creation.
518          * 
519          * May panic if `invoice_expiry_delta_secs` is greater than one year.
520          * 
521          * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
522          * set to at least [`MIN_FINAL_CLTV_EXPIRY`].
523          * 
524          * [`create_inbound_payment`]: Self::create_inbound_payment
525          * [`PaymentReceived`]: events::Event::PaymentReceived
526          * [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id
527          */
528         public Result_PaymentSecretAPIErrorZ create_inbound_payment_for_hash(byte[] payment_hash, Option_u64Z min_value_msat, int invoice_expiry_delta_secs, long user_payment_id) {
529                 long ret = bindings.ChannelManager_create_inbound_payment_for_hash(this.ptr, payment_hash, min_value_msat.ptr, invoice_expiry_delta_secs, user_payment_id);
530                 if (ret >= 0 && ret <= 4096) { return null; }
531                 Result_PaymentSecretAPIErrorZ ret_hu_conv = Result_PaymentSecretAPIErrorZ.constr_from_ptr(ret);
532                 return ret_hu_conv;
533         }
534
535         /**
536          * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
537          * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
538          */
539         public MessageSendEventsProvider as_MessageSendEventsProvider() {
540                 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
541                 if (ret >= 0 && ret <= 4096) { return null; }
542                 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
543                 ret_hu_conv.ptrs_to.add(this);
544                 return ret_hu_conv;
545         }
546
547         /**
548          * Constructs a new EventsProvider which calls the relevant methods on this_arg.
549          * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
550          */
551         public EventsProvider as_EventsProvider() {
552                 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
553                 if (ret >= 0 && ret <= 4096) { return null; }
554                 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
555                 ret_hu_conv.ptrs_to.add(this);
556                 return ret_hu_conv;
557         }
558
559         /**
560          * Constructs a new Listen which calls the relevant methods on this_arg.
561          * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
562          */
563         public Listen as_Listen() {
564                 long ret = bindings.ChannelManager_as_Listen(this.ptr);
565                 if (ret >= 0 && ret <= 4096) { return null; }
566                 Listen ret_hu_conv = new Listen(null, ret);
567                 ret_hu_conv.ptrs_to.add(this);
568                 return ret_hu_conv;
569         }
570
571         /**
572          * Constructs a new Confirm which calls the relevant methods on this_arg.
573          * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
574          */
575         public Confirm as_Confirm() {
576                 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
577                 if (ret >= 0 && ret <= 4096) { return null; }
578                 Confirm ret_hu_conv = new Confirm(null, ret);
579                 ret_hu_conv.ptrs_to.add(this);
580                 return ret_hu_conv;
581         }
582
583         /**
584          * Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
585          * indicating whether persistence is necessary. Only one listener on
586          * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
587          * up.
588          * Note that the feature `allow_wallclock_use` must be enabled to use this function.
589          */
590         public boolean await_persistable_update_timeout(long max_wait) {
591                 boolean ret = bindings.ChannelManager_await_persistable_update_timeout(this.ptr, max_wait);
592                 return ret;
593         }
594
595         /**
596          * Blocks until ChannelManager needs to be persisted. Only one listener on
597          * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
598          * up.
599          */
600         public void await_persistable_update() {
601                 bindings.ChannelManager_await_persistable_update(this.ptr);
602         }
603
604         /**
605          * Gets the latest best block which was connected either via the [`chain::Listen`] or
606          * [`chain::Confirm`] interfaces.
607          */
608         public BestBlock current_best_block() {
609                 long ret = bindings.ChannelManager_current_best_block(this.ptr);
610                 if (ret >= 0 && ret <= 4096) { return null; }
611                 BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new BestBlock(null, ret); }
612                 ret_hu_conv.ptrs_to.add(this);
613                 return ret_hu_conv;
614         }
615
616         /**
617          * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
618          * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
619          */
620         public ChannelMessageHandler as_ChannelMessageHandler() {
621                 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
622                 if (ret >= 0 && ret <= 4096) { return null; }
623                 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
624                 ret_hu_conv.ptrs_to.add(this);
625                 return ret_hu_conv;
626         }
627
628         /**
629          * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
630          */
631         public byte[] write() {
632                 byte[] ret = bindings.ChannelManager_write(this.ptr);
633                 return ret;
634         }
635
636         /**
637          * Constructs a new Payer which calls the relevant methods on this_arg.
638          * This copies the `inner` pointer in this_arg and thus the returned Payer must be freed before this_arg is
639          */
640         public Payer as_Payer() {
641                 long ret = bindings.ChannelManager_as_Payer(this.ptr);
642                 if (ret >= 0 && ret <= 4096) { return null; }
643                 Payer ret_hu_conv = new Payer(null, ret);
644                 ret_hu_conv.ptrs_to.add(this);
645                 return ret_hu_conv;
646         }
647
648 }