lightningdevkit
Version:
Lightning Development Kit
128 lines • 6.81 kB
JavaScript
import { Option_u64Z } from '../structs/Option_u64Z.mjs';
import { Option_StrZ } from '../structs/Option_StrZ.mjs';
import { LSPSRequestId } from '../structs/LSPSRequestId.mjs';
import { LSPS2OpeningFeeParams } from '../structs/LSPS2OpeningFeeParams.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* An event which an bLIP-52 / LSPS2 server should take some action in response to.
*/
export class LSPS2ServiceEvent extends CommonBase {
constructor(_dummy, ptr) { super(ptr, bindings.LSPS2ServiceEvent_free); }
/* @internal */
static constr_from_ptr(ptr) {
const raw_ty = bindings.LDKLSPS2ServiceEvent_ty_from_ptr(ptr);
switch (raw_ty) {
case 0: return new LSPS2ServiceEvent_GetInfo(ptr);
case 1: return new LSPS2ServiceEvent_BuyRequest(ptr);
case 2: return new LSPS2ServiceEvent_OpenChannel(ptr);
default:
throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
}
clone_ptr() {
const ret = bindings.LSPS2ServiceEvent_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the LSPS2ServiceEvent
*/
clone() {
const ret = bindings.LSPS2ServiceEvent_clone(this.ptr);
const ret_hu_conv = LSPS2ServiceEvent.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Utility method to constructs a new GetInfo-variant LSPS2ServiceEvent
*/
static constructor_get_info(request_id, counterparty_node_id, token) {
const ret = bindings.LSPS2ServiceEvent_get_info(CommonBase.get_ptr_of(request_id), bindings.encodeUint8Array(counterparty_node_id), CommonBase.get_ptr_of(token));
const ret_hu_conv = LSPS2ServiceEvent.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new BuyRequest-variant LSPS2ServiceEvent
*/
static constructor_buy_request(request_id, counterparty_node_id, opening_fee_params, payment_size_msat) {
const ret = bindings.LSPS2ServiceEvent_buy_request(CommonBase.get_ptr_of(request_id), bindings.encodeUint8Array(counterparty_node_id), CommonBase.get_ptr_of(opening_fee_params), CommonBase.get_ptr_of(payment_size_msat));
const ret_hu_conv = LSPS2ServiceEvent.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new OpenChannel-variant LSPS2ServiceEvent
*/
static constructor_open_channel(their_network_key, amt_to_forward_msat, opening_fee_msat, user_channel_id, intercept_scid) {
const ret = bindings.LSPS2ServiceEvent_open_channel(bindings.encodeUint8Array(their_network_key), amt_to_forward_msat, opening_fee_msat, bindings.encodeUint128(user_channel_id), intercept_scid);
const ret_hu_conv = LSPS2ServiceEvent.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Checks if two LSPS2ServiceEvents contain equal inner contents.
* This ignores pointers and is_owned flags and looks at the values in fields.
*/
eq(b) {
const ret = bindings.LSPS2ServiceEvent_eq(this.ptr, CommonBase.get_ptr_of(b));
return ret;
}
}
/** A LSPS2ServiceEvent of type GetInfo */
export class LSPS2ServiceEvent_GetInfo extends LSPS2ServiceEvent {
/* @internal */
constructor(ptr) {
super(null, ptr);
const request_id = bindings.LDKLSPS2ServiceEvent_GetInfo_get_request_id(ptr);
const request_id_hu_conv = new LSPSRequestId(null, request_id);
CommonBase.add_ref_from(request_id_hu_conv, this);
this.request_id = request_id_hu_conv;
const counterparty_node_id = bindings.LDKLSPS2ServiceEvent_GetInfo_get_counterparty_node_id(ptr);
const counterparty_node_id_conv = bindings.decodeUint8Array(counterparty_node_id);
this.counterparty_node_id = counterparty_node_id_conv;
const token = bindings.LDKLSPS2ServiceEvent_GetInfo_get_token(ptr);
const token_hu_conv = Option_StrZ.constr_from_ptr(token);
CommonBase.add_ref_from(token_hu_conv, this);
this.token = token_hu_conv;
}
}
/** A LSPS2ServiceEvent of type BuyRequest */
export class LSPS2ServiceEvent_BuyRequest extends LSPS2ServiceEvent {
/* @internal */
constructor(ptr) {
super(null, ptr);
const request_id = bindings.LDKLSPS2ServiceEvent_BuyRequest_get_request_id(ptr);
const request_id_hu_conv = new LSPSRequestId(null, request_id);
CommonBase.add_ref_from(request_id_hu_conv, this);
this.request_id = request_id_hu_conv;
const counterparty_node_id = bindings.LDKLSPS2ServiceEvent_BuyRequest_get_counterparty_node_id(ptr);
const counterparty_node_id_conv = bindings.decodeUint8Array(counterparty_node_id);
this.counterparty_node_id = counterparty_node_id_conv;
const opening_fee_params = bindings.LDKLSPS2ServiceEvent_BuyRequest_get_opening_fee_params(ptr);
const opening_fee_params_hu_conv = new LSPS2OpeningFeeParams(null, opening_fee_params);
CommonBase.add_ref_from(opening_fee_params_hu_conv, this);
this.opening_fee_params = opening_fee_params_hu_conv;
const payment_size_msat = bindings.LDKLSPS2ServiceEvent_BuyRequest_get_payment_size_msat(ptr);
const payment_size_msat_hu_conv = Option_u64Z.constr_from_ptr(payment_size_msat);
CommonBase.add_ref_from(payment_size_msat_hu_conv, this);
this.payment_size_msat = payment_size_msat_hu_conv;
}
}
/** A LSPS2ServiceEvent of type OpenChannel */
export class LSPS2ServiceEvent_OpenChannel extends LSPS2ServiceEvent {
/* @internal */
constructor(ptr) {
super(null, ptr);
const their_network_key = bindings.LDKLSPS2ServiceEvent_OpenChannel_get_their_network_key(ptr);
const their_network_key_conv = bindings.decodeUint8Array(their_network_key);
this.their_network_key = their_network_key_conv;
this.amt_to_forward_msat = bindings.LDKLSPS2ServiceEvent_OpenChannel_get_amt_to_forward_msat(ptr);
this.opening_fee_msat = bindings.LDKLSPS2ServiceEvent_OpenChannel_get_opening_fee_msat(ptr);
const user_channel_id = bindings.LDKLSPS2ServiceEvent_OpenChannel_get_user_channel_id(ptr);
const user_channel_id_conv = bindings.decodeUint128(user_channel_id);
this.user_channel_id = user_channel_id_conv;
this.intercept_scid = bindings.LDKLSPS2ServiceEvent_OpenChannel_get_intercept_scid(ptr);
}
}
//# sourceMappingURL=LSPS2ServiceEvent.mjs.map