lightningdevkit
Version:
Lightning Development Kit
147 lines • 5.91 kB
JavaScript
import { Option_u64Z } from '../structs/Option_u64Z.mjs';
import { Result_NoneNoneZ } from '../structs/Result_NoneNoneZ.mjs';
import { Result_RouteParametersDecodeErrorZ } from '../structs/Result_RouteParametersDecodeErrorZ.mjs';
import { PaymentParameters } from '../structs/PaymentParameters.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* Parameters needed to find a [`Route`].
*
* Passed to [`find_route`] and [`build_route_from_hops`].
*/
export class RouteParameters extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.RouteParameters_free);
}
/**
* The parameters of the failed payment path.
*/
get_payment_params() {
const ret = bindings.RouteParameters_get_payment_params(this.ptr);
const ret_hu_conv = new PaymentParameters(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* The parameters of the failed payment path.
*/
set_payment_params(val) {
bindings.RouteParameters_set_payment_params(this.ptr, CommonBase.get_ptr_of(val));
}
/**
* The amount in msats sent on the failed payment path.
*/
get_final_value_msat() {
const ret = bindings.RouteParameters_get_final_value_msat(this.ptr);
return ret;
}
/**
* The amount in msats sent on the failed payment path.
*/
set_final_value_msat(val) {
bindings.RouteParameters_set_final_value_msat(this.ptr, val);
}
/**
* The maximum total fees, in millisatoshi, that may accrue during route finding.
*
* This limit also applies to the total fees that may arise while retrying failed payment
* paths.
*
* Note that values below a few sats may result in some paths being spuriously ignored.
*/
get_max_total_routing_fee_msat() {
const ret = bindings.RouteParameters_get_max_total_routing_fee_msat(this.ptr);
const ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* The maximum total fees, in millisatoshi, that may accrue during route finding.
*
* This limit also applies to the total fees that may arise while retrying failed payment
* paths.
*
* Note that values below a few sats may result in some paths being spuriously ignored.
*/
set_max_total_routing_fee_msat(val) {
bindings.RouteParameters_set_max_total_routing_fee_msat(this.ptr, CommonBase.get_ptr_of(val));
}
/**
* Constructs a new RouteParameters given each field
*/
static constructor_new(payment_params_arg, final_value_msat_arg, max_total_routing_fee_msat_arg) {
const ret = bindings.RouteParameters_new(CommonBase.get_ptr_of(payment_params_arg), final_value_msat_arg, CommonBase.get_ptr_of(max_total_routing_fee_msat_arg));
const ret_hu_conv = new RouteParameters(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
clone_ptr() {
const ret = bindings.RouteParameters_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the RouteParameters
*/
clone() {
const ret = bindings.RouteParameters_clone(this.ptr);
const ret_hu_conv = new RouteParameters(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Generates a non-cryptographic 64-bit hash of the RouteParameters.
*/
hash() {
const ret = bindings.RouteParameters_hash(this.ptr);
return ret;
}
/**
* Checks if two RouteParameterss 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.RouteParameters_eq(this.ptr, CommonBase.get_ptr_of(b));
CommonBase.add_ref_from(this, b);
return ret;
}
/**
* Constructs [`RouteParameters`] from the given [`PaymentParameters`] and a payment amount.
*
* [`Self::max_total_routing_fee_msat`] defaults to 1% of the payment amount + 50 sats
*/
static constructor_from_payment_params_and_value(payment_params, final_value_msat) {
const ret = bindings.RouteParameters_from_payment_params_and_value(CommonBase.get_ptr_of(payment_params), final_value_msat);
const ret_hu_conv = new RouteParameters(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Sets the maximum number of hops that can be included in a payment path, based on the provided
* [`RecipientOnionFields`] and blinded paths.
*/
set_max_path_length(recipient_onion, is_keysend, best_block_height) {
const ret = bindings.RouteParameters_set_max_path_length(this.ptr, CommonBase.get_ptr_of(recipient_onion), is_keysend, best_block_height);
const ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
CommonBase.add_ref_from(this, recipient_onion);
return ret_hu_conv;
}
/**
* Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
*/
write() {
const ret = bindings.RouteParameters_write(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
/**
* Read a RouteParameters from a byte array, created by RouteParameters_write
*/
static constructor_read(ser) {
const ret = bindings.RouteParameters_read(bindings.encodeUint8Array(ser));
const ret_hu_conv = Result_RouteParametersDecodeErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
}
//# sourceMappingURL=RouteParameters.mjs.map