UNPKG

lightningdevkit

Version:
274 lines 12.4 kB
import { Option_u64Z } from '../structs/Option_u64Z.mjs'; import { Result_PaymentParametersDecodeErrorZ } from '../structs/Result_PaymentParametersDecodeErrorZ.mjs'; import { Payee } from '../structs/Payee.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * Information used to route a payment. */ export class PaymentParameters extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.PaymentParameters_free); } /** * Information about the payee, such as their features and route hints for their channels. */ get_payee() { const ret = bindings.PaymentParameters_get_payee(this.ptr); const ret_hu_conv = Payee.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Information about the payee, such as their features and route hints for their channels. */ set_payee(val) { bindings.PaymentParameters_set_payee(this.ptr, CommonBase.get_ptr_of(val)); } /** * Expiration of a payment to the payee, in seconds relative to the UNIX epoch. */ get_expiry_time() { const ret = bindings.PaymentParameters_get_expiry_time(this.ptr); const ret_hu_conv = Option_u64Z.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Expiration of a payment to the payee, in seconds relative to the UNIX epoch. */ set_expiry_time(val) { bindings.PaymentParameters_set_expiry_time(this.ptr, CommonBase.get_ptr_of(val)); } /** * The maximum total CLTV delta we accept for the route. * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`]. */ get_max_total_cltv_expiry_delta() { const ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr); return ret; } /** * The maximum total CLTV delta we accept for the route. * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`]. */ set_max_total_cltv_expiry_delta(val) { bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val); } /** * The maximum number of paths that may be used by (MPP) payments. * Defaults to [`DEFAULT_MAX_PATH_COUNT`]. */ get_max_path_count() { const ret = bindings.PaymentParameters_get_max_path_count(this.ptr); return ret; } /** * The maximum number of paths that may be used by (MPP) payments. * Defaults to [`DEFAULT_MAX_PATH_COUNT`]. */ set_max_path_count(val) { bindings.PaymentParameters_set_max_path_count(this.ptr, val); } /** * The maximum number of [`Path::hops`] in any returned path. * Defaults to [`MAX_PATH_LENGTH_ESTIMATE`]. */ get_max_path_length() { const ret = bindings.PaymentParameters_get_max_path_length(this.ptr); return ret; } /** * The maximum number of [`Path::hops`] in any returned path. * Defaults to [`MAX_PATH_LENGTH_ESTIMATE`]. */ set_max_path_length(val) { bindings.PaymentParameters_set_max_path_length(this.ptr, val); } /** * Selects the maximum share of a channel's total capacity which will be sent over a channel, * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas * a lower value prefers to send larger MPP parts, potentially saturating channels and * increasing failure probability for those paths. * * Note that this restriction will be relaxed during pathfinding after paths which meet this * restriction have been found. While paths which meet this criteria will be searched for, it * is ultimately up to the scorer to select them over other paths. * * A value of 0 will allow payments up to and including a channel's total announced usable * capacity, a value of one will only use up to half its capacity, two 1/4, etc. * * Default value: 2 */ get_max_channel_saturation_power_of_half() { const ret = bindings.PaymentParameters_get_max_channel_saturation_power_of_half(this.ptr); return ret; } /** * Selects the maximum share of a channel's total capacity which will be sent over a channel, * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas * a lower value prefers to send larger MPP parts, potentially saturating channels and * increasing failure probability for those paths. * * Note that this restriction will be relaxed during pathfinding after paths which meet this * restriction have been found. While paths which meet this criteria will be searched for, it * is ultimately up to the scorer to select them over other paths. * * A value of 0 will allow payments up to and including a channel's total announced usable * capacity, a value of one will only use up to half its capacity, two 1/4, etc. * * Default value: 2 */ set_max_channel_saturation_power_of_half(val) { bindings.PaymentParameters_set_max_channel_saturation_power_of_half(this.ptr, val); } /** * A list of SCIDs which this payment was previously attempted over and which caused the * payment to fail. Future attempts for the same payment shouldn't be relayed through any of * these SCIDs. * * Returns a copy of the field. */ get_previously_failed_channels() { const ret = bindings.PaymentParameters_get_previously_failed_channels(this.ptr); const ret_conv = bindings.decodeUint64Array(ret); return ret_conv; } /** * A list of SCIDs which this payment was previously attempted over and which caused the * payment to fail. Future attempts for the same payment shouldn't be relayed through any of * these SCIDs. */ set_previously_failed_channels(val) { bindings.PaymentParameters_set_previously_failed_channels(this.ptr, bindings.encodeUint64Array(val)); } /** * A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this * payment was previously attempted over and which caused the payment to fail. Future attempts * for the same payment shouldn't be relayed through any of these blinded paths. * * Returns a copy of the field. */ get_previously_failed_blinded_path_idxs() { const ret = bindings.PaymentParameters_get_previously_failed_blinded_path_idxs(this.ptr); const ret_conv = bindings.decodeUint64Array(ret); return ret_conv; } /** * A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this * payment was previously attempted over and which caused the payment to fail. Future attempts * for the same payment shouldn't be relayed through any of these blinded paths. */ set_previously_failed_blinded_path_idxs(val) { bindings.PaymentParameters_set_previously_failed_blinded_path_idxs(this.ptr, bindings.encodeUint64Array(val)); } /** * Constructs a new PaymentParameters given each field */ static constructor_new(payee_arg, expiry_time_arg, max_total_cltv_expiry_delta_arg, max_path_count_arg, max_path_length_arg, max_channel_saturation_power_of_half_arg, previously_failed_channels_arg, previously_failed_blinded_path_idxs_arg) { const ret = bindings.PaymentParameters_new(CommonBase.get_ptr_of(payee_arg), CommonBase.get_ptr_of(expiry_time_arg), max_total_cltv_expiry_delta_arg, max_path_count_arg, max_path_length_arg, max_channel_saturation_power_of_half_arg, bindings.encodeUint64Array(previously_failed_channels_arg), bindings.encodeUint64Array(previously_failed_blinded_path_idxs_arg)); const ret_hu_conv = new PaymentParameters(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } clone_ptr() { const ret = bindings.PaymentParameters_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the PaymentParameters */ clone() { const ret = bindings.PaymentParameters_clone(this.ptr); const ret_hu_conv = new PaymentParameters(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the PaymentParameters. */ hash() { const ret = bindings.PaymentParameters_hash(this.ptr); return ret; } /** * Checks if two PaymentParameterss contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. * Two objects with NULL inner values will be considered "equal" here. */ eq(b) { const ret = bindings.PaymentParameters_eq(this.ptr, CommonBase.get_ptr_of(b)); CommonBase.add_ref_from(this, b); return ret; } /** * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read */ write() { const ret = bindings.PaymentParameters_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a PaymentParameters from a byte array, created by PaymentParameters_write */ static constructor_read(ser, arg) { const ret = bindings.PaymentParameters_read(bindings.encodeUint8Array(ser), arg); const ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Creates a payee with the node id of the given `pubkey`. * * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has * provided. */ static constructor_from_node_id(payee_pubkey, final_cltv_expiry_delta) { const ret = bindings.PaymentParameters_from_node_id(bindings.encodeUint8Array(payee_pubkey), final_cltv_expiry_delta); const ret_hu_conv = new PaymentParameters(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Creates a payee with the node id of the given `pubkey` to use for keysend payments. * * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has * provided. * * Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose * whether your router will be allowed to find a multi-part route for this payment. If you * set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via * [`RecipientOnionFields::secret_only`]. * * [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only */ static constructor_for_keysend(payee_pubkey, final_cltv_expiry_delta, allow_mpp) { const ret = bindings.PaymentParameters_for_keysend(bindings.encodeUint8Array(payee_pubkey), final_cltv_expiry_delta, allow_mpp); const ret_hu_conv = new PaymentParameters(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Creates parameters for paying to a blinded payee from the provided invoice. Sets * [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and * [`PaymentParameters::expiry_time`]. */ static constructor_from_bolt12_invoice(invoice) { const ret = bindings.PaymentParameters_from_bolt12_invoice(CommonBase.get_ptr_of(invoice)); const ret_hu_conv = new PaymentParameters(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); CommonBase.add_ref_from(ret_hu_conv, invoice); return ret_hu_conv; } /** * Creates parameters for paying to a blinded payee from the provided blinded route hints. */ static constructor_blinded(blinded_route_hints) { const ret = bindings.PaymentParameters_blinded(bindings.encodeUint64Array(blinded_route_hints.map(blinded_route_hints_conv_20 => CommonBase.get_ptr_of(blinded_route_hints_conv_20)))); const ret_hu_conv = new PaymentParameters(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } } //# sourceMappingURL=PaymentParameters.mjs.map