lightningdevkit
Version:
Lightning Development Kit
126 lines • 7.15 kB
JavaScript
import { Result_NoneAPIErrorZ } from '../structs/Result_NoneAPIErrorZ.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* The main object allowing to send and receive bLIP-52 / LSPS2 messages.
*/
export class LSPS2ServiceHandler extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.LSPS2ServiceHandler_free);
}
/**
* Used by LSP to inform a client requesting a JIT Channel the token they used is invalid.
*
* Should be called in response to receiving a [`LSPS2ServiceEvent::GetInfo`] event.
*
* [`LSPS2ServiceEvent::GetInfo`]: crate::lsps2::event::LSPS2ServiceEvent::GetInfo
*/
invalid_token_provided(counterparty_node_id, request_id) {
const ret = bindings.LSPS2ServiceHandler_invalid_token_provided(this.ptr, bindings.encodeUint8Array(counterparty_node_id), CommonBase.get_ptr_of(request_id));
const ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Used by LSP to provide fee parameters to a client requesting a JIT Channel.
*
* Should be called in response to receiving a [`LSPS2ServiceEvent::GetInfo`] event.
*
* [`LSPS2ServiceEvent::GetInfo`]: crate::lsps2::event::LSPS2ServiceEvent::GetInfo
*/
opening_fee_params_generated(counterparty_node_id, request_id, opening_fee_params_menu) {
const ret = bindings.LSPS2ServiceHandler_opening_fee_params_generated(this.ptr, bindings.encodeUint8Array(counterparty_node_id), CommonBase.get_ptr_of(request_id), bindings.encodeUint64Array(opening_fee_params_menu.map(opening_fee_params_menu_conv_26 => CommonBase.get_ptr_of(opening_fee_params_menu_conv_26))));
const ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
opening_fee_params_menu.forEach((opening_fee_params_menu_conv_26) => {
CommonBase.add_ref_from(this, opening_fee_params_menu_conv_26);
// Due to rust's strict-ownership memory model, in some cases we need to "move"
// an object to pass exclusive ownership to the function being called.
// In most cases, we avoid this being visible in GC'd languages by cloning the object
// at the FFI layer, creating a new object which Rust can claim ownership of
// However, in some cases (eg here), there is no way to clone an object, and thus
// we actually have to pass full ownership to Rust.
// Thus, after this call, opening_fee_params_menu_conv_26 is reset to null and is now a dummy object.
CommonBase.set_null_skip_free(opening_fee_params_menu_conv_26);
;
});
return ret_hu_conv;
}
/**
* Used by LSP to provide client with the intercept scid and cltv_expiry_delta to use in their invoice.
*
* Should be called in response to receiving a [`LSPS2ServiceEvent::BuyRequest`] event.
*
* [`LSPS2ServiceEvent::BuyRequest`]: crate::lsps2::event::LSPS2ServiceEvent::BuyRequest
*/
invoice_parameters_generated(counterparty_node_id, request_id, intercept_scid, cltv_expiry_delta, client_trusts_lsp, user_channel_id) {
const ret = bindings.LSPS2ServiceHandler_invoice_parameters_generated(this.ptr, bindings.encodeUint8Array(counterparty_node_id), CommonBase.get_ptr_of(request_id), intercept_scid, cltv_expiry_delta, client_trusts_lsp, bindings.encodeUint128(user_channel_id));
const ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Forward [`Event::HTLCIntercepted`] event parameters into this function.
*
* Will fail the intercepted HTLC if the intercept scid matches a payment we are expecting
* but the payment amount is incorrect or the expiry has passed.
*
* Will generate a [`LSPS2ServiceEvent::OpenChannel`] event if the intercept scid matches a payment we are expected
* and the payment amount is correct and the offer has not expired.
*
* Will do nothing if the intercept scid does not match any of the ones we gave out.
*
* [`Event::HTLCIntercepted`]: lightning::events::Event::HTLCIntercepted
* [`LSPS2ServiceEvent::OpenChannel`]: crate::lsps2::event::LSPS2ServiceEvent::OpenChannel
*/
htlc_intercepted(intercept_scid, intercept_id, expected_outbound_amount_msat, payment_hash) {
const ret = bindings.LSPS2ServiceHandler_htlc_intercepted(this.ptr, intercept_scid, bindings.encodeUint8Array(intercept_id), expected_outbound_amount_msat, bindings.encodeUint8Array(payment_hash));
const ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Forward [`Event::HTLCHandlingFailed`] event parameter into this function.
*
* Will attempt to forward the next payment in the queue if one is present.
* Will do nothing if the intercept scid does not match any of the ones we gave out
* or if the payment queue is empty
*
* [`Event::HTLCHandlingFailed`]: lightning::events::Event::HTLCHandlingFailed
*/
htlc_handling_failed(failed_next_destination) {
const ret = bindings.LSPS2ServiceHandler_htlc_handling_failed(this.ptr, CommonBase.get_ptr_of(failed_next_destination));
const ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Forward [`Event::PaymentForwarded`] event parameter into this function.
*
* Will register the forwarded payment as having paid the JIT channel fee, and forward any held
* and future HTLCs for the SCID of the initial invoice. In the future, this will verify the
* `skimmed_fee_msat` in [`Event::PaymentForwarded`].
*
* Note that `next_channel_id` is required to be provided. Therefore, the corresponding
* [`Event::PaymentForwarded`] events need to be generated and serialized by LDK versions
* greater or equal to 0.0.107.
*
* [`Event::PaymentForwarded`]: lightning::events::Event::PaymentForwarded
*/
payment_forwarded(next_channel_id) {
const ret = bindings.LSPS2ServiceHandler_payment_forwarded(this.ptr, CommonBase.get_ptr_of(next_channel_id));
const ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Forward [`Event::ChannelReady`] event parameters into this function.
*
* Will forward the intercepted HTLC if it matches a channel
* we need to forward a payment over otherwise it will be ignored.
*
* [`Event::ChannelReady`]: lightning::events::Event::ChannelReady
*/
channel_ready(user_channel_id, channel_id, counterparty_node_id) {
const ret = bindings.LSPS2ServiceHandler_channel_ready(this.ptr, bindings.encodeUint128(user_channel_id), CommonBase.get_ptr_of(channel_id), bindings.encodeUint8Array(counterparty_node_id));
const ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
CommonBase.add_ref_from(this, channel_id);
return ret_hu_conv;
}
}
//# sourceMappingURL=LSPS2ServiceHandler.mjs.map