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 * Gets the 128-bit integer, as 16 little-endian bytes
13 public static byte[] U128_le_bytes(org.ldk.util.UInt128 val) {
14 byte[] ret = bindings.U128_le_bytes(val.getLEBytes());
15 Reference.reachabilityFence(val);
20 * Constructs a new U128 from 16 little-endian bytes
22 public static UInt128 U128_new(byte[] le_bytes) {
23 byte[] ret = bindings.U128_new(InternalUtils.check_arr_len(le_bytes, 16));
24 Reference.reachabilityFence(le_bytes);
25 org.ldk.util.UInt128 ret_conv = new org.ldk.util.UInt128(ret);
30 * Constructs a new COption_NoneZ containing a
32 public static COption_NoneZ COption_NoneZ_some() {
33 COption_NoneZ ret = bindings.COption_NoneZ_some();
38 * Constructs a new COption_NoneZ containing nothing
40 public static COption_NoneZ COption_NoneZ_none() {
41 COption_NoneZ ret = bindings.COption_NoneZ_none();
46 * Read a APIError from a byte array, created by APIError_write
48 public static Result_COption_APIErrorZDecodeErrorZ APIError_read(byte[] ser) {
49 long ret = bindings.APIError_read(ser);
50 Reference.reachabilityFence(ser);
51 if (ret >= 0 && ret <= 4096) { return null; }
52 Result_COption_APIErrorZDecodeErrorZ ret_hu_conv = Result_COption_APIErrorZDecodeErrorZ.constr_from_ptr(ret);
57 * Creates a digital signature of a message given a SecretKey, like the node's secret.
58 * 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.
59 * Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.
61 public static Result_StringErrorZ sign(byte[] msg, byte[] sk) {
62 long ret = bindings.sign(msg, InternalUtils.check_arr_len(sk, 32));
63 Reference.reachabilityFence(msg);
64 Reference.reachabilityFence(sk);
65 if (ret >= 0 && ret <= 4096) { return null; }
66 Result_StringErrorZ ret_hu_conv = Result_StringErrorZ.constr_from_ptr(ret);
71 * Recovers the PublicKey of the signer of the message given the message and the signature.
73 public static Result_PublicKeyErrorZ recover_pk(byte[] msg, java.lang.String sig) {
74 long ret = bindings.recover_pk(msg, sig);
75 Reference.reachabilityFence(msg);
76 Reference.reachabilityFence(sig);
77 if (ret >= 0 && ret <= 4096) { return null; }
78 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
83 * Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature,
86 public static boolean verify(byte[] msg, java.lang.String sig, byte[] pk) {
87 boolean ret = bindings.verify(msg, sig, InternalUtils.check_arr_len(pk, 33));
88 Reference.reachabilityFence(msg);
89 Reference.reachabilityFence(sig);
90 Reference.reachabilityFence(pk);
95 * Construct the invoice's HRP and signatureless data into a preimage to be hashed.
97 public static byte[] construct_invoice_preimage(byte[] hrp_bytes, UInt5[] data_without_signature) {
98 byte[] ret = bindings.construct_invoice_preimage(hrp_bytes, data_without_signature != null ? InternalUtils.convUInt5Array(data_without_signature) : null);
99 Reference.reachabilityFence(hrp_bytes);
100 Reference.reachabilityFence(data_without_signature);
105 * Read a MonitorEvent from a byte array, created by MonitorEvent_write
107 public static Result_COption_MonitorEventZDecodeErrorZ MonitorEvent_read(byte[] ser) {
108 long ret = bindings.MonitorEvent_read(ser);
109 Reference.reachabilityFence(ser);
110 if (ret >= 0 && ret <= 4096) { return null; }
111 Result_COption_MonitorEventZDecodeErrorZ ret_hu_conv = Result_COption_MonitorEventZDecodeErrorZ.constr_from_ptr(ret);
116 * Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
118 public static Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ C2Tuple_BlockHashChannelMonitorZ_read(byte[] ser, org.ldk.structs.EntropySource arg_a, org.ldk.structs.SignerProvider arg_b) {
119 long ret = bindings.C2Tuple_BlockHashChannelMonitorZ_read(ser, arg_a.ptr, arg_b.ptr);
120 Reference.reachabilityFence(ser);
121 Reference.reachabilityFence(arg_a);
122 Reference.reachabilityFence(arg_b);
123 if (ret >= 0 && ret <= 4096) { return null; }
124 Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.constr_from_ptr(ret);
125 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_a); };
126 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_b); };
131 * Fetches the set of [`InitFeatures`] flags which are provided by or required by
132 * [`ChannelManager`].
134 public static InitFeatures provided_init_features(org.ldk.structs.UserConfig config) {
135 long ret = bindings.provided_init_features(config == null ? 0 : config.ptr);
136 Reference.reachabilityFence(config);
137 if (ret >= 0 && ret <= 4096) { return null; }
138 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
139 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
140 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(config); };
145 * Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
147 public static Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ C2Tuple_BlockHashChannelManagerZ_read(byte[] ser, EntropySource arg_entropy_source, NodeSigner arg_node_signer, SignerProvider arg_signer_provider, FeeEstimator arg_fee_estimator, Watch arg_chain_monitor, BroadcasterInterface arg_tx_broadcaster, Router arg_router, Logger arg_logger, UserConfig arg_default_config, ChannelMonitor[] arg_channel_monitors) {
148 long ret = bindings.C2Tuple_BlockHashChannelManagerZ_read(ser, bindings.ChannelManagerReadArgs_new(arg_entropy_source.ptr, arg_node_signer.ptr, arg_signer_provider.ptr, arg_fee_estimator.ptr, arg_chain_monitor.ptr, arg_tx_broadcaster.ptr, arg_router.ptr, 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));
149 Reference.reachabilityFence(ser);
150 Reference.reachabilityFence(arg_entropy_source);
151 Reference.reachabilityFence(arg_node_signer);
152 Reference.reachabilityFence(arg_signer_provider);
153 Reference.reachabilityFence(arg_fee_estimator);
154 Reference.reachabilityFence(arg_chain_monitor);
155 Reference.reachabilityFence(arg_tx_broadcaster);
156 Reference.reachabilityFence(arg_router);
157 Reference.reachabilityFence(arg_logger);
158 Reference.reachabilityFence(arg_default_config);
159 Reference.reachabilityFence(arg_channel_monitors);
160 if (ret >= 0 && ret <= 4096) { return null; }
161 Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret);
162 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_entropy_source); };
163 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_node_signer); };
164 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_signer_provider); };
165 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_fee_estimator); };
166 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_chain_monitor); };
167 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_tx_broadcaster); };
168 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_router); };
169 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_logger); };
170 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg_default_config); };
171 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); }; };
176 * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment`], but no
177 * `ChannelManager` is required. Useful for generating invoices for [phantom node payments] without
178 * a `ChannelManager`.
180 * `keys` is generated by calling [`NodeSigner::get_inbound_payment_key_material`] and then
181 * calling [`ExpandedKey::new`] with its result. It is recommended to cache this value and not
182 * regenerate it for each new inbound payment.
184 * `current_time` is a Unix timestamp representing the current time.
186 * Note that if `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
187 * on versions of LDK prior to 0.0.114.
189 * [phantom node payments]: crate::sign::PhantomKeysManager
190 * [`NodeSigner::get_inbound_payment_key_material`]: crate::sign::NodeSigner::get_inbound_payment_key_material
192 public static Result_C2Tuple_PaymentHashPaymentSecretZNoneZ create(org.ldk.structs.ExpandedKey keys, org.ldk.structs.Option_u64Z min_value_msat, int invoice_expiry_delta_secs, org.ldk.structs.EntropySource entropy_source, long current_time, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
193 long ret = bindings.create(keys == null ? 0 : keys.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, entropy_source.ptr, current_time, min_final_cltv_expiry_delta.ptr);
194 Reference.reachabilityFence(keys);
195 Reference.reachabilityFence(min_value_msat);
196 Reference.reachabilityFence(invoice_expiry_delta_secs);
197 Reference.reachabilityFence(entropy_source);
198 Reference.reachabilityFence(current_time);
199 Reference.reachabilityFence(min_final_cltv_expiry_delta);
200 if (ret >= 0 && ret <= 4096) { return null; }
201 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
202 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys); };
203 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_value_msat); };
204 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
205 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
210 * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash`],
211 * but no `ChannelManager` is required. Useful for generating invoices for [phantom node payments]
212 * without a `ChannelManager`.
214 * See [`create`] for information on the `keys` and `current_time` parameters.
216 * Note that if `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
217 * on versions of LDK prior to 0.0.114.
219 * [phantom node payments]: crate::sign::PhantomKeysManager
221 public static Result_PaymentSecretNoneZ create_from_hash(org.ldk.structs.ExpandedKey keys, org.ldk.structs.Option_u64Z min_value_msat, byte[] payment_hash, int invoice_expiry_delta_secs, long current_time, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
222 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, min_final_cltv_expiry_delta.ptr);
223 Reference.reachabilityFence(keys);
224 Reference.reachabilityFence(min_value_msat);
225 Reference.reachabilityFence(payment_hash);
226 Reference.reachabilityFence(invoice_expiry_delta_secs);
227 Reference.reachabilityFence(current_time);
228 Reference.reachabilityFence(min_final_cltv_expiry_delta);
229 if (ret >= 0 && ret <= 4096) { return null; }
230 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
231 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys); };
232 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_value_msat); };
233 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
238 * Gets the weight for an HTLC-Success transaction.
240 public static long htlc_success_tx_weight(org.ldk.structs.ChannelTypeFeatures channel_type_features) {
241 long ret = bindings.htlc_success_tx_weight(channel_type_features == null ? 0 : channel_type_features.ptr);
242 Reference.reachabilityFence(channel_type_features);
247 * Gets the weight for an HTLC-Timeout transaction.
249 public static long htlc_timeout_tx_weight(org.ldk.structs.ChannelTypeFeatures channel_type_features) {
250 long ret = bindings.htlc_timeout_tx_weight(channel_type_features == null ? 0 : channel_type_features.ptr);
251 Reference.reachabilityFence(channel_type_features);
256 * Check if a given input witness attempts to claim a HTLC.
258 public static Option_HTLCClaimZ HTLCClaim_from_witness(byte[] witness) {
259 long ret = bindings.HTLCClaim_from_witness(witness);
260 Reference.reachabilityFence(witness);
261 if (ret >= 0 && ret <= 4096) { return null; }
262 org.ldk.structs.Option_HTLCClaimZ ret_hu_conv = org.ldk.structs.Option_HTLCClaimZ.constr_from_ptr(ret);
263 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
268 * Build the commitment secret from the seed and the commitment number
270 public static byte[] build_commitment_secret(byte[] commitment_seed, long idx) {
271 byte[] ret = bindings.build_commitment_secret(InternalUtils.check_arr_len(commitment_seed, 32), idx);
272 Reference.reachabilityFence(commitment_seed);
273 Reference.reachabilityFence(idx);
278 * Build a closing transaction
280 public static byte[] build_closing_transaction(long to_holder_value_sat, long to_counterparty_value_sat, byte[] to_holder_script, byte[] to_counterparty_script, org.ldk.structs.OutPoint funding_outpoint) {
281 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);
282 Reference.reachabilityFence(to_holder_value_sat);
283 Reference.reachabilityFence(to_counterparty_value_sat);
284 Reference.reachabilityFence(to_holder_script);
285 Reference.reachabilityFence(to_counterparty_script);
286 Reference.reachabilityFence(funding_outpoint);
291 * Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
292 * from the base secret and the per_commitment_point.
294 public static byte[] derive_private_key(byte[] per_commitment_point, byte[] base_secret) {
295 byte[] ret = bindings.derive_private_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_secret, 32));
296 Reference.reachabilityFence(per_commitment_point);
297 Reference.reachabilityFence(base_secret);
302 * Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
303 * from the base point and the per_commitment_key. This is the public equivalent of
304 * derive_private_key - using only public keys to derive a public key instead of private keys.
306 public static byte[] derive_public_key(byte[] per_commitment_point, byte[] base_point) {
307 byte[] ret = bindings.derive_public_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_point, 33));
308 Reference.reachabilityFence(per_commitment_point);
309 Reference.reachabilityFence(base_point);
314 * Derives a per-commitment-transaction revocation key from its constituent parts.
316 * Only the cheating participant owns a valid witness to propagate a revoked
317 * commitment transaction, thus per_commitment_secret always come from cheater
318 * and revocation_base_secret always come from punisher, which is the broadcaster
319 * of the transaction spending with this key knowledge.
321 public static byte[] derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret) {
322 byte[] ret = bindings.derive_private_revocation_key(InternalUtils.check_arr_len(per_commitment_secret, 32), InternalUtils.check_arr_len(countersignatory_revocation_base_secret, 32));
323 Reference.reachabilityFence(per_commitment_secret);
324 Reference.reachabilityFence(countersignatory_revocation_base_secret);
329 * Derives a per-commitment-transaction revocation public key from its constituent parts. This is
330 * the public equivalend of derive_private_revocation_key - using only public keys to derive a
331 * public key instead of private keys.
333 * Only the cheating participant owns a valid witness to propagate a revoked
334 * commitment transaction, thus per_commitment_point always come from cheater
335 * and revocation_base_point always come from punisher, which is the broadcaster
336 * of the transaction spending with this key knowledge.
338 * Note that this is infallible iff we trust that at least one of the two input keys are randomly
339 * generated (ie our own).
341 public static byte[] derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point) {
342 byte[] ret = bindings.derive_public_revocation_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(countersignatory_revocation_base_point, 33));
343 Reference.reachabilityFence(per_commitment_point);
344 Reference.reachabilityFence(countersignatory_revocation_base_point);
349 * A script either spendable by the revocation
350 * key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
351 * Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
353 public static byte[] get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key) {
354 byte[] ret = bindings.get_revokeable_redeemscript(InternalUtils.check_arr_len(revocation_key, 33), contest_delay, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33));
355 Reference.reachabilityFence(revocation_key);
356 Reference.reachabilityFence(contest_delay);
357 Reference.reachabilityFence(broadcaster_delayed_payment_key);
362 * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
363 * does not need to have its previous_output_index filled.
365 public static byte[] get_htlc_redeemscript(org.ldk.structs.HTLCOutputInCommitment htlc, org.ldk.structs.ChannelTypeFeatures channel_type_features, org.ldk.structs.TxCreationKeys keys) {
366 byte[] ret = bindings.get_htlc_redeemscript(htlc == null ? 0 : htlc.ptr, channel_type_features == null ? 0 : channel_type_features.ptr, keys == null ? 0 : keys.ptr);
367 Reference.reachabilityFence(htlc);
368 Reference.reachabilityFence(channel_type_features);
369 Reference.reachabilityFence(keys);
374 * Gets the redeemscript for a funding output from the two funding public keys.
375 * Note that the order of funding public keys does not matter.
377 public static byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory) {
378 byte[] ret = bindings.make_funding_redeemscript(InternalUtils.check_arr_len(broadcaster, 33), InternalUtils.check_arr_len(countersignatory, 33));
379 Reference.reachabilityFence(broadcaster);
380 Reference.reachabilityFence(countersignatory);
385 * Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
386 * parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
387 * transaction which needs signing, and can be used to construct an HTLC transaction which is
388 * broadcastable given a counterparty HTLC signature.
390 * Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
391 * commitment transaction).
393 public static byte[] build_htlc_transaction(byte[] commitment_txid, int feerate_per_kw, short contest_delay, org.ldk.structs.HTLCOutputInCommitment htlc, org.ldk.structs.ChannelTypeFeatures channel_type_features, byte[] broadcaster_delayed_payment_key, byte[] revocation_key) {
394 byte[] ret = bindings.build_htlc_transaction(InternalUtils.check_arr_len(commitment_txid, 32), feerate_per_kw, contest_delay, htlc == null ? 0 : htlc.ptr, channel_type_features == null ? 0 : channel_type_features.ptr, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33), InternalUtils.check_arr_len(revocation_key, 33));
395 Reference.reachabilityFence(commitment_txid);
396 Reference.reachabilityFence(feerate_per_kw);
397 Reference.reachabilityFence(contest_delay);
398 Reference.reachabilityFence(htlc);
399 Reference.reachabilityFence(channel_type_features);
400 Reference.reachabilityFence(broadcaster_delayed_payment_key);
401 Reference.reachabilityFence(revocation_key);
406 * Returns the witness required to satisfy and spend a HTLC input.
408 public static byte[] build_htlc_input_witness(byte[] local_sig, byte[] remote_sig, org.ldk.structs.Option_PaymentPreimageZ preimage, byte[] redeem_script, org.ldk.structs.ChannelTypeFeatures channel_type_features) {
409 byte[] ret = bindings.build_htlc_input_witness(InternalUtils.check_arr_len(local_sig, 64), InternalUtils.check_arr_len(remote_sig, 64), preimage.ptr, redeem_script, channel_type_features == null ? 0 : channel_type_features.ptr);
410 Reference.reachabilityFence(local_sig);
411 Reference.reachabilityFence(remote_sig);
412 Reference.reachabilityFence(preimage);
413 Reference.reachabilityFence(redeem_script);
414 Reference.reachabilityFence(channel_type_features);
419 * Gets the witnessScript for the to_remote output when anchors are enabled.
421 public static byte[] get_to_countersignatory_with_anchors_redeemscript(byte[] payment_point) {
422 byte[] ret = bindings.get_to_countersignatory_with_anchors_redeemscript(InternalUtils.check_arr_len(payment_point, 33));
423 Reference.reachabilityFence(payment_point);
428 * Gets the witnessScript for an anchor output from the funding public key.
429 * The witness in the spending input must be:
430 * <BIP 143 funding_signature>
431 * After 16 blocks of confirmation, an alternative satisfying witness could be:
433 * (empty vector required to satisfy compliance with MINIMALIF-standard rule)
435 public static byte[] get_anchor_redeemscript(byte[] funding_pubkey) {
436 byte[] ret = bindings.get_anchor_redeemscript(InternalUtils.check_arr_len(funding_pubkey, 33));
437 Reference.reachabilityFence(funding_pubkey);
442 * Returns the witness required to satisfy and spend an anchor input.
444 public static byte[] build_anchor_input_witness(byte[] funding_key, byte[] funding_sig) {
445 byte[] ret = bindings.build_anchor_input_witness(InternalUtils.check_arr_len(funding_key, 33), InternalUtils.check_arr_len(funding_sig, 64));
446 Reference.reachabilityFence(funding_key);
447 Reference.reachabilityFence(funding_sig);
452 * Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
453 * shared secret first. This prevents on-chain observers from discovering how many commitment
454 * transactions occurred in a channel before it was closed.
456 * This function gets the shared secret from relevant channel public keys and can be used to
457 * \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
459 public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, boolean outbound_from_broadcaster) {
460 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);
461 Reference.reachabilityFence(broadcaster_payment_basepoint);
462 Reference.reachabilityFence(countersignatory_payment_basepoint);
463 Reference.reachabilityFence(outbound_from_broadcaster);
468 * Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
470 public static Result_COption_NetworkUpdateZDecodeErrorZ NetworkUpdate_read(byte[] ser) {
471 long ret = bindings.NetworkUpdate_read(ser);
472 Reference.reachabilityFence(ser);
473 if (ret >= 0 && ret <= 4096) { return null; }
474 Result_COption_NetworkUpdateZDecodeErrorZ ret_hu_conv = Result_COption_NetworkUpdateZDecodeErrorZ.constr_from_ptr(ret);
479 * Verifies the signature of a [`NodeAnnouncement`].
481 * Returns an error if it is invalid.
483 public static Result_NoneLightningErrorZ verify_node_announcement(org.ldk.structs.NodeAnnouncement msg) {
484 long ret = bindings.verify_node_announcement(msg == null ? 0 : msg.ptr);
485 Reference.reachabilityFence(msg);
486 if (ret >= 0 && ret <= 4096) { return null; }
487 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
488 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
493 * Verifies all signatures included in a [`ChannelAnnouncement`].
495 * Returns an error if one of the signatures is invalid.
497 public static Result_NoneLightningErrorZ verify_channel_announcement(org.ldk.structs.ChannelAnnouncement msg) {
498 long ret = bindings.verify_channel_announcement(msg == null ? 0 : msg.ptr);
499 Reference.reachabilityFence(msg);
500 if (ret >= 0 && ret <= 4096) { return null; }
501 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
502 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
507 * Finds a route from us (payer) to the given target node (payee).
509 * If the payee provided features in their invoice, they should be provided via the `payee` field
510 * in the given [`RouteParameters::payment_params`].
511 * Without this, MPP will only be used if the payee's features are available in the network graph.
513 * Private routing paths between a public node and the target may be included in the `payee` field
514 * of [`RouteParameters::payment_params`].
516 * If some channels aren't announced, it may be useful to fill in `first_hops` with the results
517 * from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
518 * from `network_graph` will be ignored, and only those in `first_hops` will be used.
520 * The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
521 * However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
522 * `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
526 * Panics if first_hops contains channels without `short_channel_id`s;
527 * [`ChannelManager::list_usable_channels`] will never include such channels.
529 * [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
530 * [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
531 * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
533 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
535 public static Result_RouteLightningErrorZ find_route(byte[] our_node_pubkey, org.ldk.structs.RouteParameters route_params, org.ldk.structs.NetworkGraph network_graph, @Nullable ChannelDetails[] first_hops, org.ldk.structs.Logger logger, org.ldk.structs.Score scorer, org.ldk.structs.ProbabilisticScoringFeeParameters score_params, byte[] random_seed_bytes) {
536 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.ptr, scorer.ptr, score_params == null ? 0 : score_params.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
537 Reference.reachabilityFence(our_node_pubkey);
538 Reference.reachabilityFence(route_params);
539 Reference.reachabilityFence(network_graph);
540 Reference.reachabilityFence(first_hops);
541 Reference.reachabilityFence(logger);
542 Reference.reachabilityFence(scorer);
543 Reference.reachabilityFence(score_params);
544 Reference.reachabilityFence(random_seed_bytes);
545 if (ret >= 0 && ret <= 4096) { return null; }
546 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
547 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_params); };
548 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
549 if (first_hops != null) { for (ChannelDetails first_hops_conv_16: first_hops) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(first_hops_conv_16); }; } };
550 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
551 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(scorer); };
552 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(score_params); };
557 * Construct a route from us (payer) to the target node (payee) via the given hops (which should
558 * exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
560 * Re-uses logic from `find_route`, so the restrictions described there also apply here.
562 public static Result_RouteLightningErrorZ build_route_from_hops(byte[] our_node_pubkey, byte[][] hops, org.ldk.structs.RouteParameters route_params, org.ldk.structs.NetworkGraph network_graph, org.ldk.structs.Logger logger, byte[] random_seed_bytes) {
563 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.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
564 Reference.reachabilityFence(our_node_pubkey);
565 Reference.reachabilityFence(hops);
566 Reference.reachabilityFence(route_params);
567 Reference.reachabilityFence(network_graph);
568 Reference.reachabilityFence(logger);
569 Reference.reachabilityFence(random_seed_bytes);
570 if (ret >= 0 && ret <= 4096) { return null; }
571 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
572 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_params); };
573 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
574 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
579 * Creates an unsigned [`PartiallySignedTransaction`] which spends the given descriptors to
580 * the given outputs, plus an output to the given change destination (if sufficient
581 * change value remains). The PSBT will have a feerate, at least, of the given value.
583 * The `locktime` argument is used to set the transaction's locktime. If `None`, the
584 * transaction will have a locktime of 0. It it recommended to set this to the current block
585 * height to avoid fee sniping, unless you have some specific reason to use a different
588 * Returns the PSBT and expected max transaction weight.
590 * Returns `Err(())` if the output value is greater than the input value minus required fee,
591 * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
592 * does not match the one we can spend.
594 * We do not enforce that outputs meet the dust limit or that any output scripts are standard.
596 public static Result_C2Tuple_PartiallySignedTransactionusizeZNoneZ SpendableOutputDescriptor_create_spendable_outputs_psbt(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight, org.ldk.structs.Option_PackedLockTimeZ locktime) {
597 long ret = bindings.SpendableOutputDescriptor_create_spendable_outputs_psbt(descriptors != null ? Arrays.stream(descriptors).mapToLong(descriptors_conv_27 -> descriptors_conv_27.ptr).toArray() : null, outputs != null ? Arrays.stream(outputs).mapToLong(outputs_conv_7 -> outputs_conv_7.ptr).toArray() : null, change_destination_script, feerate_sat_per_1000_weight, locktime.ptr);
598 Reference.reachabilityFence(descriptors);
599 Reference.reachabilityFence(outputs);
600 Reference.reachabilityFence(change_destination_script);
601 Reference.reachabilityFence(feerate_sat_per_1000_weight);
602 Reference.reachabilityFence(locktime);
603 if (ret >= 0 && ret <= 4096) { return null; }
604 Result_C2Tuple_PartiallySignedTransactionusizeZNoneZ ret_hu_conv = Result_C2Tuple_PartiallySignedTransactionusizeZNoneZ.constr_from_ptr(ret);
605 for (SpendableOutputDescriptor descriptors_conv_27: descriptors) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(descriptors_conv_27); }; };
606 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(locktime); };
611 * Returns whether `tlv_type` corresponds to a TLV record for Offers.
613 public static boolean OffersMessage_is_known_type(long tlv_type) {
614 boolean ret = bindings.OffersMessage_is_known_type(tlv_type);
615 Reference.reachabilityFence(tlv_type);
620 * Read a PathFailure from a byte array, created by PathFailure_write
622 public static Result_COption_PathFailureZDecodeErrorZ PathFailure_read(byte[] ser) {
623 long ret = bindings.PathFailure_read(ser);
624 Reference.reachabilityFence(ser);
625 if (ret >= 0 && ret <= 4096) { return null; }
626 Result_COption_PathFailureZDecodeErrorZ ret_hu_conv = Result_COption_PathFailureZDecodeErrorZ.constr_from_ptr(ret);
631 * Read a ClosureReason from a byte array, created by ClosureReason_write
633 public static Result_COption_ClosureReasonZDecodeErrorZ ClosureReason_read(byte[] ser) {
634 long ret = bindings.ClosureReason_read(ser);
635 Reference.reachabilityFence(ser);
636 if (ret >= 0 && ret <= 4096) { return null; }
637 Result_COption_ClosureReasonZDecodeErrorZ ret_hu_conv = Result_COption_ClosureReasonZDecodeErrorZ.constr_from_ptr(ret);
642 * Read a HTLCDestination from a byte array, created by HTLCDestination_write
644 public static Result_COption_HTLCDestinationZDecodeErrorZ HTLCDestination_read(byte[] ser) {
645 long ret = bindings.HTLCDestination_read(ser);
646 Reference.reachabilityFence(ser);
647 if (ret >= 0 && ret <= 4096) { return null; }
648 Result_COption_HTLCDestinationZDecodeErrorZ ret_hu_conv = Result_COption_HTLCDestinationZDecodeErrorZ.constr_from_ptr(ret);
653 * Read a Event from a byte array, created by Event_write
655 public static Result_COption_EventZDecodeErrorZ Event_read(byte[] ser) {
656 long ret = bindings.Event_read(ser);
657 Reference.reachabilityFence(ser);
658 if (ret >= 0 && ret <= 4096) { return null; }
659 Result_COption_EventZDecodeErrorZ ret_hu_conv = Result_COption_EventZDecodeErrorZ.constr_from_ptr(ret);
664 * Pays the given [`Bolt11Invoice`], retrying if needed based on [`Retry`].
666 * [`Bolt11Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
667 * as the payment is still pending. If the payment succeeds, you must ensure that a second payment
668 * with the same [`PaymentHash`] is never sent.
670 * If you wish to use a different payment idempotency token, see [`pay_invoice_with_id`].
672 public static Result_PaymentIdPaymentErrorZ pay_invoice(org.ldk.structs.Bolt11Invoice invoice, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
673 long ret = bindings.pay_invoice(invoice == null ? 0 : invoice.ptr, retry_strategy.ptr, channelmanager == null ? 0 : channelmanager.ptr);
674 Reference.reachabilityFence(invoice);
675 Reference.reachabilityFence(retry_strategy);
676 Reference.reachabilityFence(channelmanager);
677 if (ret >= 0 && ret <= 4096) { return null; }
678 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
679 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
680 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
681 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
686 * Pays the given [`Bolt11Invoice`] with a custom idempotency key, retrying if needed based on
689 * Note that idempotency is only guaranteed as long as the payment is still pending. Once the
690 * payment completes or fails, no idempotency guarantees are made.
692 * You should ensure that the [`Bolt11Invoice::payment_hash`] is unique and the same
693 * [`PaymentHash`] has never been paid before.
695 * See [`pay_invoice`] for a variant which uses the [`PaymentHash`] for the idempotency token.
697 public static Result_NonePaymentErrorZ pay_invoice_with_id(org.ldk.structs.Bolt11Invoice invoice, byte[] payment_id, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
698 long ret = bindings.pay_invoice_with_id(invoice == null ? 0 : invoice.ptr, InternalUtils.check_arr_len(payment_id, 32), retry_strategy.ptr, channelmanager == null ? 0 : channelmanager.ptr);
699 Reference.reachabilityFence(invoice);
700 Reference.reachabilityFence(payment_id);
701 Reference.reachabilityFence(retry_strategy);
702 Reference.reachabilityFence(channelmanager);
703 if (ret >= 0 && ret <= 4096) { return null; }
704 Result_NonePaymentErrorZ ret_hu_conv = Result_NonePaymentErrorZ.constr_from_ptr(ret);
705 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
706 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
707 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
712 * Pays the given zero-value [`Bolt11Invoice`] using the given amount, retrying if needed based on
715 * [`Bolt11Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
716 * as the payment is still pending. If the payment succeeds, you must ensure that a second payment
717 * with the same [`PaymentHash`] is never sent.
719 * If you wish to use a different payment idempotency token, see
720 * [`pay_zero_value_invoice_with_id`].
722 public static Result_PaymentIdPaymentErrorZ pay_zero_value_invoice(org.ldk.structs.Bolt11Invoice invoice, long amount_msats, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
723 long ret = bindings.pay_zero_value_invoice(invoice == null ? 0 : invoice.ptr, amount_msats, retry_strategy.ptr, channelmanager == null ? 0 : channelmanager.ptr);
724 Reference.reachabilityFence(invoice);
725 Reference.reachabilityFence(amount_msats);
726 Reference.reachabilityFence(retry_strategy);
727 Reference.reachabilityFence(channelmanager);
728 if (ret >= 0 && ret <= 4096) { return null; }
729 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
730 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
731 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
732 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
737 * Pays the given zero-value [`Bolt11Invoice`] using the given amount and custom idempotency key,
738 * retrying if needed based on [`Retry`].
740 * Note that idempotency is only guaranteed as long as the payment is still pending. Once the
741 * payment completes or fails, no idempotency guarantees are made.
743 * You should ensure that the [`Bolt11Invoice::payment_hash`] is unique and the same
744 * [`PaymentHash`] has never been paid before.
746 * See [`pay_zero_value_invoice`] for a variant which uses the [`PaymentHash`] for the
749 public static Result_NonePaymentErrorZ pay_zero_value_invoice_with_id(org.ldk.structs.Bolt11Invoice invoice, long amount_msats, byte[] payment_id, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
750 long ret = bindings.pay_zero_value_invoice_with_id(invoice == null ? 0 : invoice.ptr, amount_msats, InternalUtils.check_arr_len(payment_id, 32), retry_strategy.ptr, channelmanager == null ? 0 : channelmanager.ptr);
751 Reference.reachabilityFence(invoice);
752 Reference.reachabilityFence(amount_msats);
753 Reference.reachabilityFence(payment_id);
754 Reference.reachabilityFence(retry_strategy);
755 Reference.reachabilityFence(channelmanager);
756 if (ret >= 0 && ret <= 4096) { return null; }
757 Result_NonePaymentErrorZ ret_hu_conv = Result_NonePaymentErrorZ.constr_from_ptr(ret);
758 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
759 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
760 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
765 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
766 * See [`PhantomKeysManager`] for more information on phantom node payments.
768 * `phantom_route_hints` parameter:
769 * Contains channel info for all nodes participating in the phantom invoice
770 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
772 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
773 * updated when a channel becomes disabled or closes
774 * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
775 * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
778 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
779 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
780 * If `None` is provided for `payment_hash`, then one will be created.
782 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
783 * in excess of the current time.
785 * `duration_since_epoch` is the current time since epoch in seconds.
787 * You can specify a custom `min_final_cltv_expiry_delta`, or let LDK default it to
788 * [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. The provided expiry must be at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`] - 3.
789 * Note that LDK will add a buffer of 3 blocks to the delta to allow for up to a few new block
790 * confirmations during routing.
792 * Note that the provided `keys_manager`'s `NodeSigner` implementation must support phantom
793 * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
796 * [`PhantomKeysManager`]: lightning::sign::PhantomKeysManager
797 * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
798 * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
799 * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
800 * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
801 * [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
803 * This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
804 * available and the current time is supplied by the caller.
806 public static Result_Bolt11InvoiceSignOrCreationErrorZ create_phantom_invoice(org.ldk.structs.Option_u64Z amt_msat, org.ldk.structs.Option_PaymentHashZ payment_hash, java.lang.String description, int invoice_expiry_delta_secs, PhantomRouteHints[] phantom_route_hints, org.ldk.structs.EntropySource entropy_source, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.Logger logger, org.ldk.enums.Currency network, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta, long duration_since_epoch) {
807 long ret = bindings.create_phantom_invoice(amt_msat.ptr, payment_hash.ptr, 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, entropy_source.ptr, node_signer.ptr, logger.ptr, network, min_final_cltv_expiry_delta.ptr, duration_since_epoch);
808 Reference.reachabilityFence(amt_msat);
809 Reference.reachabilityFence(payment_hash);
810 Reference.reachabilityFence(description);
811 Reference.reachabilityFence(invoice_expiry_delta_secs);
812 Reference.reachabilityFence(phantom_route_hints);
813 Reference.reachabilityFence(entropy_source);
814 Reference.reachabilityFence(node_signer);
815 Reference.reachabilityFence(logger);
816 Reference.reachabilityFence(network);
817 Reference.reachabilityFence(min_final_cltv_expiry_delta);
818 Reference.reachabilityFence(duration_since_epoch);
819 if (ret >= 0 && ret <= 4096) { return null; }
820 Result_Bolt11InvoiceSignOrCreationErrorZ ret_hu_conv = Result_Bolt11InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
821 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
822 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_hash); };
823 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); }; };
824 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
825 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
826 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
827 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
832 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
833 * See [`PhantomKeysManager`] for more information on phantom node payments.
835 * `phantom_route_hints` parameter:
836 * Contains channel info for all nodes participating in the phantom invoice
837 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
839 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
840 * updated when a channel becomes disabled or closes
841 * Note that the route hints generated from `phantom_route_hints` will be limited to a maximum
842 * of 3 hints to ensure that the invoice can be scanned in a QR code. These hints are selected
843 * in the order that the nodes in `PhantomRouteHints` are specified, selecting one hint per node
844 * until the maximum is hit. Callers may provide as many `PhantomRouteHints::channels` as
845 * desired, but note that some nodes will be trimmed if more than 3 nodes are provided.
847 * `description_hash` is a SHA-256 hash of the description text
849 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
850 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
851 * If `None` is provided for `payment_hash`, then one will be created.
853 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
854 * in excess of the current time.
856 * `duration_since_epoch` is the current time since epoch in seconds.
858 * Note that the provided `keys_manager`'s `NodeSigner` implementation must support phantom
859 * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
862 * [`PhantomKeysManager`]: lightning::sign::PhantomKeysManager
863 * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
864 * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
865 * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
866 * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
868 * This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
869 * available and the current time is supplied by the caller.
871 public static Result_Bolt11InvoiceSignOrCreationErrorZ create_phantom_invoice_with_description_hash(org.ldk.structs.Option_u64Z amt_msat, org.ldk.structs.Option_PaymentHashZ payment_hash, int invoice_expiry_delta_secs, org.ldk.structs.Sha256 description_hash, PhantomRouteHints[] phantom_route_hints, org.ldk.structs.EntropySource entropy_source, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.Logger logger, org.ldk.enums.Currency network, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta, long duration_since_epoch) {
872 long ret = bindings.create_phantom_invoice_with_description_hash(amt_msat.ptr, payment_hash.ptr, 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, entropy_source.ptr, node_signer.ptr, logger.ptr, network, min_final_cltv_expiry_delta.ptr, duration_since_epoch);
873 Reference.reachabilityFence(amt_msat);
874 Reference.reachabilityFence(payment_hash);
875 Reference.reachabilityFence(invoice_expiry_delta_secs);
876 Reference.reachabilityFence(description_hash);
877 Reference.reachabilityFence(phantom_route_hints);
878 Reference.reachabilityFence(entropy_source);
879 Reference.reachabilityFence(node_signer);
880 Reference.reachabilityFence(logger);
881 Reference.reachabilityFence(network);
882 Reference.reachabilityFence(min_final_cltv_expiry_delta);
883 Reference.reachabilityFence(duration_since_epoch);
884 if (ret >= 0 && ret <= 4096) { return null; }
885 Result_Bolt11InvoiceSignOrCreationErrorZ ret_hu_conv = Result_Bolt11InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
886 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
887 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_hash); };
888 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
889 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); }; };
890 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
891 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
892 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
893 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
898 * Utility to construct an invoice. Generally, unless you want to do something like a custom
899 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
900 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
901 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
902 * that the payment secret is valid when the invoice is paid.
904 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
905 * in excess of the current time.
907 * You can specify a custom `min_final_cltv_expiry_delta`, or let LDK default it to
908 * [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. The provided expiry must be at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
909 * Note that LDK will add a buffer of 3 blocks to the delta to allow for up to a few new block
910 * confirmations during routing.
912 * [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
914 public static Result_Bolt11InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.Logger logger, org.ldk.enums.Currency network, org.ldk.structs.Option_u64Z amt_msat, java.lang.String description, int invoice_expiry_delta_secs, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
915 long ret = bindings.create_invoice_from_channelmanager(channelmanager == null ? 0 : channelmanager.ptr, node_signer.ptr, logger.ptr, network, amt_msat.ptr, description, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
916 Reference.reachabilityFence(channelmanager);
917 Reference.reachabilityFence(node_signer);
918 Reference.reachabilityFence(logger);
919 Reference.reachabilityFence(network);
920 Reference.reachabilityFence(amt_msat);
921 Reference.reachabilityFence(description);
922 Reference.reachabilityFence(invoice_expiry_delta_secs);
923 Reference.reachabilityFence(min_final_cltv_expiry_delta);
924 if (ret >= 0 && ret <= 4096) { return null; }
925 Result_Bolt11InvoiceSignOrCreationErrorZ ret_hu_conv = Result_Bolt11InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
926 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
927 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
928 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
929 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
930 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
935 * Utility to construct an invoice. Generally, unless you want to do something like a custom
936 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
937 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
938 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
939 * that the payment secret is valid when the invoice is paid.
940 * Use this variant if you want to pass the `description_hash` to the invoice.
942 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
943 * in excess of the current time.
945 * You can specify a custom `min_final_cltv_expiry_delta`, or let LDK default it to
946 * [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. The provided expiry must be at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
947 * Note that LDK will add a buffer of 3 blocks to the delta to allow for up to a few new block
948 * confirmations during routing.
950 * [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
952 public static Result_Bolt11InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.Logger logger, org.ldk.enums.Currency network, org.ldk.structs.Option_u64Z amt_msat, org.ldk.structs.Sha256 description_hash, int invoice_expiry_delta_secs, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
953 long ret = bindings.create_invoice_from_channelmanager_with_description_hash(channelmanager == null ? 0 : channelmanager.ptr, node_signer.ptr, logger.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
954 Reference.reachabilityFence(channelmanager);
955 Reference.reachabilityFence(node_signer);
956 Reference.reachabilityFence(logger);
957 Reference.reachabilityFence(network);
958 Reference.reachabilityFence(amt_msat);
959 Reference.reachabilityFence(description_hash);
960 Reference.reachabilityFence(invoice_expiry_delta_secs);
961 Reference.reachabilityFence(min_final_cltv_expiry_delta);
962 if (ret >= 0 && ret <= 4096) { return null; }
963 Result_Bolt11InvoiceSignOrCreationErrorZ ret_hu_conv = Result_Bolt11InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
964 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
965 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
966 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
967 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
968 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
969 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
974 * See [`create_invoice_from_channelmanager_with_description_hash`]
975 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
976 * available and the current time is supplied by the caller.
978 public static Result_Bolt11InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.Logger logger, org.ldk.enums.Currency network, org.ldk.structs.Option_u64Z amt_msat, org.ldk.structs.Sha256 description_hash, long duration_since_epoch, int invoice_expiry_delta_secs, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
979 long ret = bindings.create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, node_signer.ptr, logger.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr, duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
980 Reference.reachabilityFence(channelmanager);
981 Reference.reachabilityFence(node_signer);
982 Reference.reachabilityFence(logger);
983 Reference.reachabilityFence(network);
984 Reference.reachabilityFence(amt_msat);
985 Reference.reachabilityFence(description_hash);
986 Reference.reachabilityFence(duration_since_epoch);
987 Reference.reachabilityFence(invoice_expiry_delta_secs);
988 Reference.reachabilityFence(min_final_cltv_expiry_delta);
989 if (ret >= 0 && ret <= 4096) { return null; }
990 Result_Bolt11InvoiceSignOrCreationErrorZ ret_hu_conv = Result_Bolt11InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
991 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
992 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
993 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
994 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
995 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
996 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
1001 * See [`create_invoice_from_channelmanager`]
1002 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
1003 * available and the current time is supplied by the caller.
1005 public static Result_Bolt11InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_and_duration_since_epoch(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.Logger logger, org.ldk.enums.Currency network, org.ldk.structs.Option_u64Z amt_msat, java.lang.String description, long duration_since_epoch, int invoice_expiry_delta_secs, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
1006 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, node_signer.ptr, logger.ptr, network, amt_msat.ptr, description, duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
1007 Reference.reachabilityFence(channelmanager);
1008 Reference.reachabilityFence(node_signer);
1009 Reference.reachabilityFence(logger);
1010 Reference.reachabilityFence(network);
1011 Reference.reachabilityFence(amt_msat);
1012 Reference.reachabilityFence(description);
1013 Reference.reachabilityFence(duration_since_epoch);
1014 Reference.reachabilityFence(invoice_expiry_delta_secs);
1015 Reference.reachabilityFence(min_final_cltv_expiry_delta);
1016 if (ret >= 0 && ret <= 4096) { return null; }
1017 Result_Bolt11InvoiceSignOrCreationErrorZ ret_hu_conv = Result_Bolt11InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
1018 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
1019 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
1020 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
1021 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
1022 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
1027 * See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
1028 * This version allows for providing a custom [`PaymentHash`] for the invoice.
1029 * This may be useful if you're building an on-chain swap or involving another protocol where
1030 * the payment hash is also involved outside the scope of lightning.
1032 public static Result_Bolt11InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.NodeSigner node_signer, org.ldk.structs.Logger logger, org.ldk.enums.Currency network, org.ldk.structs.Option_u64Z amt_msat, java.lang.String description, long duration_since_epoch, int invoice_expiry_delta_secs, byte[] payment_hash, org.ldk.structs.Option_u16Z min_final_cltv_expiry_delta) {
1033 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(channelmanager == null ? 0 : channelmanager.ptr, node_signer.ptr, logger.ptr, network, amt_msat.ptr, description, duration_since_epoch, invoice_expiry_delta_secs, InternalUtils.check_arr_len(payment_hash, 32), min_final_cltv_expiry_delta.ptr);
1034 Reference.reachabilityFence(channelmanager);
1035 Reference.reachabilityFence(node_signer);
1036 Reference.reachabilityFence(logger);
1037 Reference.reachabilityFence(network);
1038 Reference.reachabilityFence(amt_msat);
1039 Reference.reachabilityFence(description);
1040 Reference.reachabilityFence(duration_since_epoch);
1041 Reference.reachabilityFence(invoice_expiry_delta_secs);
1042 Reference.reachabilityFence(payment_hash);
1043 Reference.reachabilityFence(min_final_cltv_expiry_delta);
1044 if (ret >= 0 && ret <= 4096) { return null; }
1045 Result_Bolt11InvoiceSignOrCreationErrorZ ret_hu_conv = Result_Bolt11InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
1046 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
1047 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
1048 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
1049 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
1050 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };