4990ad25faeecf5a2ed0900e020a703c19e5f211
[ldk-java] / src / main / java / org / ldk / structs / UtilMethods.java
1 package org.ldk.structs;
2 import org.ldk.impl.bindings;
3 import org.ldk.enums.*;
4 import org.ldk.util.*;
5 import java.util.Arrays;
6 import java.lang.ref.Reference;
7 import javax.annotation.Nullable;
8
9 public class UtilMethods {
10         /**
11          * Constructs a new COption_NoneZ containing a
12          */
13         public static COption_NoneZ COption_NoneZ_some() {
14                 COption_NoneZ ret = bindings.COption_NoneZ_some();
15                 return ret;
16         }
17
18         /**
19          * Constructs a new COption_NoneZ containing nothing
20          */
21         public static COption_NoneZ COption_NoneZ_none() {
22                 COption_NoneZ ret = bindings.COption_NoneZ_none();
23                 return ret;
24         }
25
26         /**
27          * Read a ClosureReason from a byte array, created by ClosureReason_write
28          */
29         public static Result_COption_ClosureReasonZDecodeErrorZ ClosureReason_read(byte[] ser) {
30                 long ret = bindings.ClosureReason_read(ser);
31                 Reference.reachabilityFence(ser);
32                 if (ret >= 0 && ret <= 4096) { return null; }
33                 Result_COption_ClosureReasonZDecodeErrorZ ret_hu_conv = Result_COption_ClosureReasonZDecodeErrorZ.constr_from_ptr(ret);
34                 return ret_hu_conv;
35         }
36
37         /**
38          * Read a HTLCDestination from a byte array, created by HTLCDestination_write
39          */
40         public static Result_COption_HTLCDestinationZDecodeErrorZ HTLCDestination_read(byte[] ser) {
41                 long ret = bindings.HTLCDestination_read(ser);
42                 Reference.reachabilityFence(ser);
43                 if (ret >= 0 && ret <= 4096) { return null; }
44                 Result_COption_HTLCDestinationZDecodeErrorZ ret_hu_conv = Result_COption_HTLCDestinationZDecodeErrorZ.constr_from_ptr(ret);
45                 return ret_hu_conv;
46         }
47
48         /**
49          * Read a Event from a byte array, created by Event_write
50          */
51         public static Result_COption_EventZDecodeErrorZ Event_read(byte[] ser) {
52                 long ret = bindings.Event_read(ser);
53                 Reference.reachabilityFence(ser);
54                 if (ret >= 0 && ret <= 4096) { return null; }
55                 Result_COption_EventZDecodeErrorZ ret_hu_conv = Result_COption_EventZDecodeErrorZ.constr_from_ptr(ret);
56                 return ret_hu_conv;
57         }
58
59         /**
60          * Creates a digital signature of a message given a SecretKey, like the node's secret.
61          * A receiver knowing the PublicKey (e.g. the node's id) and the message can be sure that the signature was generated by the caller.
62          * Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.
63          */
64         public static Result_StringErrorZ sign(byte[] msg, byte[] sk) {
65                 long ret = bindings.sign(msg, InternalUtils.check_arr_len(sk, 32));
66                 Reference.reachabilityFence(msg);
67                 Reference.reachabilityFence(sk);
68                 if (ret >= 0 && ret <= 4096) { return null; }
69                 Result_StringErrorZ ret_hu_conv = Result_StringErrorZ.constr_from_ptr(ret);
70                 return ret_hu_conv;
71         }
72
73         /**
74          * Recovers the PublicKey of the signer of the message given the message and the signature.
75          */
76         public static Result_PublicKeyErrorZ recover_pk(byte[] msg, java.lang.String sig) {
77                 long ret = bindings.recover_pk(msg, sig);
78                 Reference.reachabilityFence(msg);
79                 Reference.reachabilityFence(sig);
80                 if (ret >= 0 && ret <= 4096) { return null; }
81                 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
82                 return ret_hu_conv;
83         }
84
85         /**
86          * Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature,
87          * and the PublicKey.
88          */
89         public static boolean verify(byte[] msg, java.lang.String sig, byte[] pk) {
90                 boolean ret = bindings.verify(msg, sig, InternalUtils.check_arr_len(pk, 33));
91                 Reference.reachabilityFence(msg);
92                 Reference.reachabilityFence(sig);
93                 Reference.reachabilityFence(pk);
94                 return ret;
95         }
96
97         /**
98          * Construct the invoice's HRP and signatureless data into a preimage to be hashed.
99          */
100         public static byte[] construct_invoice_preimage(byte[] hrp_bytes, UInt5[] data_without_signature) {
101                 byte[] ret = bindings.construct_invoice_preimage(hrp_bytes, data_without_signature != null ? InternalUtils.convUInt5Array(data_without_signature) : null);
102                 Reference.reachabilityFence(hrp_bytes);
103                 Reference.reachabilityFence(data_without_signature);
104                 return ret;
105         }
106
107         /**
108          * Read a MonitorEvent from a byte array, created by MonitorEvent_write
109          */
110         public static Result_COption_MonitorEventZDecodeErrorZ MonitorEvent_read(byte[] ser) {
111                 long ret = bindings.MonitorEvent_read(ser);
112                 Reference.reachabilityFence(ser);
113                 if (ret >= 0 && ret <= 4096) { return null; }
114                 Result_COption_MonitorEventZDecodeErrorZ ret_hu_conv = Result_COption_MonitorEventZDecodeErrorZ.constr_from_ptr(ret);
115                 return ret_hu_conv;
116         }
117
118         /**
119          * Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
120          */
121         public static Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ C2Tuple_BlockHashChannelMonitorZ_read(byte[] ser, KeysInterface arg) {
122                 long ret = bindings.C2Tuple_BlockHashChannelMonitorZ_read(ser, arg == null ? 0 : arg.ptr);
123                 Reference.reachabilityFence(ser);
124                 Reference.reachabilityFence(arg);
125                 if (ret >= 0 && ret <= 4096) { return null; }
126                 Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.constr_from_ptr(ret);
127                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg); };
128                 return ret_hu_conv;
129         }
130
131         /**
132          * Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
133          */
134         public static Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ C2Tuple_BlockHashChannelManagerZ_read(byte[] ser, KeysInterface arg_keys_manager, FeeEstimator arg_fee_estimator, Watch arg_chain_monitor, BroadcasterInterface arg_tx_broadcaster, Logger arg_logger, UserConfig arg_default_config, ChannelMonitor[] arg_channel_monitors) {
135                 long ret = bindings.C2Tuple_BlockHashChannelManagerZ_read(ser, bindings.ChannelManagerReadArgs_new(arg_keys_manager == null ? 0 : arg_keys_manager.ptr, arg_fee_estimator == null ? 0 : arg_fee_estimator.ptr, arg_chain_monitor == null ? 0 : arg_chain_monitor.ptr, arg_tx_broadcaster == null ? 0 : arg_tx_broadcaster.ptr, arg_logger == null ? 0 : arg_logger.ptr, arg_default_config == null ? 0 : arg_default_config.ptr, arg_channel_monitors != null ? Arrays.stream(arg_channel_monitors).mapToLong(arg_channel_monitors_conv_16 -> arg_channel_monitors_conv_16 == null ? 0 : arg_channel_monitors_conv_16.ptr).toArray() : null));
136                 Reference.reachabilityFence(ser);
137                 Reference.reachabilityFence(arg_keys_manager);
138                 Reference.reachabilityFence(arg_fee_estimator);
139                 Reference.reachabilityFence(arg_chain_monitor);
140                 Reference.reachabilityFence(arg_tx_broadcaster);
141                 Reference.reachabilityFence(arg_logger);
142                 Reference.reachabilityFence(arg_default_config);
143                 Reference.reachabilityFence(arg_channel_monitors);
144                 if (ret >= 0 && ret <= 4096) { return null; }
145                 Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret);
146                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_keys_manager); };
147                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_fee_estimator); };
148                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_chain_monitor); };
149                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_tx_broadcaster); };
150                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_logger); };
151                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_default_config); };
152                 for (ChannelMonitor arg_channel_monitors_conv_16: arg_channel_monitors) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_channel_monitors_conv_16); }; };
153                 return ret_hu_conv;
154         }
155
156         /**
157          * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment`], but no
158          * `ChannelManager` is required. Useful for generating invoices for [phantom node payments] without
159          * a `ChannelManager`.
160          * 
161          * `keys` is generated by calling [`KeysInterface::get_inbound_payment_key_material`] and then
162          * calling [`ExpandedKey::new`] with its result. It is recommended to cache this value and not
163          * regenerate it for each new inbound payment.
164          * 
165          * `current_time` is a Unix timestamp representing the current time.
166          * 
167          * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
168          */
169         public static Result_C2Tuple_PaymentHashPaymentSecretZNoneZ create(ExpandedKey keys, Option_u64Z min_value_msat, int invoice_expiry_delta_secs, KeysInterface keys_manager, long current_time) {
170                 long ret = bindings.create(keys == null ? 0 : keys.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, keys_manager == null ? 0 : keys_manager.ptr, current_time);
171                 Reference.reachabilityFence(keys);
172                 Reference.reachabilityFence(min_value_msat);
173                 Reference.reachabilityFence(invoice_expiry_delta_secs);
174                 Reference.reachabilityFence(keys_manager);
175                 Reference.reachabilityFence(current_time);
176                 if (ret >= 0 && ret <= 4096) { return null; }
177                 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
178                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys); };
179                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
180                 return ret_hu_conv;
181         }
182
183         /**
184          * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash`],
185          * but no `ChannelManager` is required. Useful for generating invoices for [phantom node payments]
186          * without a `ChannelManager`.
187          * 
188          * See [`create`] for information on the `keys` and `current_time` parameters.
189          * 
190          * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
191          */
192         public static Result_PaymentSecretNoneZ create_from_hash(ExpandedKey keys, Option_u64Z min_value_msat, byte[] payment_hash, int invoice_expiry_delta_secs, long current_time) {
193                 long ret = bindings.create_from_hash(keys == null ? 0 : keys.ptr, min_value_msat.ptr, InternalUtils.check_arr_len(payment_hash, 32), invoice_expiry_delta_secs, current_time);
194                 Reference.reachabilityFence(keys);
195                 Reference.reachabilityFence(min_value_msat);
196                 Reference.reachabilityFence(payment_hash);
197                 Reference.reachabilityFence(invoice_expiry_delta_secs);
198                 Reference.reachabilityFence(current_time);
199                 if (ret >= 0 && ret <= 4096) { return null; }
200                 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
201                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys); };
202                 return ret_hu_conv;
203         }
204
205         /**
206          * Gets the weight for an HTLC-Success transaction.
207          */
208         public static long htlc_success_tx_weight(boolean opt_anchors) {
209                 long ret = bindings.htlc_success_tx_weight(opt_anchors);
210                 Reference.reachabilityFence(opt_anchors);
211                 return ret;
212         }
213
214         /**
215          * Gets the weight for an HTLC-Timeout transaction.
216          */
217         public static long htlc_timeout_tx_weight(boolean opt_anchors) {
218                 long ret = bindings.htlc_timeout_tx_weight(opt_anchors);
219                 Reference.reachabilityFence(opt_anchors);
220                 return ret;
221         }
222
223         /**
224          * Build the commitment secret from the seed and the commitment number
225          */
226         public static byte[] build_commitment_secret(byte[] commitment_seed, long idx) {
227                 byte[] ret = bindings.build_commitment_secret(InternalUtils.check_arr_len(commitment_seed, 32), idx);
228                 Reference.reachabilityFence(commitment_seed);
229                 Reference.reachabilityFence(idx);
230                 return ret;
231         }
232
233         /**
234          * Build a closing transaction
235          */
236         public static byte[] build_closing_transaction(long to_holder_value_sat, long to_counterparty_value_sat, byte[] to_holder_script, byte[] to_counterparty_script, OutPoint funding_outpoint) {
237                 byte[] ret = bindings.build_closing_transaction(to_holder_value_sat, to_counterparty_value_sat, to_holder_script, to_counterparty_script, funding_outpoint == null ? 0 : funding_outpoint.ptr);
238                 Reference.reachabilityFence(to_holder_value_sat);
239                 Reference.reachabilityFence(to_counterparty_value_sat);
240                 Reference.reachabilityFence(to_holder_script);
241                 Reference.reachabilityFence(to_counterparty_script);
242                 Reference.reachabilityFence(funding_outpoint);
243                 return ret;
244         }
245
246         /**
247          * Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
248          * from the base secret and the per_commitment_point.
249          * 
250          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
251          * generated (ie our own).
252          */
253         public static Result_SecretKeyErrorZ derive_private_key(byte[] per_commitment_point, byte[] base_secret) {
254                 long ret = bindings.derive_private_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_secret, 32));
255                 Reference.reachabilityFence(per_commitment_point);
256                 Reference.reachabilityFence(base_secret);
257                 if (ret >= 0 && ret <= 4096) { return null; }
258                 Result_SecretKeyErrorZ ret_hu_conv = Result_SecretKeyErrorZ.constr_from_ptr(ret);
259                 return ret_hu_conv;
260         }
261
262         /**
263          * Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
264          * from the base point and the per_commitment_key. This is the public equivalent of
265          * derive_private_key - using only public keys to derive a public key instead of private keys.
266          * 
267          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
268          * generated (ie our own).
269          */
270         public static Result_PublicKeyErrorZ derive_public_key(byte[] per_commitment_point, byte[] base_point) {
271                 long ret = bindings.derive_public_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_point, 33));
272                 Reference.reachabilityFence(per_commitment_point);
273                 Reference.reachabilityFence(base_point);
274                 if (ret >= 0 && ret <= 4096) { return null; }
275                 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
276                 return ret_hu_conv;
277         }
278
279         /**
280          * Derives a per-commitment-transaction revocation key from its constituent parts.
281          * 
282          * Only the cheating participant owns a valid witness to propagate a revoked
283          * commitment transaction, thus per_commitment_secret always come from cheater
284          * and revocation_base_secret always come from punisher, which is the broadcaster
285          * of the transaction spending with this key knowledge.
286          * 
287          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
288          * generated (ie our own).
289          */
290         public static Result_SecretKeyErrorZ derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret) {
291                 long ret = bindings.derive_private_revocation_key(InternalUtils.check_arr_len(per_commitment_secret, 32), InternalUtils.check_arr_len(countersignatory_revocation_base_secret, 32));
292                 Reference.reachabilityFence(per_commitment_secret);
293                 Reference.reachabilityFence(countersignatory_revocation_base_secret);
294                 if (ret >= 0 && ret <= 4096) { return null; }
295                 Result_SecretKeyErrorZ ret_hu_conv = Result_SecretKeyErrorZ.constr_from_ptr(ret);
296                 return ret_hu_conv;
297         }
298
299         /**
300          * Derives a per-commitment-transaction revocation public key from its constituent parts. This is
301          * the public equivalend of derive_private_revocation_key - using only public keys to derive a
302          * public key instead of private keys.
303          * 
304          * Only the cheating participant owns a valid witness to propagate a revoked
305          * commitment transaction, thus per_commitment_point always come from cheater
306          * and revocation_base_point always come from punisher, which is the broadcaster
307          * of the transaction spending with this key knowledge.
308          * 
309          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
310          * generated (ie our own).
311          */
312         public static Result_PublicKeyErrorZ derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point) {
313                 long ret = bindings.derive_public_revocation_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(countersignatory_revocation_base_point, 33));
314                 Reference.reachabilityFence(per_commitment_point);
315                 Reference.reachabilityFence(countersignatory_revocation_base_point);
316                 if (ret >= 0 && ret <= 4096) { return null; }
317                 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
318                 return ret_hu_conv;
319         }
320
321         /**
322          * A script either spendable by the revocation
323          * key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
324          * Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
325          */
326         public static byte[] get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key) {
327                 byte[] ret = bindings.get_revokeable_redeemscript(InternalUtils.check_arr_len(revocation_key, 33), contest_delay, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33));
328                 Reference.reachabilityFence(revocation_key);
329                 Reference.reachabilityFence(contest_delay);
330                 Reference.reachabilityFence(broadcaster_delayed_payment_key);
331                 return ret;
332         }
333
334         /**
335          * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
336          * does not need to have its previous_output_index filled.
337          */
338         public static byte[] get_htlc_redeemscript(HTLCOutputInCommitment htlc, boolean opt_anchors, TxCreationKeys keys) {
339                 byte[] ret = bindings.get_htlc_redeemscript(htlc == null ? 0 : htlc.ptr, opt_anchors, keys == null ? 0 : keys.ptr);
340                 Reference.reachabilityFence(htlc);
341                 Reference.reachabilityFence(opt_anchors);
342                 Reference.reachabilityFence(keys);
343                 return ret;
344         }
345
346         /**
347          * Gets the redeemscript for a funding output from the two funding public keys.
348          * Note that the order of funding public keys does not matter.
349          */
350         public static byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory) {
351                 byte[] ret = bindings.make_funding_redeemscript(InternalUtils.check_arr_len(broadcaster, 33), InternalUtils.check_arr_len(countersignatory, 33));
352                 Reference.reachabilityFence(broadcaster);
353                 Reference.reachabilityFence(countersignatory);
354                 return ret;
355         }
356
357         /**
358          * Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
359          * parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
360          * transaction which needs signing, and can be used to construct an HTLC transaction which is
361          * broadcastable given a counterparty HTLC signature.
362          * 
363          * Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
364          * commitment transaction).
365          */
366         public static byte[] build_htlc_transaction(byte[] commitment_txid, int feerate_per_kw, short contest_delay, HTLCOutputInCommitment htlc, boolean opt_anchors, byte[] broadcaster_delayed_payment_key, byte[] revocation_key) {
367                 byte[] ret = bindings.build_htlc_transaction(InternalUtils.check_arr_len(commitment_txid, 32), feerate_per_kw, contest_delay, htlc == null ? 0 : htlc.ptr, opt_anchors, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33), InternalUtils.check_arr_len(revocation_key, 33));
368                 Reference.reachabilityFence(commitment_txid);
369                 Reference.reachabilityFence(feerate_per_kw);
370                 Reference.reachabilityFence(contest_delay);
371                 Reference.reachabilityFence(htlc);
372                 Reference.reachabilityFence(opt_anchors);
373                 Reference.reachabilityFence(broadcaster_delayed_payment_key);
374                 Reference.reachabilityFence(revocation_key);
375                 return ret;
376         }
377
378         /**
379          * Gets the witnessScript for an anchor output from the funding public key.
380          * The witness in the spending input must be:
381          * <BIP 143 funding_signature>
382          * After 16 blocks of confirmation, an alternative satisfying witness could be:
383          * <>
384          * (empty vector required to satisfy compliance with MINIMALIF-standard rule)
385          */
386         public static byte[] get_anchor_redeemscript(byte[] funding_pubkey) {
387                 byte[] ret = bindings.get_anchor_redeemscript(InternalUtils.check_arr_len(funding_pubkey, 33));
388                 Reference.reachabilityFence(funding_pubkey);
389                 return ret;
390         }
391
392         /**
393          * Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
394          * shared secret first. This prevents on-chain observers from discovering how many commitment
395          * transactions occurred in a channel before it was closed.
396          * 
397          * This function gets the shared secret from relevant channel public keys and can be used to
398          * \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
399          */
400         public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, boolean outbound_from_broadcaster) {
401                 long ret = bindings.get_commitment_transaction_number_obscure_factor(InternalUtils.check_arr_len(broadcaster_payment_basepoint, 33), InternalUtils.check_arr_len(countersignatory_payment_basepoint, 33), outbound_from_broadcaster);
402                 Reference.reachabilityFence(broadcaster_payment_basepoint);
403                 Reference.reachabilityFence(countersignatory_payment_basepoint);
404                 Reference.reachabilityFence(outbound_from_broadcaster);
405                 return ret;
406         }
407
408         /**
409          * Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
410          */
411         public static Result_COption_NetworkUpdateZDecodeErrorZ NetworkUpdate_read(byte[] ser) {
412                 long ret = bindings.NetworkUpdate_read(ser);
413                 Reference.reachabilityFence(ser);
414                 if (ret >= 0 && ret <= 4096) { return null; }
415                 Result_COption_NetworkUpdateZDecodeErrorZ ret_hu_conv = Result_COption_NetworkUpdateZDecodeErrorZ.constr_from_ptr(ret);
416                 return ret_hu_conv;
417         }
418
419         /**
420          * Finds a route from us (payer) to the given target node (payee).
421          * 
422          * If the payee provided features in their invoice, they should be provided via `params.payee`.
423          * Without this, MPP will only be used if the payee's features are available in the network graph.
424          * 
425          * Private routing paths between a public node and the target may be included in `params.payee`.
426          * 
427          * If some channels aren't announced, it may be useful to fill in `first_hops` with the results
428          * from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
429          * from `network_graph` will be ignored, and only those in `first_hops` will be used.
430          * 
431          * The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
432          * However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
433          * `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
434          * 
435          * # Note
436          * 
437          * May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
438          * adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
439          * function.
440          * 
441          * # Panics
442          * 
443          * Panics if first_hops contains channels without short_channel_ids;
444          * [`ChannelManager::list_usable_channels`] will never include such channels.
445          * 
446          * [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
447          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
448          * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
449          * 
450          * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
451          */
452         public static Result_RouteLightningErrorZ find_route(byte[] our_node_pubkey, RouteParameters route_params, NetworkGraph network_graph, @Nullable ChannelDetails[] first_hops, Logger logger, Score scorer, byte[] random_seed_bytes) {
453                 long ret = bindings.find_route(InternalUtils.check_arr_len(our_node_pubkey, 33), route_params == null ? 0 : route_params.ptr, network_graph == null ? 0 : network_graph.ptr, first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr).toArray() : null, logger == null ? 0 : logger.ptr, scorer == null ? 0 : scorer.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
454                 Reference.reachabilityFence(our_node_pubkey);
455                 Reference.reachabilityFence(route_params);
456                 Reference.reachabilityFence(network_graph);
457                 Reference.reachabilityFence(first_hops);
458                 Reference.reachabilityFence(logger);
459                 Reference.reachabilityFence(scorer);
460                 Reference.reachabilityFence(random_seed_bytes);
461                 if (ret >= 0 && ret <= 4096) { return null; }
462                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
463                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_params); };
464                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
465                 for (ChannelDetails first_hops_conv_16: first_hops) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(first_hops_conv_16); }; };
466                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
467                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(scorer); };
468                 return ret_hu_conv;
469         }
470
471         /**
472          * Construct a route from us (payer) to the target node (payee) via the given hops (which should
473          * exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
474          * 
475          * Re-uses logic from `find_route`, so the restrictions described there also apply here.
476          */
477         public static Result_RouteLightningErrorZ build_route_from_hops(byte[] our_node_pubkey, byte[][] hops, RouteParameters route_params, NetworkGraph network_graph, Logger logger, byte[] random_seed_bytes) {
478                 long ret = bindings.build_route_from_hops(InternalUtils.check_arr_len(our_node_pubkey, 33), hops != null ? Arrays.stream(hops).map(hops_conv_8 -> InternalUtils.check_arr_len(hops_conv_8, 33)).toArray(byte[][]::new) : null, route_params == null ? 0 : route_params.ptr, network_graph == null ? 0 : network_graph.ptr, logger == null ? 0 : logger.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
479                 Reference.reachabilityFence(our_node_pubkey);
480                 Reference.reachabilityFence(hops);
481                 Reference.reachabilityFence(route_params);
482                 Reference.reachabilityFence(network_graph);
483                 Reference.reachabilityFence(logger);
484                 Reference.reachabilityFence(random_seed_bytes);
485                 if (ret >= 0 && ret <= 4096) { return null; }
486                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
487                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_params); };
488                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
489                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
490                 return ret_hu_conv;
491         }
492
493         /**
494          * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
495          * See [`PhantomKeysManager`] for more information on phantom node payments.
496          * 
497          * `phantom_route_hints` parameter:
498          * Contains channel info for all nodes participating in the phantom invoice
499          * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
500          * participating node
501          * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
502          * updated when a channel becomes disabled or closes
503          * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
504          * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
505          * down
506          * 
507          * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
508          * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
509          * If `None` is provided for `payment_hash`, then one will be created.
510          * 
511          * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
512          * in excess of the current time.
513          * 
514          * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
515          * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
516          * requirement).
517          * 
518          * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
519          * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
520          * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
521          * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
522          * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
523          * 
524          * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
525          */
526         public static Result_InvoiceSignOrCreationErrorZ create_phantom_invoice(Option_u64Z amt_msat, @Nullable byte[] payment_hash, java.lang.String description, int invoice_expiry_delta_secs, PhantomRouteHints[] phantom_route_hints, KeysInterface keys_manager, org.ldk.enums.Currency network) {
527                 long ret = bindings.create_phantom_invoice(amt_msat.ptr, InternalUtils.check_arr_len(payment_hash, 32), description, invoice_expiry_delta_secs, phantom_route_hints != null ? Arrays.stream(phantom_route_hints).mapToLong(phantom_route_hints_conv_19 -> phantom_route_hints_conv_19 == null ? 0 : phantom_route_hints_conv_19.ptr).toArray() : null, keys_manager == null ? 0 : keys_manager.ptr, network);
528                 Reference.reachabilityFence(amt_msat);
529                 Reference.reachabilityFence(payment_hash);
530                 Reference.reachabilityFence(description);
531                 Reference.reachabilityFence(invoice_expiry_delta_secs);
532                 Reference.reachabilityFence(phantom_route_hints);
533                 Reference.reachabilityFence(keys_manager);
534                 Reference.reachabilityFence(network);
535                 if (ret >= 0 && ret <= 4096) { return null; }
536                 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
537                 for (PhantomRouteHints phantom_route_hints_conv_19: phantom_route_hints) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(phantom_route_hints_conv_19); }; };
538                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
539                 return ret_hu_conv;
540         }
541
542         /**
543          * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
544          * See [`PhantomKeysManager`] for more information on phantom node payments.
545          * 
546          * `phantom_route_hints` parameter:
547          * Contains channel info for all nodes participating in the phantom invoice
548          * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
549          * participating node
550          * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
551          * updated when a channel becomes disabled or closes
552          * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
553          * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
554          * down
555          * 
556          * `description_hash` is a SHA-256 hash of the description text
557          * 
558          * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
559          * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
560          * If `None` is provided for `payment_hash`, then one will be created.
561          * 
562          * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
563          * in excess of the current time.
564          * 
565          * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
566          * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
567          * requirement).
568          * 
569          * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
570          * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
571          * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
572          * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
573          * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
574          * 
575          * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
576          */
577         public static Result_InvoiceSignOrCreationErrorZ create_phantom_invoice_with_description_hash(Option_u64Z amt_msat, @Nullable byte[] payment_hash, int invoice_expiry_delta_secs, Sha256 description_hash, PhantomRouteHints[] phantom_route_hints, KeysInterface keys_manager, org.ldk.enums.Currency network) {
578                 long ret = bindings.create_phantom_invoice_with_description_hash(amt_msat.ptr, InternalUtils.check_arr_len(payment_hash, 32), invoice_expiry_delta_secs, description_hash == null ? 0 : description_hash.ptr, phantom_route_hints != null ? Arrays.stream(phantom_route_hints).mapToLong(phantom_route_hints_conv_19 -> phantom_route_hints_conv_19 == null ? 0 : phantom_route_hints_conv_19.ptr).toArray() : null, keys_manager == null ? 0 : keys_manager.ptr, network);
579                 Reference.reachabilityFence(amt_msat);
580                 Reference.reachabilityFence(payment_hash);
581                 Reference.reachabilityFence(invoice_expiry_delta_secs);
582                 Reference.reachabilityFence(description_hash);
583                 Reference.reachabilityFence(phantom_route_hints);
584                 Reference.reachabilityFence(keys_manager);
585                 Reference.reachabilityFence(network);
586                 if (ret >= 0 && ret <= 4096) { return null; }
587                 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
588                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
589                 for (PhantomRouteHints phantom_route_hints_conv_19: phantom_route_hints) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(phantom_route_hints_conv_19); }; };
590                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
591                 return ret_hu_conv;
592         }
593
594         /**
595          * Utility to construct an invoice. Generally, unless you want to do something like a custom
596          * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
597          * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
598          * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
599          * that the payment secret is valid when the invoice is paid.
600          * 
601          * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
602          * in excess of the current time.
603          */
604         public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager(ChannelManager channelmanager, KeysInterface keys_manager, org.ldk.enums.Currency network, Option_u64Z amt_msat, java.lang.String description, int invoice_expiry_delta_secs) {
605                 long ret = bindings.create_invoice_from_channelmanager(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description, invoice_expiry_delta_secs);
606                 Reference.reachabilityFence(channelmanager);
607                 Reference.reachabilityFence(keys_manager);
608                 Reference.reachabilityFence(network);
609                 Reference.reachabilityFence(amt_msat);
610                 Reference.reachabilityFence(description);
611                 Reference.reachabilityFence(invoice_expiry_delta_secs);
612                 if (ret >= 0 && ret <= 4096) { return null; }
613                 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
614                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
615                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
616                 return ret_hu_conv;
617         }
618
619         /**
620          * Utility to construct an invoice. Generally, unless you want to do something like a custom
621          * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
622          * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
623          * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
624          * that the payment secret is valid when the invoice is paid.
625          * Use this variant if you want to pass the `description_hash` to the invoice.
626          * 
627          * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
628          * in excess of the current time.
629          */
630         public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash(ChannelManager channelmanager, KeysInterface keys_manager, org.ldk.enums.Currency network, Option_u64Z amt_msat, Sha256 description_hash, int invoice_expiry_delta_secs) {
631                 long ret = bindings.create_invoice_from_channelmanager_with_description_hash(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr, invoice_expiry_delta_secs);
632                 Reference.reachabilityFence(channelmanager);
633                 Reference.reachabilityFence(keys_manager);
634                 Reference.reachabilityFence(network);
635                 Reference.reachabilityFence(amt_msat);
636                 Reference.reachabilityFence(description_hash);
637                 Reference.reachabilityFence(invoice_expiry_delta_secs);
638                 if (ret >= 0 && ret <= 4096) { return null; }
639                 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
640                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
641                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
642                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
643                 return ret_hu_conv;
644         }
645
646         /**
647          * See [`create_invoice_from_channelmanager_with_description_hash`]
648          * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
649          * available and the current time is supplied by the caller.
650          */
651         public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(ChannelManager channelmanager, KeysInterface keys_manager, org.ldk.enums.Currency network, Option_u64Z amt_msat, Sha256 description_hash, long duration_since_epoch, int invoice_expiry_delta_secs) {
652                 long ret = bindings.create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr, duration_since_epoch, invoice_expiry_delta_secs);
653                 Reference.reachabilityFence(channelmanager);
654                 Reference.reachabilityFence(keys_manager);
655                 Reference.reachabilityFence(network);
656                 Reference.reachabilityFence(amt_msat);
657                 Reference.reachabilityFence(description_hash);
658                 Reference.reachabilityFence(duration_since_epoch);
659                 Reference.reachabilityFence(invoice_expiry_delta_secs);
660                 if (ret >= 0 && ret <= 4096) { return null; }
661                 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
662                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
663                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
664                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
665                 return ret_hu_conv;
666         }
667
668         /**
669          * See [`create_invoice_from_channelmanager`]
670          * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
671          * available and the current time is supplied by the caller.
672          */
673         public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_and_duration_since_epoch(ChannelManager channelmanager, KeysInterface keys_manager, org.ldk.enums.Currency network, Option_u64Z amt_msat, java.lang.String description, long duration_since_epoch, int invoice_expiry_delta_secs) {
674                 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description, duration_since_epoch, invoice_expiry_delta_secs);
675                 Reference.reachabilityFence(channelmanager);
676                 Reference.reachabilityFence(keys_manager);
677                 Reference.reachabilityFence(network);
678                 Reference.reachabilityFence(amt_msat);
679                 Reference.reachabilityFence(description);
680                 Reference.reachabilityFence(duration_since_epoch);
681                 Reference.reachabilityFence(invoice_expiry_delta_secs);
682                 if (ret >= 0 && ret <= 4096) { return null; }
683                 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
684                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
685                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
686                 return ret_hu_conv;
687         }
688
689 }