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 == null ? 0 : arg_a.ptr, arg_b == null ? 0 : 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 == null ? 0 : arg_entropy_source.ptr, arg_node_signer == null ? 0 : arg_node_signer.ptr, arg_signer_provider == null ? 0 : arg_signer_provider.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_router == null ? 0 : arg_router.ptr, arg_logger == null ? 0 : arg_logger.ptr, arg_default_config == null ? 0 : arg_default_config.ptr, arg_channel_monitors != null ? Arrays.stream(arg_channel_monitors).mapToLong(arg_channel_monitors_conv_16 -> arg_channel_monitors_conv_16 == null ? 0 : arg_channel_monitors_conv_16.ptr).toArray() : null));
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::chain::keysinterface::PhantomKeysManager
190 * [`NodeSigner::get_inbound_payment_key_material`]: crate::chain::keysinterface::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 == null ? 0 : 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::chain::keysinterface::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(boolean opt_anchors) {
241 long ret = bindings.htlc_success_tx_weight(opt_anchors);
242 Reference.reachabilityFence(opt_anchors);
247 * Gets the weight for an HTLC-Timeout transaction.
249 public static long htlc_timeout_tx_weight(boolean opt_anchors) {
250 long ret = bindings.htlc_timeout_tx_weight(opt_anchors);
251 Reference.reachabilityFence(opt_anchors);
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, boolean opt_anchors, org.ldk.structs.TxCreationKeys keys) {
366 byte[] ret = bindings.get_htlc_redeemscript(htlc == null ? 0 : htlc.ptr, opt_anchors, keys == null ? 0 : keys.ptr);
367 Reference.reachabilityFence(htlc);
368 Reference.reachabilityFence(opt_anchors);
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, boolean opt_anchors, boolean use_non_zero_fee_anchors, 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, opt_anchors, use_non_zero_fee_anchors, 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(opt_anchors);
400 Reference.reachabilityFence(use_non_zero_fee_anchors);
401 Reference.reachabilityFence(broadcaster_delayed_payment_key);
402 Reference.reachabilityFence(revocation_key);
407 * Returns the witness required to satisfy and spend a HTLC input.
409 * Note that preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
411 public static byte[] build_htlc_input_witness(byte[] local_sig, byte[] remote_sig, @Nullable byte[] preimage, byte[] redeem_script, boolean opt_anchors) {
412 byte[] ret = bindings.build_htlc_input_witness(InternalUtils.check_arr_len(local_sig, 64), InternalUtils.check_arr_len(remote_sig, 64), InternalUtils.check_arr_len(preimage, 32), redeem_script, opt_anchors);
413 Reference.reachabilityFence(local_sig);
414 Reference.reachabilityFence(remote_sig);
415 Reference.reachabilityFence(preimage);
416 Reference.reachabilityFence(redeem_script);
417 Reference.reachabilityFence(opt_anchors);
422 * Gets the witnessScript for the to_remote output when anchors are enabled.
424 public static byte[] get_to_countersignatory_with_anchors_redeemscript(byte[] payment_point) {
425 byte[] ret = bindings.get_to_countersignatory_with_anchors_redeemscript(InternalUtils.check_arr_len(payment_point, 33));
426 Reference.reachabilityFence(payment_point);
431 * Gets the witnessScript for an anchor output from the funding public key.
432 * The witness in the spending input must be:
433 * <BIP 143 funding_signature>
434 * After 16 blocks of confirmation, an alternative satisfying witness could be:
436 * (empty vector required to satisfy compliance with MINIMALIF-standard rule)
438 public static byte[] get_anchor_redeemscript(byte[] funding_pubkey) {
439 byte[] ret = bindings.get_anchor_redeemscript(InternalUtils.check_arr_len(funding_pubkey, 33));
440 Reference.reachabilityFence(funding_pubkey);
445 * Returns the witness required to satisfy and spend an anchor input.
447 public static byte[] build_anchor_input_witness(byte[] funding_key, byte[] funding_sig) {
448 byte[] ret = bindings.build_anchor_input_witness(InternalUtils.check_arr_len(funding_key, 33), InternalUtils.check_arr_len(funding_sig, 64));
449 Reference.reachabilityFence(funding_key);
450 Reference.reachabilityFence(funding_sig);
455 * Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
456 * shared secret first. This prevents on-chain observers from discovering how many commitment
457 * transactions occurred in a channel before it was closed.
459 * This function gets the shared secret from relevant channel public keys and can be used to
460 * \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
462 public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, boolean outbound_from_broadcaster) {
463 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);
464 Reference.reachabilityFence(broadcaster_payment_basepoint);
465 Reference.reachabilityFence(countersignatory_payment_basepoint);
466 Reference.reachabilityFence(outbound_from_broadcaster);
471 * Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
473 public static Result_COption_NetworkUpdateZDecodeErrorZ NetworkUpdate_read(byte[] ser) {
474 long ret = bindings.NetworkUpdate_read(ser);
475 Reference.reachabilityFence(ser);
476 if (ret >= 0 && ret <= 4096) { return null; }
477 Result_COption_NetworkUpdateZDecodeErrorZ ret_hu_conv = Result_COption_NetworkUpdateZDecodeErrorZ.constr_from_ptr(ret);
482 * Finds a route from us (payer) to the given target node (payee).
484 * If the payee provided features in their invoice, they should be provided via `params.payee`.
485 * Without this, MPP will only be used if the payee's features are available in the network graph.
487 * Private routing paths between a public node and the target may be included in `params.payee`.
489 * If some channels aren't announced, it may be useful to fill in `first_hops` with the results
490 * from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
491 * from `network_graph` will be ignored, and only those in `first_hops` will be used.
493 * The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
494 * However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
495 * `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
499 * May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
500 * adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
505 * Panics if first_hops contains channels without short_channel_ids;
506 * [`ChannelManager::list_usable_channels`] will never include such channels.
508 * [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
509 * [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
510 * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
512 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
514 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, byte[] random_seed_bytes) {
515 long ret = bindings.find_route(InternalUtils.check_arr_len(our_node_pubkey, 33), route_params == null ? 0 : route_params.ptr, network_graph == null ? 0 : network_graph.ptr, first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr).toArray() : null, logger == null ? 0 : logger.ptr, scorer == null ? 0 : scorer.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
516 Reference.reachabilityFence(our_node_pubkey);
517 Reference.reachabilityFence(route_params);
518 Reference.reachabilityFence(network_graph);
519 Reference.reachabilityFence(first_hops);
520 Reference.reachabilityFence(logger);
521 Reference.reachabilityFence(scorer);
522 Reference.reachabilityFence(random_seed_bytes);
523 if (ret >= 0 && ret <= 4096) { return null; }
524 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
525 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_params); };
526 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
527 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); }; } };
528 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
529 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(scorer); };
534 * Construct a route from us (payer) to the target node (payee) via the given hops (which should
535 * exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
537 * Re-uses logic from `find_route`, so the restrictions described there also apply here.
539 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) {
540 long ret = bindings.build_route_from_hops(InternalUtils.check_arr_len(our_node_pubkey, 33), hops != null ? Arrays.stream(hops).map(hops_conv_8 -> InternalUtils.check_arr_len(hops_conv_8, 33)).toArray(byte[][]::new) : null, route_params == null ? 0 : route_params.ptr, network_graph == null ? 0 : network_graph.ptr, logger == null ? 0 : logger.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
541 Reference.reachabilityFence(our_node_pubkey);
542 Reference.reachabilityFence(hops);
543 Reference.reachabilityFence(route_params);
544 Reference.reachabilityFence(network_graph);
545 Reference.reachabilityFence(logger);
546 Reference.reachabilityFence(random_seed_bytes);
547 if (ret >= 0 && ret <= 4096) { return null; }
548 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
549 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_params); };
550 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
551 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
556 * Read a PathFailure from a byte array, created by PathFailure_write
558 public static Result_COption_PathFailureZDecodeErrorZ PathFailure_read(byte[] ser) {
559 long ret = bindings.PathFailure_read(ser);
560 Reference.reachabilityFence(ser);
561 if (ret >= 0 && ret <= 4096) { return null; }
562 Result_COption_PathFailureZDecodeErrorZ ret_hu_conv = Result_COption_PathFailureZDecodeErrorZ.constr_from_ptr(ret);
567 * Read a ClosureReason from a byte array, created by ClosureReason_write
569 public static Result_COption_ClosureReasonZDecodeErrorZ ClosureReason_read(byte[] ser) {
570 long ret = bindings.ClosureReason_read(ser);
571 Reference.reachabilityFence(ser);
572 if (ret >= 0 && ret <= 4096) { return null; }
573 Result_COption_ClosureReasonZDecodeErrorZ ret_hu_conv = Result_COption_ClosureReasonZDecodeErrorZ.constr_from_ptr(ret);
578 * Read a HTLCDestination from a byte array, created by HTLCDestination_write
580 public static Result_COption_HTLCDestinationZDecodeErrorZ HTLCDestination_read(byte[] ser) {
581 long ret = bindings.HTLCDestination_read(ser);
582 Reference.reachabilityFence(ser);
583 if (ret >= 0 && ret <= 4096) { return null; }
584 Result_COption_HTLCDestinationZDecodeErrorZ ret_hu_conv = Result_COption_HTLCDestinationZDecodeErrorZ.constr_from_ptr(ret);
589 * Read a Event from a byte array, created by Event_write
591 public static Result_COption_EventZDecodeErrorZ Event_read(byte[] ser) {
592 long ret = bindings.Event_read(ser);
593 Reference.reachabilityFence(ser);
594 if (ret >= 0 && ret <= 4096) { return null; }
595 Result_COption_EventZDecodeErrorZ ret_hu_conv = Result_COption_EventZDecodeErrorZ.constr_from_ptr(ret);
600 * Pays the given [`Invoice`], retrying if needed based on [`Retry`].
602 * [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
603 * as the payment is still pending. Once the payment completes or fails, you must ensure that
604 * a second payment with the same [`PaymentHash`] is never sent.
606 * If you wish to use a different payment idempotency token, see [`pay_invoice_with_id`].
608 public static Result_PaymentIdPaymentErrorZ pay_invoice(org.ldk.structs.Invoice invoice, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
609 long ret = bindings.pay_invoice(invoice == null ? 0 : invoice.ptr, retry_strategy.ptr, channelmanager == null ? 0 : channelmanager.ptr);
610 Reference.reachabilityFence(invoice);
611 Reference.reachabilityFence(retry_strategy);
612 Reference.reachabilityFence(channelmanager);
613 if (ret >= 0 && ret <= 4096) { return null; }
614 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
615 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
616 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
617 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
622 * Pays the given [`Invoice`] with a custom idempotency key, retrying if needed based on [`Retry`].
624 * Note that idempotency is only guaranteed as long as the payment is still pending. Once the
625 * payment completes or fails, no idempotency guarantees are made.
627 * You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
628 * has never been paid before.
630 * See [`pay_invoice`] for a variant which uses the [`PaymentHash`] for the idempotency token.
632 public static Result_NonePaymentErrorZ pay_invoice_with_id(org.ldk.structs.Invoice invoice, byte[] payment_id, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
633 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);
634 Reference.reachabilityFence(invoice);
635 Reference.reachabilityFence(payment_id);
636 Reference.reachabilityFence(retry_strategy);
637 Reference.reachabilityFence(channelmanager);
638 if (ret >= 0 && ret <= 4096) { return null; }
639 Result_NonePaymentErrorZ ret_hu_conv = Result_NonePaymentErrorZ.constr_from_ptr(ret);
640 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
641 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
642 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
647 * Pays the given zero-value [`Invoice`] using the given amount, retrying if needed based on
650 * [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
651 * as the payment is still pending. Once the payment completes or fails, you must ensure that
652 * a second payment with the same [`PaymentHash`] is never sent.
654 * If you wish to use a different payment idempotency token, see
655 * [`pay_zero_value_invoice_with_id`].
657 public static Result_PaymentIdPaymentErrorZ pay_zero_value_invoice(org.ldk.structs.Invoice invoice, long amount_msats, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
658 long ret = bindings.pay_zero_value_invoice(invoice == null ? 0 : invoice.ptr, amount_msats, retry_strategy.ptr, channelmanager == null ? 0 : channelmanager.ptr);
659 Reference.reachabilityFence(invoice);
660 Reference.reachabilityFence(amount_msats);
661 Reference.reachabilityFence(retry_strategy);
662 Reference.reachabilityFence(channelmanager);
663 if (ret >= 0 && ret <= 4096) { return null; }
664 Result_PaymentIdPaymentErrorZ ret_hu_conv = Result_PaymentIdPaymentErrorZ.constr_from_ptr(ret);
665 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
666 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
667 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
672 * Pays the given zero-value [`Invoice`] using the given amount and custom idempotency key,
673 * , retrying if needed based on [`Retry`].
675 * Note that idempotency is only guaranteed as long as the payment is still pending. Once the
676 * payment completes or fails, no idempotency guarantees are made.
678 * You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
679 * has never been paid before.
681 * See [`pay_zero_value_invoice`] for a variant which uses the [`PaymentHash`] for the
684 public static Result_NonePaymentErrorZ pay_zero_value_invoice_with_id(org.ldk.structs.Invoice invoice, long amount_msats, byte[] payment_id, org.ldk.structs.Retry retry_strategy, org.ldk.structs.ChannelManager channelmanager) {
685 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);
686 Reference.reachabilityFence(invoice);
687 Reference.reachabilityFence(amount_msats);
688 Reference.reachabilityFence(payment_id);
689 Reference.reachabilityFence(retry_strategy);
690 Reference.reachabilityFence(channelmanager);
691 if (ret >= 0 && ret <= 4096) { return null; }
692 Result_NonePaymentErrorZ ret_hu_conv = Result_NonePaymentErrorZ.constr_from_ptr(ret);
693 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
694 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(retry_strategy); };
695 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
700 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
701 * See [`PhantomKeysManager`] for more information on phantom node payments.
703 * `phantom_route_hints` parameter:
704 * Contains channel info for all nodes participating in the phantom invoice
705 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
707 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
708 * updated when a channel becomes disabled or closes
709 * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
710 * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
713 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
714 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
715 * If `None` is provided for `payment_hash`, then one will be created.
717 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
718 * in excess of the current time.
720 * `duration_since_epoch` is the current time since epoch in seconds.
722 * You can specify a custom `min_final_cltv_expiry_delta`, or let LDK default it to
723 * [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. The provided expiry must be at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`] - 3.
724 * Note that LDK will add a buffer of 3 blocks to the delta to allow for up to a few new block
725 * confirmations during routing.
727 * Note that the provided `keys_manager`'s `NodeSigner` implementation must support phantom
728 * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
731 * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
732 * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
733 * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
734 * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
735 * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
736 * [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
738 * This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
739 * available and the current time is supplied by the caller.
741 * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
743 public static Result_InvoiceSignOrCreationErrorZ create_phantom_invoice(org.ldk.structs.Option_u64Z amt_msat, @Nullable byte[] 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) {
744 long ret = bindings.create_phantom_invoice(amt_msat.ptr, InternalUtils.check_arr_len(payment_hash, 32), description, invoice_expiry_delta_secs, phantom_route_hints != null ? Arrays.stream(phantom_route_hints).mapToLong(phantom_route_hints_conv_19 -> phantom_route_hints_conv_19 == null ? 0 : phantom_route_hints_conv_19.ptr).toArray() : null, entropy_source == null ? 0 : entropy_source.ptr, node_signer == null ? 0 : node_signer.ptr, logger == null ? 0 : logger.ptr, network, min_final_cltv_expiry_delta.ptr, duration_since_epoch);
745 Reference.reachabilityFence(amt_msat);
746 Reference.reachabilityFence(payment_hash);
747 Reference.reachabilityFence(description);
748 Reference.reachabilityFence(invoice_expiry_delta_secs);
749 Reference.reachabilityFence(phantom_route_hints);
750 Reference.reachabilityFence(entropy_source);
751 Reference.reachabilityFence(node_signer);
752 Reference.reachabilityFence(logger);
753 Reference.reachabilityFence(network);
754 Reference.reachabilityFence(min_final_cltv_expiry_delta);
755 Reference.reachabilityFence(duration_since_epoch);
756 if (ret >= 0 && ret <= 4096) { return null; }
757 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
758 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
759 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); }; };
760 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
761 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
762 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
763 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
768 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
769 * See [`PhantomKeysManager`] for more information on phantom node payments.
771 * `phantom_route_hints` parameter:
772 * Contains channel info for all nodes participating in the phantom invoice
773 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
775 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
776 * updated when a channel becomes disabled or closes
777 * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
778 * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
781 * `description_hash` is a SHA-256 hash of the description text
783 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
784 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
785 * If `None` is provided for `payment_hash`, then one will be created.
787 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
788 * in excess of the current time.
790 * `duration_since_epoch` is the current time since epoch in seconds.
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::chain::keysinterface::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
802 * This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
803 * available and the current time is supplied by the caller.
805 * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
807 public static Result_InvoiceSignOrCreationErrorZ create_phantom_invoice_with_description_hash(org.ldk.structs.Option_u64Z amt_msat, @Nullable byte[] 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) {
808 long ret = bindings.create_phantom_invoice_with_description_hash(amt_msat.ptr, InternalUtils.check_arr_len(payment_hash, 32), invoice_expiry_delta_secs, description_hash == null ? 0 : description_hash.ptr, phantom_route_hints != null ? Arrays.stream(phantom_route_hints).mapToLong(phantom_route_hints_conv_19 -> phantom_route_hints_conv_19 == null ? 0 : phantom_route_hints_conv_19.ptr).toArray() : null, entropy_source == null ? 0 : entropy_source.ptr, node_signer == null ? 0 : node_signer.ptr, logger == null ? 0 : logger.ptr, network, min_final_cltv_expiry_delta.ptr, duration_since_epoch);
809 Reference.reachabilityFence(amt_msat);
810 Reference.reachabilityFence(payment_hash);
811 Reference.reachabilityFence(invoice_expiry_delta_secs);
812 Reference.reachabilityFence(description_hash);
813 Reference.reachabilityFence(phantom_route_hints);
814 Reference.reachabilityFence(entropy_source);
815 Reference.reachabilityFence(node_signer);
816 Reference.reachabilityFence(logger);
817 Reference.reachabilityFence(network);
818 Reference.reachabilityFence(min_final_cltv_expiry_delta);
819 Reference.reachabilityFence(duration_since_epoch);
820 if (ret >= 0 && ret <= 4096) { return null; }
821 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
822 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
823 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
824 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); }; };
825 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
826 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
827 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
828 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
833 * Utility to construct an invoice. Generally, unless you want to do something like a custom
834 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
835 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
836 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
837 * that the payment secret is valid when the invoice is paid.
839 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
840 * in excess of the current time.
842 * You can specify a custom `min_final_cltv_expiry_delta`, or let LDK default it to
843 * [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. The provided expiry must be at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
844 * Note that LDK will add a buffer of 3 blocks to the delta to allow for up to a few new block
845 * confirmations during routing.
847 * [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
849 public static Result_InvoiceSignOrCreationErrorZ 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) {
850 long ret = bindings.create_invoice_from_channelmanager(channelmanager == null ? 0 : channelmanager.ptr, node_signer == null ? 0 : node_signer.ptr, logger == null ? 0 : logger.ptr, network, amt_msat.ptr, description, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
851 Reference.reachabilityFence(channelmanager);
852 Reference.reachabilityFence(node_signer);
853 Reference.reachabilityFence(logger);
854 Reference.reachabilityFence(network);
855 Reference.reachabilityFence(amt_msat);
856 Reference.reachabilityFence(description);
857 Reference.reachabilityFence(invoice_expiry_delta_secs);
858 Reference.reachabilityFence(min_final_cltv_expiry_delta);
859 if (ret >= 0 && ret <= 4096) { return null; }
860 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
861 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
862 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
863 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
864 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
865 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
870 * Utility to construct an invoice. Generally, unless you want to do something like a custom
871 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
872 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
873 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
874 * that the payment secret is valid when the invoice is paid.
875 * Use this variant if you want to pass the `description_hash` to the invoice.
877 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
878 * in excess of the current time.
880 * You can specify a custom `min_final_cltv_expiry_delta`, or let LDK default it to
881 * [`MIN_FINAL_CLTV_EXPIRY_DELTA`]. The provided expiry must be at least [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
882 * Note that LDK will add a buffer of 3 blocks to the delta to allow for up to a few new block
883 * confirmations during routing.
885 * [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
887 public static Result_InvoiceSignOrCreationErrorZ 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) {
888 long ret = bindings.create_invoice_from_channelmanager_with_description_hash(channelmanager == null ? 0 : channelmanager.ptr, node_signer == null ? 0 : node_signer.ptr, logger == null ? 0 : logger.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
889 Reference.reachabilityFence(channelmanager);
890 Reference.reachabilityFence(node_signer);
891 Reference.reachabilityFence(logger);
892 Reference.reachabilityFence(network);
893 Reference.reachabilityFence(amt_msat);
894 Reference.reachabilityFence(description_hash);
895 Reference.reachabilityFence(invoice_expiry_delta_secs);
896 Reference.reachabilityFence(min_final_cltv_expiry_delta);
897 if (ret >= 0 && ret <= 4096) { return null; }
898 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
899 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
900 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
901 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
902 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
903 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(description_hash); };
904 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
909 * See [`create_invoice_from_channelmanager_with_description_hash`]
910 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
911 * available and the current time is supplied by the caller.
913 public static Result_InvoiceSignOrCreationErrorZ 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) {
914 long ret = bindings.create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, node_signer == null ? 0 : node_signer.ptr, logger == null ? 0 : 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);
915 Reference.reachabilityFence(channelmanager);
916 Reference.reachabilityFence(node_signer);
917 Reference.reachabilityFence(logger);
918 Reference.reachabilityFence(network);
919 Reference.reachabilityFence(amt_msat);
920 Reference.reachabilityFence(description_hash);
921 Reference.reachabilityFence(duration_since_epoch);
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_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.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(description_hash); };
931 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
936 * See [`create_invoice_from_channelmanager`]
937 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
938 * available and the current time is supplied by the caller.
940 public static Result_InvoiceSignOrCreationErrorZ 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) {
941 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, node_signer == null ? 0 : node_signer.ptr, logger == null ? 0 : logger.ptr, network, amt_msat.ptr, description, duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta.ptr);
942 Reference.reachabilityFence(channelmanager);
943 Reference.reachabilityFence(node_signer);
944 Reference.reachabilityFence(logger);
945 Reference.reachabilityFence(network);
946 Reference.reachabilityFence(amt_msat);
947 Reference.reachabilityFence(description);
948 Reference.reachabilityFence(duration_since_epoch);
949 Reference.reachabilityFence(invoice_expiry_delta_secs);
950 Reference.reachabilityFence(min_final_cltv_expiry_delta);
951 if (ret >= 0 && ret <= 4096) { return null; }
952 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
953 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
954 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
955 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
956 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
957 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };
962 * See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
963 * This version allows for providing a custom [`PaymentHash`] for the invoice.
964 * This may be useful if you're building an on-chain swap or involving another protocol where
965 * the payment hash is also involved outside the scope of lightning.
967 public static Result_InvoiceSignOrCreationErrorZ 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) {
968 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(channelmanager == null ? 0 : channelmanager.ptr, node_signer == null ? 0 : node_signer.ptr, logger == null ? 0 : 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);
969 Reference.reachabilityFence(channelmanager);
970 Reference.reachabilityFence(node_signer);
971 Reference.reachabilityFence(logger);
972 Reference.reachabilityFence(network);
973 Reference.reachabilityFence(amt_msat);
974 Reference.reachabilityFence(description);
975 Reference.reachabilityFence(duration_since_epoch);
976 Reference.reachabilityFence(invoice_expiry_delta_secs);
977 Reference.reachabilityFence(payment_hash);
978 Reference.reachabilityFence(min_final_cltv_expiry_delta);
979 if (ret >= 0 && ret <= 4096) { return null; }
980 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
981 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channelmanager); };
982 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(node_signer); };
983 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
984 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(amt_msat); };
985 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(min_final_cltv_expiry_delta); };