1 package org.ldk.structs;
2 import org.ldk.impl.bindings;
3 import org.ldk.enums.*;
5 import java.util.Arrays;
6 import java.lang.ref.Reference;
7 import javax.annotation.Nullable;
9 public class UtilMethods {
11 * Constructs a new COption_NoneZ containing a
13 public static COption_NoneZ COption_NoneZ_some() {
14 COption_NoneZ ret = bindings.COption_NoneZ_some();
19 * Constructs a new COption_NoneZ containing nothing
21 public static COption_NoneZ COption_NoneZ_none() {
22 COption_NoneZ ret = bindings.COption_NoneZ_none();
27 * Read a ClosureReason from a byte array, created by ClosureReason_write
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);
38 * Read a Event from a byte array, created by Event_write
40 public static Result_COption_EventZDecodeErrorZ Event_read(byte[] ser) {
41 long ret = bindings.Event_read(ser);
42 Reference.reachabilityFence(ser);
43 if (ret >= 0 && ret <= 4096) { return null; }
44 Result_COption_EventZDecodeErrorZ ret_hu_conv = Result_COption_EventZDecodeErrorZ.constr_from_ptr(ret);
49 * Creates a digital signature of a message given a SecretKey, like the node's secret.
50 * 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.
51 * Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.
53 public static Result_StringErrorZ sign(byte[] msg, byte[] sk) {
54 long ret = bindings.sign(msg, InternalUtils.check_arr_len(sk, 32));
55 Reference.reachabilityFence(msg);
56 Reference.reachabilityFence(sk);
57 if (ret >= 0 && ret <= 4096) { return null; }
58 Result_StringErrorZ ret_hu_conv = Result_StringErrorZ.constr_from_ptr(ret);
63 * Recovers the PublicKey of the signer of the message given the message and the signature.
65 public static Result_PublicKeyErrorZ recover_pk(byte[] msg, java.lang.String sig) {
66 long ret = bindings.recover_pk(msg, sig);
67 Reference.reachabilityFence(msg);
68 Reference.reachabilityFence(sig);
69 if (ret >= 0 && ret <= 4096) { return null; }
70 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
75 * Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature,
78 public static boolean verify(byte[] msg, java.lang.String sig, byte[] pk) {
79 boolean ret = bindings.verify(msg, sig, InternalUtils.check_arr_len(pk, 33));
80 Reference.reachabilityFence(msg);
81 Reference.reachabilityFence(sig);
82 Reference.reachabilityFence(pk);
87 * Construct the invoice's HRP and signatureless data into a preimage to be hashed.
89 public static byte[] construct_invoice_preimage(byte[] hrp_bytes, UInt5[] data_without_signature) {
90 byte[] ret = bindings.construct_invoice_preimage(hrp_bytes, data_without_signature != null ? InternalUtils.convUInt5Array(data_without_signature) : null);
91 Reference.reachabilityFence(hrp_bytes);
92 Reference.reachabilityFence(data_without_signature);
97 * Read a MonitorEvent from a byte array, created by MonitorEvent_write
99 public static Result_COption_MonitorEventZDecodeErrorZ MonitorEvent_read(byte[] ser) {
100 long ret = bindings.MonitorEvent_read(ser);
101 Reference.reachabilityFence(ser);
102 if (ret >= 0 && ret <= 4096) { return null; }
103 Result_COption_MonitorEventZDecodeErrorZ ret_hu_conv = Result_COption_MonitorEventZDecodeErrorZ.constr_from_ptr(ret);
108 * Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
110 public static Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ C2Tuple_BlockHashChannelMonitorZ_read(byte[] ser, KeysInterface arg) {
111 long ret = bindings.C2Tuple_BlockHashChannelMonitorZ_read(ser, arg == null ? 0 : arg.ptr);
112 Reference.reachabilityFence(ser);
113 Reference.reachabilityFence(arg);
114 if (ret >= 0 && ret <= 4096) { return null; }
115 Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.constr_from_ptr(ret);
116 ret_hu_conv.ptrs_to.add(arg);
121 * Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
123 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) {
124 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 & ~1, 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 & ~1).toArray() : null));
125 Reference.reachabilityFence(ser);
126 Reference.reachabilityFence(arg_keys_manager);
127 Reference.reachabilityFence(arg_fee_estimator);
128 Reference.reachabilityFence(arg_chain_monitor);
129 Reference.reachabilityFence(arg_tx_broadcaster);
130 Reference.reachabilityFence(arg_logger);
131 Reference.reachabilityFence(arg_default_config);
132 Reference.reachabilityFence(arg_channel_monitors);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret);
135 ret_hu_conv.ptrs_to.add(arg_keys_manager);
136 ret_hu_conv.ptrs_to.add(arg_fee_estimator);
137 ret_hu_conv.ptrs_to.add(arg_chain_monitor);
138 ret_hu_conv.ptrs_to.add(arg_tx_broadcaster);
139 ret_hu_conv.ptrs_to.add(arg_logger);
141 for (ChannelMonitor arg_channel_monitors_conv_16: arg_channel_monitors) { ret_hu_conv.ptrs_to.add(arg_channel_monitors_conv_16); };
146 * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment`], but no
147 * `ChannelManager` is required. Useful for generating invoices for [phantom node payments] without
148 * a `ChannelManager`.
150 * `keys` is generated by calling [`KeysInterface::get_inbound_payment_key_material`] and then
151 * calling [`ExpandedKey::new`] with its result. It is recommended to cache this value and not
152 * regenerate it for each new inbound payment.
154 * `current_time` is a Unix timestamp representing the current time.
156 * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
158 public static Result_C2Tuple_PaymentHashPaymentSecretZNoneZ create(ExpandedKey keys, Option_u64Z min_value_msat, int invoice_expiry_delta_secs, KeysInterface keys_manager, long current_time) {
159 long ret = bindings.create(keys == null ? 0 : keys.ptr & ~1, min_value_msat.ptr, invoice_expiry_delta_secs, keys_manager == null ? 0 : keys_manager.ptr, current_time);
160 Reference.reachabilityFence(keys);
161 Reference.reachabilityFence(min_value_msat);
162 Reference.reachabilityFence(invoice_expiry_delta_secs);
163 Reference.reachabilityFence(keys_manager);
164 Reference.reachabilityFence(current_time);
165 if (ret >= 0 && ret <= 4096) { return null; }
166 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
167 ret_hu_conv.ptrs_to.add(keys);
168 ret_hu_conv.ptrs_to.add(keys_manager);
173 * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash`],
174 * but no `ChannelManager` is required. Useful for generating invoices for [phantom node payments]
175 * without a `ChannelManager`.
177 * See [`create`] for information on the `keys` and `current_time` parameters.
179 * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
181 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) {
182 long ret = bindings.create_from_hash(keys == null ? 0 : keys.ptr & ~1, min_value_msat.ptr, InternalUtils.check_arr_len(payment_hash, 32), invoice_expiry_delta_secs, current_time);
183 Reference.reachabilityFence(keys);
184 Reference.reachabilityFence(min_value_msat);
185 Reference.reachabilityFence(payment_hash);
186 Reference.reachabilityFence(invoice_expiry_delta_secs);
187 Reference.reachabilityFence(current_time);
188 if (ret >= 0 && ret <= 4096) { return null; }
189 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
190 ret_hu_conv.ptrs_to.add(keys);
195 * Gets the weight for an HTLC-Success transaction.
197 public static long htlc_success_tx_weight(boolean opt_anchors) {
198 long ret = bindings.htlc_success_tx_weight(opt_anchors);
199 Reference.reachabilityFence(opt_anchors);
204 * Gets the weight for an HTLC-Timeout transaction.
206 public static long htlc_timeout_tx_weight(boolean opt_anchors) {
207 long ret = bindings.htlc_timeout_tx_weight(opt_anchors);
208 Reference.reachabilityFence(opt_anchors);
213 * Build the commitment secret from the seed and the commitment number
215 public static byte[] build_commitment_secret(byte[] commitment_seed, long idx) {
216 byte[] ret = bindings.build_commitment_secret(InternalUtils.check_arr_len(commitment_seed, 32), idx);
217 Reference.reachabilityFence(commitment_seed);
218 Reference.reachabilityFence(idx);
223 * Build a closing transaction
225 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) {
226 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 & ~1);
227 Reference.reachabilityFence(to_holder_value_sat);
228 Reference.reachabilityFence(to_counterparty_value_sat);
229 Reference.reachabilityFence(to_holder_script);
230 Reference.reachabilityFence(to_counterparty_script);
231 Reference.reachabilityFence(funding_outpoint);
236 * Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
237 * from the base secret and the per_commitment_point.
239 * Note that this is infallible iff we trust that at least one of the two input keys are randomly
240 * generated (ie our own).
242 public static Result_SecretKeyErrorZ derive_private_key(byte[] per_commitment_point, byte[] base_secret) {
243 long ret = bindings.derive_private_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_secret, 32));
244 Reference.reachabilityFence(per_commitment_point);
245 Reference.reachabilityFence(base_secret);
246 if (ret >= 0 && ret <= 4096) { return null; }
247 Result_SecretKeyErrorZ ret_hu_conv = Result_SecretKeyErrorZ.constr_from_ptr(ret);
252 * Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
253 * from the base point and the per_commitment_key. This is the public equivalent of
254 * derive_private_key - using only public keys to derive a public key instead of private keys.
256 * Note that this is infallible iff we trust that at least one of the two input keys are randomly
257 * generated (ie our own).
259 public static Result_PublicKeyErrorZ derive_public_key(byte[] per_commitment_point, byte[] base_point) {
260 long ret = bindings.derive_public_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_point, 33));
261 Reference.reachabilityFence(per_commitment_point);
262 Reference.reachabilityFence(base_point);
263 if (ret >= 0 && ret <= 4096) { return null; }
264 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
269 * Derives a per-commitment-transaction revocation key from its constituent parts.
271 * Only the cheating participant owns a valid witness to propagate a revoked
272 * commitment transaction, thus per_commitment_secret always come from cheater
273 * and revocation_base_secret always come from punisher, which is the broadcaster
274 * of the transaction spending with this key knowledge.
276 * Note that this is infallible iff we trust that at least one of the two input keys are randomly
277 * generated (ie our own).
279 public static Result_SecretKeyErrorZ derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret) {
280 long ret = bindings.derive_private_revocation_key(InternalUtils.check_arr_len(per_commitment_secret, 32), InternalUtils.check_arr_len(countersignatory_revocation_base_secret, 32));
281 Reference.reachabilityFence(per_commitment_secret);
282 Reference.reachabilityFence(countersignatory_revocation_base_secret);
283 if (ret >= 0 && ret <= 4096) { return null; }
284 Result_SecretKeyErrorZ ret_hu_conv = Result_SecretKeyErrorZ.constr_from_ptr(ret);
289 * Derives a per-commitment-transaction revocation public key from its constituent parts. This is
290 * the public equivalend of derive_private_revocation_key - using only public keys to derive a
291 * public key instead of private keys.
293 * Only the cheating participant owns a valid witness to propagate a revoked
294 * commitment transaction, thus per_commitment_point always come from cheater
295 * and revocation_base_point always come from punisher, which is the broadcaster
296 * of the transaction spending with this key knowledge.
298 * Note that this is infallible iff we trust that at least one of the two input keys are randomly
299 * generated (ie our own).
301 public static Result_PublicKeyErrorZ derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point) {
302 long ret = bindings.derive_public_revocation_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(countersignatory_revocation_base_point, 33));
303 Reference.reachabilityFence(per_commitment_point);
304 Reference.reachabilityFence(countersignatory_revocation_base_point);
305 if (ret >= 0 && ret <= 4096) { return null; }
306 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
311 * A script either spendable by the revocation
312 * key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
313 * Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
315 public static byte[] get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key) {
316 byte[] ret = bindings.get_revokeable_redeemscript(InternalUtils.check_arr_len(revocation_key, 33), contest_delay, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33));
317 Reference.reachabilityFence(revocation_key);
318 Reference.reachabilityFence(contest_delay);
319 Reference.reachabilityFence(broadcaster_delayed_payment_key);
324 * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
325 * does not need to have its previous_output_index filled.
327 public static byte[] get_htlc_redeemscript(HTLCOutputInCommitment htlc, boolean opt_anchors, TxCreationKeys keys) {
328 byte[] ret = bindings.get_htlc_redeemscript(htlc == null ? 0 : htlc.ptr & ~1, opt_anchors, keys == null ? 0 : keys.ptr & ~1);
329 Reference.reachabilityFence(htlc);
330 Reference.reachabilityFence(opt_anchors);
331 Reference.reachabilityFence(keys);
336 * Gets the redeemscript for a funding output from the two funding public keys.
337 * Note that the order of funding public keys does not matter.
339 public static byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory) {
340 byte[] ret = bindings.make_funding_redeemscript(InternalUtils.check_arr_len(broadcaster, 33), InternalUtils.check_arr_len(countersignatory, 33));
341 Reference.reachabilityFence(broadcaster);
342 Reference.reachabilityFence(countersignatory);
347 * Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
348 * parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
349 * transaction which needs signing, and can be used to construct an HTLC transaction which is
350 * broadcastable given a counterparty HTLC signature.
352 * Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
353 * commitment transaction).
355 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) {
356 byte[] ret = bindings.build_htlc_transaction(InternalUtils.check_arr_len(commitment_txid, 32), feerate_per_kw, contest_delay, htlc == null ? 0 : htlc.ptr & ~1, opt_anchors, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33), InternalUtils.check_arr_len(revocation_key, 33));
357 Reference.reachabilityFence(commitment_txid);
358 Reference.reachabilityFence(feerate_per_kw);
359 Reference.reachabilityFence(contest_delay);
360 Reference.reachabilityFence(htlc);
361 Reference.reachabilityFence(opt_anchors);
362 Reference.reachabilityFence(broadcaster_delayed_payment_key);
363 Reference.reachabilityFence(revocation_key);
368 * Gets the witnessScript for an anchor output from the funding public key.
369 * The witness in the spending input must be:
370 * <BIP 143 funding_signature>
371 * After 16 blocks of confirmation, an alternative satisfying witness could be:
373 * (empty vector required to satisfy compliance with MINIMALIF-standard rule)
375 public static byte[] get_anchor_redeemscript(byte[] funding_pubkey) {
376 byte[] ret = bindings.get_anchor_redeemscript(InternalUtils.check_arr_len(funding_pubkey, 33));
377 Reference.reachabilityFence(funding_pubkey);
382 * Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
383 * shared secret first. This prevents on-chain observers from discovering how many commitment
384 * transactions occurred in a channel before it was closed.
386 * This function gets the shared secret from relevant channel public keys and can be used to
387 * \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
389 public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, boolean outbound_from_broadcaster) {
390 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);
391 Reference.reachabilityFence(broadcaster_payment_basepoint);
392 Reference.reachabilityFence(countersignatory_payment_basepoint);
393 Reference.reachabilityFence(outbound_from_broadcaster);
398 * Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
400 public static Result_COption_NetworkUpdateZDecodeErrorZ NetworkUpdate_read(byte[] ser) {
401 long ret = bindings.NetworkUpdate_read(ser);
402 Reference.reachabilityFence(ser);
403 if (ret >= 0 && ret <= 4096) { return null; }
404 Result_COption_NetworkUpdateZDecodeErrorZ ret_hu_conv = Result_COption_NetworkUpdateZDecodeErrorZ.constr_from_ptr(ret);
409 * Finds a route from us (payer) to the given target node (payee).
411 * If the payee provided features in their invoice, they should be provided via `params.payee`.
412 * Without this, MPP will only be used if the payee's features are available in the network graph.
414 * Private routing paths between a public node and the target may be included in `params.payee`.
416 * If some channels aren't announced, it may be useful to fill in `first_hops` with the results
417 * from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
418 * from `network_graph` will be ignored, and only those in `first_hops` will be used.
420 * The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
421 * However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
422 * `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
426 * May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
427 * adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
432 * Panics if first_hops contains channels without short_channel_ids;
433 * [`ChannelManager::list_usable_channels`] will never include such channels.
435 * [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
436 * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
437 * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
439 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
441 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) {
442 long ret = bindings.find_route(InternalUtils.check_arr_len(our_node_pubkey, 33), route_params == null ? 0 : route_params.ptr & ~1, network_graph == null ? 0 : network_graph.ptr & ~1, first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr & ~1).toArray() : null, logger == null ? 0 : logger.ptr, scorer == null ? 0 : scorer.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
443 Reference.reachabilityFence(our_node_pubkey);
444 Reference.reachabilityFence(route_params);
445 Reference.reachabilityFence(network_graph);
446 Reference.reachabilityFence(first_hops);
447 Reference.reachabilityFence(logger);
448 Reference.reachabilityFence(scorer);
449 Reference.reachabilityFence(random_seed_bytes);
450 if (ret >= 0 && ret <= 4096) { return null; }
451 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
452 ret_hu_conv.ptrs_to.add(route_params);
453 ret_hu_conv.ptrs_to.add(network_graph);
454 for (ChannelDetails first_hops_conv_16: first_hops) { ret_hu_conv.ptrs_to.add(first_hops_conv_16); };
455 ret_hu_conv.ptrs_to.add(logger);
456 ret_hu_conv.ptrs_to.add(scorer);
461 * Construct a route from us (payer) to the target node (payee) via the given hops (which should
462 * exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
464 * Re-uses logic from `find_route`, so the restrictions described there also apply here.
466 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) {
467 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 & ~1, network_graph == null ? 0 : network_graph.ptr & ~1, logger == null ? 0 : logger.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
468 Reference.reachabilityFence(our_node_pubkey);
469 Reference.reachabilityFence(hops);
470 Reference.reachabilityFence(route_params);
471 Reference.reachabilityFence(network_graph);
472 Reference.reachabilityFence(logger);
473 Reference.reachabilityFence(random_seed_bytes);
474 if (ret >= 0 && ret <= 4096) { return null; }
475 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
476 ret_hu_conv.ptrs_to.add(route_params);
477 ret_hu_conv.ptrs_to.add(network_graph);
478 ret_hu_conv.ptrs_to.add(logger);
483 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
484 * See [`PhantomKeysManager`] for more information on phantom node payments.
486 * `phantom_route_hints` parameter:
487 * Contains channel info for all nodes participating in the phantom invoice
488 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
490 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
491 * updated when a channel becomes disabled or closes
492 * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
493 * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
496 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
497 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
498 * If `None` is provided for `payment_hash`, then one will be created.
500 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
501 * in excess of the current time.
503 * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
504 * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
507 * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
508 * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
509 * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
510 * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
511 * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
513 * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
515 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) {
516 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 & ~1).toArray() : null, keys_manager == null ? 0 : keys_manager.ptr, network);
517 Reference.reachabilityFence(amt_msat);
518 Reference.reachabilityFence(payment_hash);
519 Reference.reachabilityFence(description);
520 Reference.reachabilityFence(invoice_expiry_delta_secs);
521 Reference.reachabilityFence(phantom_route_hints);
522 Reference.reachabilityFence(keys_manager);
523 Reference.reachabilityFence(network);
524 if (ret >= 0 && ret <= 4096) { return null; }
525 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
526 ret_hu_conv.ptrs_to.add(keys_manager);
531 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
532 * See [`PhantomKeysManager`] for more information on phantom node payments.
534 * `phantom_route_hints` parameter:
535 * Contains channel info for all nodes participating in the phantom invoice
536 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
538 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
539 * updated when a channel becomes disabled or closes
540 * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
541 * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
544 * `description_hash` is a SHA-256 hash of the description text
546 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
547 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
548 * If `None` is provided for `payment_hash`, then one will be created.
550 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
551 * in excess of the current time.
553 * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
554 * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
557 * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
558 * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
559 * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
560 * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
561 * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
563 * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
565 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) {
566 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 & ~1, 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 & ~1).toArray() : null, keys_manager == null ? 0 : keys_manager.ptr, network);
567 Reference.reachabilityFence(amt_msat);
568 Reference.reachabilityFence(payment_hash);
569 Reference.reachabilityFence(invoice_expiry_delta_secs);
570 Reference.reachabilityFence(description_hash);
571 Reference.reachabilityFence(phantom_route_hints);
572 Reference.reachabilityFence(keys_manager);
573 Reference.reachabilityFence(network);
574 if (ret >= 0 && ret <= 4096) { return null; }
575 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
576 ret_hu_conv.ptrs_to.add(keys_manager);
581 * Utility to construct an invoice. Generally, unless you want to do something like a custom
582 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
583 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
584 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
585 * that the payment secret is valid when the invoice is paid.
587 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
588 * in excess of the current time.
590 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) {
591 long ret = bindings.create_invoice_from_channelmanager(channelmanager == null ? 0 : channelmanager.ptr & ~1, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description, invoice_expiry_delta_secs);
592 Reference.reachabilityFence(channelmanager);
593 Reference.reachabilityFence(keys_manager);
594 Reference.reachabilityFence(network);
595 Reference.reachabilityFence(amt_msat);
596 Reference.reachabilityFence(description);
597 Reference.reachabilityFence(invoice_expiry_delta_secs);
598 if (ret >= 0 && ret <= 4096) { return null; }
599 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
600 ret_hu_conv.ptrs_to.add(channelmanager);
601 ret_hu_conv.ptrs_to.add(keys_manager);
606 * Utility to construct an invoice. Generally, unless you want to do something like a custom
607 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
608 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
609 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
610 * that the payment secret is valid when the invoice is paid.
611 * Use this variant if you want to pass the `description_hash` to the invoice.
613 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
614 * in excess of the current time.
616 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) {
617 long ret = bindings.create_invoice_from_channelmanager_with_description_hash(channelmanager == null ? 0 : channelmanager.ptr & ~1, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr & ~1, invoice_expiry_delta_secs);
618 Reference.reachabilityFence(channelmanager);
619 Reference.reachabilityFence(keys_manager);
620 Reference.reachabilityFence(network);
621 Reference.reachabilityFence(amt_msat);
622 Reference.reachabilityFence(description_hash);
623 Reference.reachabilityFence(invoice_expiry_delta_secs);
624 if (ret >= 0 && ret <= 4096) { return null; }
625 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
626 ret_hu_conv.ptrs_to.add(channelmanager);
627 ret_hu_conv.ptrs_to.add(keys_manager);
632 * See [`create_invoice_from_channelmanager_with_description_hash`]
633 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
634 * available and the current time is supplied by the caller.
636 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) {
637 long ret = bindings.create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr & ~1, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr & ~1, duration_since_epoch, invoice_expiry_delta_secs);
638 Reference.reachabilityFence(channelmanager);
639 Reference.reachabilityFence(keys_manager);
640 Reference.reachabilityFence(network);
641 Reference.reachabilityFence(amt_msat);
642 Reference.reachabilityFence(description_hash);
643 Reference.reachabilityFence(duration_since_epoch);
644 Reference.reachabilityFence(invoice_expiry_delta_secs);
645 if (ret >= 0 && ret <= 4096) { return null; }
646 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
647 ret_hu_conv.ptrs_to.add(channelmanager);
648 ret_hu_conv.ptrs_to.add(keys_manager);
653 * See [`create_invoice_from_channelmanager`]
654 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
655 * available and the current time is supplied by the caller.
657 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) {
658 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr & ~1, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description, duration_since_epoch, invoice_expiry_delta_secs);
659 Reference.reachabilityFence(channelmanager);
660 Reference.reachabilityFence(keys_manager);
661 Reference.reachabilityFence(network);
662 Reference.reachabilityFence(amt_msat);
663 Reference.reachabilityFence(description);
664 Reference.reachabilityFence(duration_since_epoch);
665 Reference.reachabilityFence(invoice_expiry_delta_secs);
666 if (ret >= 0 && ret <= 4096) { return null; }
667 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
668 ret_hu_conv.ptrs_to.add(channelmanager);
669 ret_hu_conv.ptrs_to.add(keys_manager);