7 namespace org { namespace ldk { namespace util {
8 public class UtilMethods {
10 * Gets the 128-bit integer, as 16 little-endian bytes
12 public static byte[] U128_le_bytes(org.ldk.util.UInt128 val) {
13 byte[] ret = bindings.U128_le_bytes(val.getLEBytes());
19 * Constructs a new U128 from 16 little-endian bytes
21 public static UInt128 U128_new(byte[] le_bytes) {
22 byte[] ret = bindings.U128_new(InternalUtils.check_arr_len(le_bytes, 16));
23 GC.KeepAlive(le_bytes);
24 org.ldk.util.UInt128 ret_conv = new org.ldk.util.UInt128(ret);
29 * Constructs a new COption_NoneZ containing a
31 public static COption_NoneZ COption_NoneZ_some() {
32 COption_NoneZ ret = bindings.COption_NoneZ_some();
37 * Constructs a new COption_NoneZ containing nothing
39 public static COption_NoneZ COption_NoneZ_none() {
40 COption_NoneZ ret = bindings.COption_NoneZ_none();
45 * Read a ClosureReason from a byte array, created by ClosureReason_write
47 public static Result_COption_ClosureReasonZDecodeErrorZ ClosureReason_read(byte[] ser) {
48 long ret = bindings.ClosureReason_read(ser);
50 if (ret >= 0 && ret <= 4096) { return null; }
51 Result_COption_ClosureReasonZDecodeErrorZ ret_hu_conv = Result_COption_ClosureReasonZDecodeErrorZ.constr_from_ptr(ret);
56 * Read a HTLCDestination from a byte array, created by HTLCDestination_write
58 public static Result_COption_HTLCDestinationZDecodeErrorZ HTLCDestination_read(byte[] ser) {
59 long ret = bindings.HTLCDestination_read(ser);
61 if (ret >= 0 && ret <= 4096) { return null; }
62 Result_COption_HTLCDestinationZDecodeErrorZ ret_hu_conv = Result_COption_HTLCDestinationZDecodeErrorZ.constr_from_ptr(ret);
67 * Read a Event from a byte array, created by Event_write
69 public static Result_COption_EventZDecodeErrorZ Event_read(byte[] ser) {
70 long ret = bindings.Event_read(ser);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 Result_COption_EventZDecodeErrorZ ret_hu_conv = Result_COption_EventZDecodeErrorZ.constr_from_ptr(ret);
78 * Creates a digital signature of a message given a SecretKey, like the node's secret.
79 * 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.
80 * Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.
82 public static Result_StringErrorZ sign(byte[] msg, byte[] sk) {
83 long ret = bindings.sign(msg, InternalUtils.check_arr_len(sk, 32));
86 if (ret >= 0 && ret <= 4096) { return null; }
87 Result_StringErrorZ ret_hu_conv = Result_StringErrorZ.constr_from_ptr(ret);
92 * Recovers the PublicKey of the signer of the message given the message and the signature.
94 public static Result_PublicKeyErrorZ recover_pk(byte[] msg, string sig) {
95 long ret = bindings.recover_pk(msg, sig);
98 if (ret >= 0 && ret <= 4096) { return null; }
99 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
104 * Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature,
107 public static bool verify(byte[] msg, string sig, byte[] pk) {
108 bool ret = bindings.verify(msg, sig, InternalUtils.check_arr_len(pk, 33));
116 * Construct the invoice's HRP and signatureless data into a preimage to be hashed.
118 public static byte[] construct_invoice_preimage(byte[] hrp_bytes, UInt5[] data_without_signature) {
119 byte[] ret = bindings.construct_invoice_preimage(hrp_bytes, data_without_signature != null ? InternalUtils.convUInt5Array(data_without_signature) : null);
120 GC.KeepAlive(hrp_bytes);
121 GC.KeepAlive(data_without_signature);
126 * Read a MonitorEvent from a byte array, created by MonitorEvent_write
128 public static Result_COption_MonitorEventZDecodeErrorZ MonitorEvent_read(byte[] ser) {
129 long ret = bindings.MonitorEvent_read(ser);
131 if (ret >= 0 && ret <= 4096) { return null; }
132 Result_COption_MonitorEventZDecodeErrorZ ret_hu_conv = Result_COption_MonitorEventZDecodeErrorZ.constr_from_ptr(ret);
137 * Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
139 public static Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ C2Tuple_BlockHashChannelMonitorZ_read(byte[] ser, org.ldk.structs.KeysInterface arg) {
140 long ret = bindings.C2Tuple_BlockHashChannelMonitorZ_read(ser, arg == null ? 0 : arg.ptr);
143 if (ret >= 0 && ret <= 4096) { return null; }
144 Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.constr_from_ptr(ret);
145 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg); };
150 * Fetches the set of [`NodeFeatures`] flags which are provided by or required by
151 * [`ChannelManager`].
153 public static NodeFeatures provided_node_features() {
154 long ret = bindings.provided_node_features();
155 if (ret >= 0 && ret <= 4096) { return null; }
156 org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); }
157 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
162 * Fetches the set of [`ChannelFeatures`] flags which are provided by or required by
163 * [`ChannelManager`].
165 public static ChannelFeatures provided_channel_features() {
166 long ret = bindings.provided_channel_features();
167 if (ret >= 0 && ret <= 4096) { return null; }
168 org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); }
169 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
174 * Fetches the set of [`InitFeatures`] flags which are provided by or required by
175 * [`ChannelManager`].
177 public static InitFeatures provided_init_features() {
178 long ret = bindings.provided_init_features();
179 if (ret >= 0 && ret <= 4096) { return null; }
180 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
181 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
186 * Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
188 public static Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ C2Tuple_BlockHashChannelManagerZ_read(byte[] ser, KeysInterface arg_keys_manager, FeeEstimator arg_fee_estimator, Watch arg_chain_monitor, BroadcasterInterface arg_tx_broadcaster, Logger arg_logger, UserConfig arg_default_config, ChannelMonitor[] arg_channel_monitors) {
189 long ret = bindings.C2Tuple_BlockHashChannelManagerZ_read(ser, bindings.ChannelManagerReadArgs_new(arg_keys_manager == null ? 0 : arg_keys_manager.ptr, arg_fee_estimator == null ? 0 : arg_fee_estimator.ptr, arg_chain_monitor == null ? 0 : arg_chain_monitor.ptr, arg_tx_broadcaster == null ? 0 : arg_tx_broadcaster.ptr, arg_logger == null ? 0 : arg_logger.ptr, arg_default_config == null ? 0 : arg_default_config.ptr, arg_channel_monitors != null ? InternalUtils.mapArray(arg_channel_monitors, arg_channel_monitors_conv_16 => arg_channel_monitors_conv_16 == null ? 0 : arg_channel_monitors_conv_16.ptr) : null));
191 GC.KeepAlive(arg_keys_manager);
192 GC.KeepAlive(arg_fee_estimator);
193 GC.KeepAlive(arg_chain_monitor);
194 GC.KeepAlive(arg_tx_broadcaster);
195 GC.KeepAlive(arg_logger);
196 GC.KeepAlive(arg_default_config);
197 GC.KeepAlive(arg_channel_monitors);
198 if (ret >= 0 && ret <= 4096) { return null; }
199 Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret);
200 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_keys_manager); };
201 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_fee_estimator); };
202 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_chain_monitor); };
203 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_tx_broadcaster); };
204 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_logger); };
205 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_default_config); };
206 foreach (ChannelMonitor arg_channel_monitors_conv_16 in arg_channel_monitors) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_channel_monitors_conv_16); }; };
211 * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment`], but no
212 * `ChannelManager` is required. Useful for generating invoices for [phantom node payments] without
213 * a `ChannelManager`.
215 * `keys` is generated by calling [`KeysInterface::get_inbound_payment_key_material`] and then
216 * calling [`ExpandedKey::new`] with its result. It is recommended to cache this value and not
217 * regenerate it for each new inbound payment.
219 * `current_time` is a Unix timestamp representing the current time.
221 * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
223 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.KeysInterface keys_manager, long current_time) {
224 long ret = bindings.create(keys == null ? 0 : keys.ptr, min_value_msat.ptr, invoice_expiry_delta_secs, keys_manager == null ? 0 : keys_manager.ptr, current_time);
226 GC.KeepAlive(min_value_msat);
227 GC.KeepAlive(invoice_expiry_delta_secs);
228 GC.KeepAlive(keys_manager);
229 GC.KeepAlive(current_time);
230 if (ret >= 0 && ret <= 4096) { return null; }
231 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
232 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys); };
233 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
238 * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash`],
239 * but no `ChannelManager` is required. Useful for generating invoices for [phantom node payments]
240 * without a `ChannelManager`.
242 * See [`create`] for information on the `keys` and `current_time` parameters.
244 * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
246 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) {
247 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);
249 GC.KeepAlive(min_value_msat);
250 GC.KeepAlive(payment_hash);
251 GC.KeepAlive(invoice_expiry_delta_secs);
252 GC.KeepAlive(current_time);
253 if (ret >= 0 && ret <= 4096) { return null; }
254 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
255 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys); };
260 * Gets the weight for an HTLC-Success transaction.
262 public static long htlc_success_tx_weight(bool opt_anchors) {
263 long ret = bindings.htlc_success_tx_weight(opt_anchors);
264 GC.KeepAlive(opt_anchors);
269 * Gets the weight for an HTLC-Timeout transaction.
271 public static long htlc_timeout_tx_weight(bool opt_anchors) {
272 long ret = bindings.htlc_timeout_tx_weight(opt_anchors);
273 GC.KeepAlive(opt_anchors);
278 * Check if a given input witness attempts to claim a HTLC.
280 public static Option_HTLCClaimZ HTLCClaim_from_witness(byte[] witness) {
281 long ret = bindings.HTLCClaim_from_witness(witness);
282 GC.KeepAlive(witness);
283 if (ret >= 0 && ret <= 4096) { return null; }
284 org.ldk.structs.Option_HTLCClaimZ ret_hu_conv = org.ldk.structs.Option_HTLCClaimZ.constr_from_ptr(ret);
285 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
290 * Build the commitment secret from the seed and the commitment number
292 public static byte[] build_commitment_secret(byte[] commitment_seed, long idx) {
293 byte[] ret = bindings.build_commitment_secret(InternalUtils.check_arr_len(commitment_seed, 32), idx);
294 GC.KeepAlive(commitment_seed);
300 * Build a closing transaction
302 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) {
303 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);
304 GC.KeepAlive(to_holder_value_sat);
305 GC.KeepAlive(to_counterparty_value_sat);
306 GC.KeepAlive(to_holder_script);
307 GC.KeepAlive(to_counterparty_script);
308 GC.KeepAlive(funding_outpoint);
313 * Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
314 * from the base secret and the per_commitment_point.
316 public static byte[] derive_private_key(byte[] per_commitment_point, byte[] base_secret) {
317 byte[] ret = bindings.derive_private_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_secret, 32));
318 GC.KeepAlive(per_commitment_point);
319 GC.KeepAlive(base_secret);
324 * Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
325 * from the base point and the per_commitment_key. This is the public equivalent of
326 * derive_private_key - using only public keys to derive a public key instead of private keys.
328 public static byte[] derive_public_key(byte[] per_commitment_point, byte[] base_point) {
329 byte[] ret = bindings.derive_public_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_point, 33));
330 GC.KeepAlive(per_commitment_point);
331 GC.KeepAlive(base_point);
336 * Derives a per-commitment-transaction revocation key from its constituent parts.
338 * Only the cheating participant owns a valid witness to propagate a revoked
339 * commitment transaction, thus per_commitment_secret always come from cheater
340 * and revocation_base_secret always come from punisher, which is the broadcaster
341 * of the transaction spending with this key knowledge.
343 public static byte[] derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret) {
344 byte[] ret = bindings.derive_private_revocation_key(InternalUtils.check_arr_len(per_commitment_secret, 32), InternalUtils.check_arr_len(countersignatory_revocation_base_secret, 32));
345 GC.KeepAlive(per_commitment_secret);
346 GC.KeepAlive(countersignatory_revocation_base_secret);
351 * Derives a per-commitment-transaction revocation public key from its constituent parts. This is
352 * the public equivalend of derive_private_revocation_key - using only public keys to derive a
353 * public key instead of private keys.
355 * Only the cheating participant owns a valid witness to propagate a revoked
356 * commitment transaction, thus per_commitment_point always come from cheater
357 * and revocation_base_point always come from punisher, which is the broadcaster
358 * of the transaction spending with this key knowledge.
360 * Note that this is infallible iff we trust that at least one of the two input keys are randomly
361 * generated (ie our own).
363 public static byte[] derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point) {
364 byte[] ret = bindings.derive_public_revocation_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(countersignatory_revocation_base_point, 33));
365 GC.KeepAlive(per_commitment_point);
366 GC.KeepAlive(countersignatory_revocation_base_point);
371 * A script either spendable by the revocation
372 * key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
373 * Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
375 public static byte[] get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key) {
376 byte[] ret = bindings.get_revokeable_redeemscript(InternalUtils.check_arr_len(revocation_key, 33), contest_delay, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33));
377 GC.KeepAlive(revocation_key);
378 GC.KeepAlive(contest_delay);
379 GC.KeepAlive(broadcaster_delayed_payment_key);
384 * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
385 * does not need to have its previous_output_index filled.
387 public static byte[] get_htlc_redeemscript(org.ldk.structs.HTLCOutputInCommitment htlc, bool opt_anchors, org.ldk.structs.TxCreationKeys keys) {
388 byte[] ret = bindings.get_htlc_redeemscript(htlc == null ? 0 : htlc.ptr, opt_anchors, keys == null ? 0 : keys.ptr);
390 GC.KeepAlive(opt_anchors);
396 * Gets the redeemscript for a funding output from the two funding public keys.
397 * Note that the order of funding public keys does not matter.
399 public static byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory) {
400 byte[] ret = bindings.make_funding_redeemscript(InternalUtils.check_arr_len(broadcaster, 33), InternalUtils.check_arr_len(countersignatory, 33));
401 GC.KeepAlive(broadcaster);
402 GC.KeepAlive(countersignatory);
407 * Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
408 * parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
409 * transaction which needs signing, and can be used to construct an HTLC transaction which is
410 * broadcastable given a counterparty HTLC signature.
412 * Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
413 * commitment transaction).
415 public static byte[] build_htlc_transaction(byte[] commitment_txid, int feerate_per_kw, short contest_delay, org.ldk.structs.HTLCOutputInCommitment htlc, bool opt_anchors, bool use_non_zero_fee_anchors, byte[] broadcaster_delayed_payment_key, byte[] revocation_key) {
416 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));
417 GC.KeepAlive(commitment_txid);
418 GC.KeepAlive(feerate_per_kw);
419 GC.KeepAlive(contest_delay);
421 GC.KeepAlive(opt_anchors);
422 GC.KeepAlive(use_non_zero_fee_anchors);
423 GC.KeepAlive(broadcaster_delayed_payment_key);
424 GC.KeepAlive(revocation_key);
429 * Returns the witness required to satisfy and spend a HTLC input.
431 * Note that preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
433 public static byte[] build_htlc_input_witness(byte[] local_sig, byte[] remote_sig, byte[] preimage, byte[] redeem_script, bool opt_anchors) {
434 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);
435 GC.KeepAlive(local_sig);
436 GC.KeepAlive(remote_sig);
437 GC.KeepAlive(preimage);
438 GC.KeepAlive(redeem_script);
439 GC.KeepAlive(opt_anchors);
444 * Gets the witnessScript for the to_remote output when anchors are enabled.
446 public static byte[] get_to_countersignatory_with_anchors_redeemscript(byte[] payment_point) {
447 byte[] ret = bindings.get_to_countersignatory_with_anchors_redeemscript(InternalUtils.check_arr_len(payment_point, 33));
448 GC.KeepAlive(payment_point);
453 * Gets the witnessScript for an anchor output from the funding public key.
454 * The witness in the spending input must be:
455 * <BIP 143 funding_signature>
456 * After 16 blocks of confirmation, an alternative satisfying witness could be:
458 * (empty vector required to satisfy compliance with MINIMALIF-standard rule)
460 public static byte[] get_anchor_redeemscript(byte[] funding_pubkey) {
461 byte[] ret = bindings.get_anchor_redeemscript(InternalUtils.check_arr_len(funding_pubkey, 33));
462 GC.KeepAlive(funding_pubkey);
467 * Returns the witness required to satisfy and spend an anchor input.
469 public static byte[] build_anchor_input_witness(byte[] funding_key, byte[] funding_sig) {
470 byte[] ret = bindings.build_anchor_input_witness(InternalUtils.check_arr_len(funding_key, 33), InternalUtils.check_arr_len(funding_sig, 64));
471 GC.KeepAlive(funding_key);
472 GC.KeepAlive(funding_sig);
477 * Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
478 * shared secret first. This prevents on-chain observers from discovering how many commitment
479 * transactions occurred in a channel before it was closed.
481 * This function gets the shared secret from relevant channel public keys and can be used to
482 * \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
484 public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, bool outbound_from_broadcaster) {
485 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);
486 GC.KeepAlive(broadcaster_payment_basepoint);
487 GC.KeepAlive(countersignatory_payment_basepoint);
488 GC.KeepAlive(outbound_from_broadcaster);
493 * Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
495 public static Result_COption_NetworkUpdateZDecodeErrorZ NetworkUpdate_read(byte[] ser) {
496 long ret = bindings.NetworkUpdate_read(ser);
498 if (ret >= 0 && ret <= 4096) { return null; }
499 Result_COption_NetworkUpdateZDecodeErrorZ ret_hu_conv = Result_COption_NetworkUpdateZDecodeErrorZ.constr_from_ptr(ret);
504 * Finds a route from us (payer) to the given target node (payee).
506 * If the payee provided features in their invoice, they should be provided via `params.payee`.
507 * Without this, MPP will only be used if the payee's features are available in the network graph.
509 * Private routing paths between a public node and the target may be included in `params.payee`.
511 * If some channels aren't announced, it may be useful to fill in `first_hops` with the results
512 * from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
513 * from `network_graph` will be ignored, and only those in `first_hops` will be used.
515 * The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
516 * However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
517 * `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
521 * May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
522 * adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
527 * Panics if first_hops contains channels without short_channel_ids;
528 * [`ChannelManager::list_usable_channels`] will never include such channels.
530 * [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
531 * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
532 * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
534 * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
536 public static Result_RouteLightningErrorZ find_route(byte[] our_node_pubkey, org.ldk.structs.RouteParameters route_params, org.ldk.structs.NetworkGraph network_graph, ChannelDetails[] first_hops, org.ldk.structs.Logger logger, org.ldk.structs.Score scorer, byte[] random_seed_bytes) {
537 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 ? InternalUtils.mapArray(first_hops, first_hops_conv_16 => first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr) : null, logger == null ? 0 : logger.ptr, scorer == null ? 0 : scorer.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32));
538 GC.KeepAlive(our_node_pubkey);
539 GC.KeepAlive(route_params);
540 GC.KeepAlive(network_graph);
541 GC.KeepAlive(first_hops);
542 GC.KeepAlive(logger);
543 GC.KeepAlive(scorer);
544 GC.KeepAlive(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.AddLast(route_params); };
548 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(network_graph); };
549 if (first_hops != null) { foreach (ChannelDetails first_hops_conv_16 in first_hops) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(first_hops_conv_16); }; } };
550 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
551 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(scorer); };
556 * Construct a route from us (payer) to the target node (payee) via the given hops (which should
557 * exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
559 * Re-uses logic from `find_route`, so the restrictions described there also apply here.
561 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) {
562 long ret = bindings.build_route_from_hops(InternalUtils.check_arr_len(our_node_pubkey, 33), hops != null ? InternalUtils.mapArray(hops, hops_conv_8 => InternalUtils.check_arr_len(hops_conv_8, 33)) : 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));
563 GC.KeepAlive(our_node_pubkey);
565 GC.KeepAlive(route_params);
566 GC.KeepAlive(network_graph);
567 GC.KeepAlive(logger);
568 GC.KeepAlive(random_seed_bytes);
569 if (ret >= 0 && ret <= 4096) { return null; }
570 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
571 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(route_params); };
572 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(network_graph); };
573 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
578 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
579 * See [`PhantomKeysManager`] for more information on phantom node payments.
581 * `phantom_route_hints` parameter:
582 * Contains channel info for all nodes participating in the phantom invoice
583 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
585 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
586 * updated when a channel becomes disabled or closes
587 * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
588 * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
591 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
592 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
593 * If `None` is provided for `payment_hash`, then one will be created.
595 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
596 * in excess of the current time.
598 * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
599 * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
602 * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
603 * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
604 * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
605 * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
606 * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
608 * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
610 public static Result_InvoiceSignOrCreationErrorZ create_phantom_invoice(org.ldk.structs.Option_u64Z amt_msat, byte[] payment_hash, string description, int invoice_expiry_delta_secs, PhantomRouteHints[] phantom_route_hints, org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.Logger logger, Currency network) {
611 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 ? InternalUtils.mapArray(phantom_route_hints, phantom_route_hints_conv_19 => phantom_route_hints_conv_19 == null ? 0 : phantom_route_hints_conv_19.ptr) : null, keys_manager == null ? 0 : keys_manager.ptr, logger == null ? 0 : logger.ptr, network);
612 GC.KeepAlive(amt_msat);
613 GC.KeepAlive(payment_hash);
614 GC.KeepAlive(description);
615 GC.KeepAlive(invoice_expiry_delta_secs);
616 GC.KeepAlive(phantom_route_hints);
617 GC.KeepAlive(keys_manager);
618 GC.KeepAlive(logger);
619 GC.KeepAlive(network);
620 if (ret >= 0 && ret <= 4096) { return null; }
621 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
622 foreach (PhantomRouteHints phantom_route_hints_conv_19 in phantom_route_hints) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(phantom_route_hints_conv_19); }; };
623 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
624 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
629 * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\"
630 * See [`PhantomKeysManager`] for more information on phantom node payments.
632 * `phantom_route_hints` parameter:
633 * Contains channel info for all nodes participating in the phantom invoice
634 * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each
636 * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is
637 * updated when a channel becomes disabled or closes
638 * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice
639 * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared
642 * `description_hash` is a SHA-256 hash of the description text
644 * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference
645 * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]).
646 * If `None` is provided for `payment_hash`, then one will be created.
648 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
649 * in excess of the current time.
651 * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom
652 * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this
655 * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
656 * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints
657 * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment
658 * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
659 * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels
661 * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None
663 public static Result_InvoiceSignOrCreationErrorZ create_phantom_invoice_with_description_hash(org.ldk.structs.Option_u64Z amt_msat, byte[] payment_hash, int invoice_expiry_delta_secs, org.ldk.structs.Sha256 description_hash, PhantomRouteHints[] phantom_route_hints, org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.Logger logger, Currency network) {
664 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 ? InternalUtils.mapArray(phantom_route_hints, phantom_route_hints_conv_19 => phantom_route_hints_conv_19 == null ? 0 : phantom_route_hints_conv_19.ptr) : null, keys_manager == null ? 0 : keys_manager.ptr, logger == null ? 0 : logger.ptr, network);
665 GC.KeepAlive(amt_msat);
666 GC.KeepAlive(payment_hash);
667 GC.KeepAlive(invoice_expiry_delta_secs);
668 GC.KeepAlive(description_hash);
669 GC.KeepAlive(phantom_route_hints);
670 GC.KeepAlive(keys_manager);
671 GC.KeepAlive(logger);
672 GC.KeepAlive(network);
673 if (ret >= 0 && ret <= 4096) { return null; }
674 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
675 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(description_hash); };
676 foreach (PhantomRouteHints phantom_route_hints_conv_19 in phantom_route_hints) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(phantom_route_hints_conv_19); }; };
677 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
678 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
683 * Utility to construct an invoice. Generally, unless you want to do something like a custom
684 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
685 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
686 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
687 * that the payment secret is valid when the invoice is paid.
689 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
690 * in excess of the current time.
692 public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.Logger logger, Currency network, org.ldk.structs.Option_u64Z amt_msat, string description, int invoice_expiry_delta_secs) {
693 long ret = bindings.create_invoice_from_channelmanager(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, logger == null ? 0 : logger.ptr, network, amt_msat.ptr, description, invoice_expiry_delta_secs);
694 GC.KeepAlive(channelmanager);
695 GC.KeepAlive(keys_manager);
696 GC.KeepAlive(logger);
697 GC.KeepAlive(network);
698 GC.KeepAlive(amt_msat);
699 GC.KeepAlive(description);
700 GC.KeepAlive(invoice_expiry_delta_secs);
701 if (ret >= 0 && ret <= 4096) { return null; }
702 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
703 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); };
704 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
705 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
710 * Utility to construct an invoice. Generally, unless you want to do something like a custom
711 * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
712 * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
713 * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
714 * that the payment secret is valid when the invoice is paid.
715 * Use this variant if you want to pass the `description_hash` to the invoice.
717 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
718 * in excess of the current time.
720 public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.Logger logger, Currency network, org.ldk.structs.Option_u64Z amt_msat, org.ldk.structs.Sha256 description_hash, int invoice_expiry_delta_secs) {
721 long ret = bindings.create_invoice_from_channelmanager_with_description_hash(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, logger == null ? 0 : logger.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr, invoice_expiry_delta_secs);
722 GC.KeepAlive(channelmanager);
723 GC.KeepAlive(keys_manager);
724 GC.KeepAlive(logger);
725 GC.KeepAlive(network);
726 GC.KeepAlive(amt_msat);
727 GC.KeepAlive(description_hash);
728 GC.KeepAlive(invoice_expiry_delta_secs);
729 if (ret >= 0 && ret <= 4096) { return null; }
730 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
731 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); };
732 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
733 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
734 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(description_hash); };
739 * See [`create_invoice_from_channelmanager_with_description_hash`]
740 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
741 * available and the current time is supplied by the caller.
743 public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.Logger logger, Currency network, org.ldk.structs.Option_u64Z amt_msat, org.ldk.structs.Sha256 description_hash, long duration_since_epoch, int invoice_expiry_delta_secs) {
744 long ret = bindings.create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, logger == null ? 0 : logger.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr, duration_since_epoch, invoice_expiry_delta_secs);
745 GC.KeepAlive(channelmanager);
746 GC.KeepAlive(keys_manager);
747 GC.KeepAlive(logger);
748 GC.KeepAlive(network);
749 GC.KeepAlive(amt_msat);
750 GC.KeepAlive(description_hash);
751 GC.KeepAlive(duration_since_epoch);
752 GC.KeepAlive(invoice_expiry_delta_secs);
753 if (ret >= 0 && ret <= 4096) { return null; }
754 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
755 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); };
756 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
757 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
758 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(description_hash); };
763 * See [`create_invoice_from_channelmanager`]
764 * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not
765 * available and the current time is supplied by the caller.
767 public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_and_duration_since_epoch(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.Logger logger, Currency network, org.ldk.structs.Option_u64Z amt_msat, string description, long duration_since_epoch, int invoice_expiry_delta_secs) {
768 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.ptr, logger == null ? 0 : logger.ptr, network, amt_msat.ptr, description, duration_since_epoch, invoice_expiry_delta_secs);
769 GC.KeepAlive(channelmanager);
770 GC.KeepAlive(keys_manager);
771 GC.KeepAlive(logger);
772 GC.KeepAlive(network);
773 GC.KeepAlive(amt_msat);
774 GC.KeepAlive(description);
775 GC.KeepAlive(duration_since_epoch);
776 GC.KeepAlive(invoice_expiry_delta_secs);
777 if (ret >= 0 && ret <= 4096) { return null; }
778 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
779 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); };
780 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
781 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
786 * See [`create_invoice_from_channelmanager_and_duration_since_epoch`]
787 * This version allows for providing a custom [`PaymentHash`] for the invoice.
788 * This may be useful if you're building an on-chain swap or involving another protocol where
789 * the payment hash is also involved outside the scope of lightning.
791 public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(org.ldk.structs.ChannelManager channelmanager, org.ldk.structs.KeysInterface keys_manager, org.ldk.structs.Logger logger, Currency network, org.ldk.structs.Option_u64Z amt_msat, string description, long duration_since_epoch, int invoice_expiry_delta_secs, byte[] payment_hash) {
792 long ret = bindings.create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(channelmanager == null ? 0 : channelmanager.ptr, keys_manager == null ? 0 : keys_manager.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));
793 GC.KeepAlive(channelmanager);
794 GC.KeepAlive(keys_manager);
795 GC.KeepAlive(logger);
796 GC.KeepAlive(network);
797 GC.KeepAlive(amt_msat);
798 GC.KeepAlive(description);
799 GC.KeepAlive(duration_since_epoch);
800 GC.KeepAlive(invoice_expiry_delta_secs);
801 GC.KeepAlive(payment_hash);
802 if (ret >= 0 && ret <= 4096) { return null; }
803 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
804 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); };
805 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
806 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };