using org.ldk.impl; using org.ldk.enums; using org.ldk.util; using org.ldk.structs; using System; namespace org { namespace ldk { namespace util { public class UtilMethods { /** * Gets the 128-bit integer, as 16 little-endian bytes */ public static byte[] U128_le_bytes(org.ldk.util.UInt128 val) { byte[] ret = bindings.U128_le_bytes(val.getLEBytes()); GC.KeepAlive(val); return ret; } /** * Constructs a new U128 from 16 little-endian bytes */ public static UInt128 U128_new(byte[] le_bytes) { byte[] ret = bindings.U128_new(InternalUtils.check_arr_len(le_bytes, 16)); GC.KeepAlive(le_bytes); org.ldk.util.UInt128 ret_conv = new org.ldk.util.UInt128(ret); return ret_conv; } /** * Constructs a new COption_NoneZ containing a */ public static COption_NoneZ COption_NoneZ_some() { COption_NoneZ ret = bindings.COption_NoneZ_some(); return ret; } /** * Constructs a new COption_NoneZ containing nothing */ public static COption_NoneZ COption_NoneZ_none() { COption_NoneZ ret = bindings.COption_NoneZ_none(); return ret; } /** * Read a ClosureReason from a byte array, created by ClosureReason_write */ public static Result_COption_ClosureReasonZDecodeErrorZ ClosureReason_read(byte[] ser) { long ret = bindings.ClosureReason_read(ser); GC.KeepAlive(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_COption_ClosureReasonZDecodeErrorZ ret_hu_conv = Result_COption_ClosureReasonZDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Read a HTLCDestination from a byte array, created by HTLCDestination_write */ public static Result_COption_HTLCDestinationZDecodeErrorZ HTLCDestination_read(byte[] ser) { long ret = bindings.HTLCDestination_read(ser); GC.KeepAlive(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_COption_HTLCDestinationZDecodeErrorZ ret_hu_conv = Result_COption_HTLCDestinationZDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Read a Event from a byte array, created by Event_write */ public static Result_COption_EventZDecodeErrorZ Event_read(byte[] ser) { long ret = bindings.Event_read(ser); GC.KeepAlive(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_COption_EventZDecodeErrorZ ret_hu_conv = Result_COption_EventZDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Creates a digital signature of a message given a SecretKey, like the node's secret. * 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. * Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted. */ public static Result_StringErrorZ sign(byte[] msg, byte[] sk) { long ret = bindings.sign(msg, InternalUtils.check_arr_len(sk, 32)); GC.KeepAlive(msg); GC.KeepAlive(sk); if (ret >= 0 && ret <= 4096) { return null; } Result_StringErrorZ ret_hu_conv = Result_StringErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Recovers the PublicKey of the signer of the message given the message and the signature. */ public static Result_PublicKeyErrorZ recover_pk(byte[] msg, string sig) { long ret = bindings.recover_pk(msg, sig); GC.KeepAlive(msg); GC.KeepAlive(sig); if (ret >= 0 && ret <= 4096) { return null; } Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature, * and the PublicKey. */ public static bool verify(byte[] msg, string sig, byte[] pk) { bool ret = bindings.verify(msg, sig, InternalUtils.check_arr_len(pk, 33)); GC.KeepAlive(msg); GC.KeepAlive(sig); GC.KeepAlive(pk); return ret; } /** * Construct the invoice's HRP and signatureless data into a preimage to be hashed. */ public static byte[] construct_invoice_preimage(byte[] hrp_bytes, UInt5[] data_without_signature) { byte[] ret = bindings.construct_invoice_preimage(hrp_bytes, data_without_signature != null ? InternalUtils.convUInt5Array(data_without_signature) : null); GC.KeepAlive(hrp_bytes); GC.KeepAlive(data_without_signature); return ret; } /** * Read a MonitorEvent from a byte array, created by MonitorEvent_write */ public static Result_COption_MonitorEventZDecodeErrorZ MonitorEvent_read(byte[] ser) { long ret = bindings.MonitorEvent_read(ser); GC.KeepAlive(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_COption_MonitorEventZDecodeErrorZ ret_hu_conv = Result_COption_MonitorEventZDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write */ public static Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ C2Tuple_BlockHashChannelMonitorZ_read(byte[] ser, org.ldk.structs.KeysInterface arg) { long ret = bindings.C2Tuple_BlockHashChannelMonitorZ_read(ser, arg == null ? 0 : arg.ptr); GC.KeepAlive(ser); GC.KeepAlive(arg); if (ret >= 0 && ret <= 4096) { return null; } Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg); }; return ret_hu_conv; } /** * Fetches the set of [`NodeFeatures`] flags which are provided by or required by * [`ChannelManager`]. */ public static NodeFeatures provided_node_features() { long ret = bindings.provided_node_features(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.NodeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeFeatures(null, ret); } if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); }; return ret_hu_conv; } /** * Fetches the set of [`ChannelFeatures`] flags which are provided by or required by * [`ChannelManager`]. */ public static ChannelFeatures provided_channel_features() { long ret = bindings.provided_channel_features(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.ChannelFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelFeatures(null, ret); } if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); }; return ret_hu_conv; } /** * Fetches the set of [`InitFeatures`] flags which are provided by or required by * [`ChannelManager`]. */ public static InitFeatures provided_init_features() { long ret = bindings.provided_init_features(); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); } if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); }; return ret_hu_conv; } /** * Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write */ 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) { 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)); GC.KeepAlive(ser); GC.KeepAlive(arg_keys_manager); GC.KeepAlive(arg_fee_estimator); GC.KeepAlive(arg_chain_monitor); GC.KeepAlive(arg_tx_broadcaster); GC.KeepAlive(arg_logger); GC.KeepAlive(arg_default_config); GC.KeepAlive(arg_channel_monitors); if (ret >= 0 && ret <= 4096) { return null; } Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_fee_estimator); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_chain_monitor); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_tx_broadcaster); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_logger); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg_default_config); }; 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); }; }; return ret_hu_conv; } /** * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment`], but no * `ChannelManager` is required. Useful for generating invoices for [phantom node payments] without * a `ChannelManager`. * * `keys` is generated by calling [`KeysInterface::get_inbound_payment_key_material`] and then * calling [`ExpandedKey::new`] with its result. It is recommended to cache this value and not * regenerate it for each new inbound payment. * * `current_time` is a Unix timestamp representing the current time. * * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager */ 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) { 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); GC.KeepAlive(keys); GC.KeepAlive(min_value_msat); GC.KeepAlive(invoice_expiry_delta_secs); GC.KeepAlive(keys_manager); GC.KeepAlive(current_time); if (ret >= 0 && ret <= 4096) { return null; } Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; return ret_hu_conv; } /** * Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash`], * but no `ChannelManager` is required. Useful for generating invoices for [phantom node payments] * without a `ChannelManager`. * * See [`create`] for information on the `keys` and `current_time` parameters. * * [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager */ 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) { 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); GC.KeepAlive(keys); GC.KeepAlive(min_value_msat); GC.KeepAlive(payment_hash); GC.KeepAlive(invoice_expiry_delta_secs); GC.KeepAlive(current_time); if (ret >= 0 && ret <= 4096) { return null; } Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys); }; return ret_hu_conv; } /** * Gets the weight for an HTLC-Success transaction. */ public static long htlc_success_tx_weight(bool opt_anchors) { long ret = bindings.htlc_success_tx_weight(opt_anchors); GC.KeepAlive(opt_anchors); return ret; } /** * Gets the weight for an HTLC-Timeout transaction. */ public static long htlc_timeout_tx_weight(bool opt_anchors) { long ret = bindings.htlc_timeout_tx_weight(opt_anchors); GC.KeepAlive(opt_anchors); return ret; } /** * Check if a given input witness attempts to claim a HTLC. */ public static Option_HTLCClaimZ HTLCClaim_from_witness(byte[] witness) { long ret = bindings.HTLCClaim_from_witness(witness); GC.KeepAlive(witness); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.Option_HTLCClaimZ ret_hu_conv = org.ldk.structs.Option_HTLCClaimZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); }; return ret_hu_conv; } /** * Build the commitment secret from the seed and the commitment number */ public static byte[] build_commitment_secret(byte[] commitment_seed, long idx) { byte[] ret = bindings.build_commitment_secret(InternalUtils.check_arr_len(commitment_seed, 32), idx); GC.KeepAlive(commitment_seed); GC.KeepAlive(idx); return ret; } /** * Build a closing transaction */ 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) { 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); GC.KeepAlive(to_holder_value_sat); GC.KeepAlive(to_counterparty_value_sat); GC.KeepAlive(to_holder_script); GC.KeepAlive(to_counterparty_script); GC.KeepAlive(funding_outpoint); return ret; } /** * Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key) * from the base secret and the per_commitment_point. */ public static byte[] derive_private_key(byte[] per_commitment_point, byte[] base_secret) { byte[] ret = bindings.derive_private_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_secret, 32)); GC.KeepAlive(per_commitment_point); GC.KeepAlive(base_secret); return ret; } /** * Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key) * from the base point and the per_commitment_key. This is the public equivalent of * derive_private_key - using only public keys to derive a public key instead of private keys. */ public static byte[] derive_public_key(byte[] per_commitment_point, byte[] base_point) { byte[] ret = bindings.derive_public_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(base_point, 33)); GC.KeepAlive(per_commitment_point); GC.KeepAlive(base_point); return ret; } /** * Derives a per-commitment-transaction revocation key from its constituent parts. * * Only the cheating participant owns a valid witness to propagate a revoked * commitment transaction, thus per_commitment_secret always come from cheater * and revocation_base_secret always come from punisher, which is the broadcaster * of the transaction spending with this key knowledge. */ public static byte[] derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret) { byte[] ret = bindings.derive_private_revocation_key(InternalUtils.check_arr_len(per_commitment_secret, 32), InternalUtils.check_arr_len(countersignatory_revocation_base_secret, 32)); GC.KeepAlive(per_commitment_secret); GC.KeepAlive(countersignatory_revocation_base_secret); return ret; } /** * Derives a per-commitment-transaction revocation public key from its constituent parts. This is * the public equivalend of derive_private_revocation_key - using only public keys to derive a * public key instead of private keys. * * Only the cheating participant owns a valid witness to propagate a revoked * commitment transaction, thus per_commitment_point always come from cheater * and revocation_base_point always come from punisher, which is the broadcaster * of the transaction spending with this key knowledge. * * Note that this is infallible iff we trust that at least one of the two input keys are randomly * generated (ie our own). */ public static byte[] derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point) { byte[] ret = bindings.derive_public_revocation_key(InternalUtils.check_arr_len(per_commitment_point, 33), InternalUtils.check_arr_len(countersignatory_revocation_base_point, 33)); GC.KeepAlive(per_commitment_point); GC.KeepAlive(countersignatory_revocation_base_point); return ret; } /** * A script either spendable by the revocation * key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. * Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions. */ public static byte[] get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key) { byte[] ret = bindings.get_revokeable_redeemscript(InternalUtils.check_arr_len(revocation_key, 33), contest_delay, InternalUtils.check_arr_len(broadcaster_delayed_payment_key, 33)); GC.KeepAlive(revocation_key); GC.KeepAlive(contest_delay); GC.KeepAlive(broadcaster_delayed_payment_key); return ret; } /** * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc * does not need to have its previous_output_index filled. */ public static byte[] get_htlc_redeemscript(org.ldk.structs.HTLCOutputInCommitment htlc, bool opt_anchors, org.ldk.structs.TxCreationKeys keys) { byte[] ret = bindings.get_htlc_redeemscript(htlc == null ? 0 : htlc.ptr, opt_anchors, keys == null ? 0 : keys.ptr); GC.KeepAlive(htlc); GC.KeepAlive(opt_anchors); GC.KeepAlive(keys); return ret; } /** * Gets the redeemscript for a funding output from the two funding public keys. * Note that the order of funding public keys does not matter. */ public static byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory) { byte[] ret = bindings.make_funding_redeemscript(InternalUtils.check_arr_len(broadcaster, 33), InternalUtils.check_arr_len(countersignatory, 33)); GC.KeepAlive(broadcaster); GC.KeepAlive(countersignatory); return ret; } /** * Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC * parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the * transaction which needs signing, and can be used to construct an HTLC transaction which is * broadcastable given a counterparty HTLC signature. * * Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the * commitment transaction). */ 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) { 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)); GC.KeepAlive(commitment_txid); GC.KeepAlive(feerate_per_kw); GC.KeepAlive(contest_delay); GC.KeepAlive(htlc); GC.KeepAlive(opt_anchors); GC.KeepAlive(use_non_zero_fee_anchors); GC.KeepAlive(broadcaster_delayed_payment_key); GC.KeepAlive(revocation_key); return ret; } /** * Returns the witness required to satisfy and spend a HTLC input. * * Note that preimage (or a relevant inner pointer) may be NULL or all-0s to represent None */ public static byte[] build_htlc_input_witness(byte[] local_sig, byte[] remote_sig, byte[] preimage, byte[] redeem_script, bool opt_anchors) { 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); GC.KeepAlive(local_sig); GC.KeepAlive(remote_sig); GC.KeepAlive(preimage); GC.KeepAlive(redeem_script); GC.KeepAlive(opt_anchors); return ret; } /** * Gets the witnessScript for the to_remote output when anchors are enabled. */ public static byte[] get_to_countersignatory_with_anchors_redeemscript(byte[] payment_point) { byte[] ret = bindings.get_to_countersignatory_with_anchors_redeemscript(InternalUtils.check_arr_len(payment_point, 33)); GC.KeepAlive(payment_point); return ret; } /** * Gets the witnessScript for an anchor output from the funding public key. * The witness in the spending input must be: * * After 16 blocks of confirmation, an alternative satisfying witness could be: * <> * (empty vector required to satisfy compliance with MINIMALIF-standard rule) */ public static byte[] get_anchor_redeemscript(byte[] funding_pubkey) { byte[] ret = bindings.get_anchor_redeemscript(InternalUtils.check_arr_len(funding_pubkey, 33)); GC.KeepAlive(funding_pubkey); return ret; } /** * Returns the witness required to satisfy and spend an anchor input. */ public static byte[] build_anchor_input_witness(byte[] funding_key, byte[] funding_sig) { byte[] ret = bindings.build_anchor_input_witness(InternalUtils.check_arr_len(funding_key, 33), InternalUtils.check_arr_len(funding_sig, 64)); GC.KeepAlive(funding_key); GC.KeepAlive(funding_sig); return ret; } /** * Commitment transaction numbers which appear in the transactions themselves are XOR'd with a * shared secret first. This prevents on-chain observers from discovering how many commitment * transactions occurred in a channel before it was closed. * * This function gets the shared secret from relevant channel public keys and can be used to * \"decrypt\" the commitment transaction number given a commitment transaction on-chain. */ public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, bool outbound_from_broadcaster) { 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); GC.KeepAlive(broadcaster_payment_basepoint); GC.KeepAlive(countersignatory_payment_basepoint); GC.KeepAlive(outbound_from_broadcaster); return ret; } /** * Read a NetworkUpdate from a byte array, created by NetworkUpdate_write */ public static Result_COption_NetworkUpdateZDecodeErrorZ NetworkUpdate_read(byte[] ser) { long ret = bindings.NetworkUpdate_read(ser); GC.KeepAlive(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_COption_NetworkUpdateZDecodeErrorZ ret_hu_conv = Result_COption_NetworkUpdateZDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Finds a route from us (payer) to the given target node (payee). * * If the payee provided features in their invoice, they should be provided via `params.payee`. * Without this, MPP will only be used if the payee's features are available in the network graph. * * Private routing paths between a public node and the target may be included in `params.payee`. * * If some channels aren't announced, it may be useful to fill in `first_hops` with the results * from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels * from `network_graph` will be ignored, and only those in `first_hops` will be used. * * The fees on channels from us to the next hop are ignored as they are assumed to all be equal. * However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` / * `htlc_maximum_msat` *are* checked as they may change based on the receiving node. * * # Note * * May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any * adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this * function. * * # Panics * * Panics if first_hops contains channels without short_channel_ids; * [`ChannelManager::list_usable_channels`] will never include such channels. * * [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed * [`NetworkGraph`]: crate::routing::gossip::NetworkGraph * * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None */ 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) { 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)); GC.KeepAlive(our_node_pubkey); GC.KeepAlive(route_params); GC.KeepAlive(network_graph); GC.KeepAlive(first_hops); GC.KeepAlive(logger); GC.KeepAlive(scorer); GC.KeepAlive(random_seed_bytes); if (ret >= 0 && ret <= 4096) { return null; } Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(route_params); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(network_graph); }; 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); }; } }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(scorer); }; return ret_hu_conv; } /** * Construct a route from us (payer) to the target node (payee) via the given hops (which should * exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path. * * Re-uses logic from `find_route`, so the restrictions described there also apply here. */ 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) { 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)); GC.KeepAlive(our_node_pubkey); GC.KeepAlive(hops); GC.KeepAlive(route_params); GC.KeepAlive(network_graph); GC.KeepAlive(logger); GC.KeepAlive(random_seed_bytes); if (ret >= 0 && ret <= 4096) { return null; } Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(route_params); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(network_graph); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; return ret_hu_conv; } /** * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\" * See [`PhantomKeysManager`] for more information on phantom node payments. * * `phantom_route_hints` parameter: * Contains channel info for all nodes participating in the phantom invoice * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each * participating node * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is * updated when a channel becomes disabled or closes * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared * down * * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]). * If `None` is provided for `payment_hash`, then one will be created. * * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for * in excess of the current time. * * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this * requirement). * * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels * * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None */ 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) { 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); GC.KeepAlive(amt_msat); GC.KeepAlive(payment_hash); GC.KeepAlive(description); GC.KeepAlive(invoice_expiry_delta_secs); GC.KeepAlive(phantom_route_hints); GC.KeepAlive(keys_manager); GC.KeepAlive(logger); GC.KeepAlive(network); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); 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); }; }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; return ret_hu_conv; } /** * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\" * See [`PhantomKeysManager`] for more information on phantom node payments. * * `phantom_route_hints` parameter: * Contains channel info for all nodes participating in the phantom invoice * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each * participating node * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is * updated when a channel becomes disabled or closes * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared * down * * `description_hash` is a SHA-256 hash of the description text * * `payment_hash` can be specified if you have a specific need for a custom payment hash (see the difference * between [`ChannelManager::create_inbound_payment`] and [`ChannelManager::create_inbound_payment_for_hash`]). * If `None` is provided for `payment_hash`, then one will be created. * * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for * in excess of the current time. * * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this * requirement). * * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints * [`ChannelManager::create_inbound_payment`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment * [`ChannelManager::create_inbound_payment_for_hash`]: lightning::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels * * Note that payment_hash (or a relevant inner pointer) may be NULL or all-0s to represent None */ 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) { 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); GC.KeepAlive(amt_msat); GC.KeepAlive(payment_hash); GC.KeepAlive(invoice_expiry_delta_secs); GC.KeepAlive(description_hash); GC.KeepAlive(phantom_route_hints); GC.KeepAlive(keys_manager); GC.KeepAlive(logger); GC.KeepAlive(network); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(description_hash); }; 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); }; }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; return ret_hu_conv; } /** * Utility to construct an invoice. Generally, unless you want to do something like a custom * cltv_expiry, this is what you should be using to create an invoice. The reason being, this * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify * that the payment secret is valid when the invoice is paid. * * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for * in excess of the current time. */ 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) { 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); GC.KeepAlive(channelmanager); GC.KeepAlive(keys_manager); GC.KeepAlive(logger); GC.KeepAlive(network); GC.KeepAlive(amt_msat); GC.KeepAlive(description); GC.KeepAlive(invoice_expiry_delta_secs); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; return ret_hu_conv; } /** * Utility to construct an invoice. Generally, unless you want to do something like a custom * cltv_expiry, this is what you should be using to create an invoice. The reason being, this * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify * that the payment secret is valid when the invoice is paid. * Use this variant if you want to pass the `description_hash` to the invoice. * * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for * in excess of the current time. */ 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) { 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); GC.KeepAlive(channelmanager); GC.KeepAlive(keys_manager); GC.KeepAlive(logger); GC.KeepAlive(network); GC.KeepAlive(amt_msat); GC.KeepAlive(description_hash); GC.KeepAlive(invoice_expiry_delta_secs); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(description_hash); }; return ret_hu_conv; } /** * See [`create_invoice_from_channelmanager_with_description_hash`] * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not * available and the current time is supplied by the caller. */ 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) { 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); GC.KeepAlive(channelmanager); GC.KeepAlive(keys_manager); GC.KeepAlive(logger); GC.KeepAlive(network); GC.KeepAlive(amt_msat); GC.KeepAlive(description_hash); GC.KeepAlive(duration_since_epoch); GC.KeepAlive(invoice_expiry_delta_secs); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(description_hash); }; return ret_hu_conv; } /** * See [`create_invoice_from_channelmanager`] * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not * available and the current time is supplied by the caller. */ 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) { 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); GC.KeepAlive(channelmanager); GC.KeepAlive(keys_manager); GC.KeepAlive(logger); GC.KeepAlive(network); GC.KeepAlive(amt_msat); GC.KeepAlive(description); GC.KeepAlive(duration_since_epoch); GC.KeepAlive(invoice_expiry_delta_secs); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; return ret_hu_conv; } /** * See [`create_invoice_from_channelmanager_and_duration_since_epoch`] * This version allows for providing a custom [`PaymentHash`] for the invoice. * This may be useful if you're building an on-chain swap or involving another protocol where * the payment hash is also involved outside the scope of lightning. */ 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) { 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)); GC.KeepAlive(channelmanager); GC.KeepAlive(keys_manager); GC.KeepAlive(logger); GC.KeepAlive(network); GC.KeepAlive(amt_msat); GC.KeepAlive(description); GC.KeepAlive(duration_since_epoch); GC.KeepAlive(invoice_expiry_delta_secs); GC.KeepAlive(payment_hash); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channelmanager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); }; if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); }; return ret_hu_conv; } } } } }