lightningdevkit
Version:
Lightning Development Kit
95 lines • 3.71 kB
JavaScript
import { LSPSRequestId } from '../structs/LSPSRequestId.mjs';
import { LSPS0Request } from '../structs/LSPS0Request.mjs';
import { LSPS0Response } from '../structs/LSPS0Response.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* An bLIP-50 / LSPS0 protocol message.
*
* Please refer to the [bLIP-50 / LSPS0
* specification](https://github.com/lightning/blips/blob/master/blip-0050.md#lsps-specification-support-query)
* for more information.
*/
export class LSPS0Message extends CommonBase {
constructor(_dummy, ptr) { super(ptr, bindings.LSPS0Message_free); }
/* @internal */
static constr_from_ptr(ptr) {
const raw_ty = bindings.LDKLSPS0Message_ty_from_ptr(ptr);
switch (raw_ty) {
case 0: return new LSPS0Message_Request(ptr);
case 1: return new LSPS0Message_Response(ptr);
default:
throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
}
clone_ptr() {
const ret = bindings.LSPS0Message_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the LSPS0Message
*/
clone() {
const ret = bindings.LSPS0Message_clone(this.ptr);
const ret_hu_conv = LSPS0Message.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Utility method to constructs a new Request-variant LSPS0Message
*/
static constructor_request(a, b) {
const ret = bindings.LSPS0Message_request(CommonBase.get_ptr_of(a), CommonBase.get_ptr_of(b));
const ret_hu_conv = LSPS0Message.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new Response-variant LSPS0Message
*/
static constructor_response(a, b) {
const ret = bindings.LSPS0Message_response(CommonBase.get_ptr_of(a), CommonBase.get_ptr_of(b));
const ret_hu_conv = LSPS0Message.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Checks if two LSPS0Messages contain equal inner contents.
* This ignores pointers and is_owned flags and looks at the values in fields.
*/
eq(b) {
const ret = bindings.LSPS0Message_eq(this.ptr, CommonBase.get_ptr_of(b));
return ret;
}
}
/** A LSPS0Message of type Request */
export class LSPS0Message_Request extends LSPS0Message {
/* @internal */
constructor(ptr) {
super(null, ptr);
const _0 = bindings.LDKLSPS0Message_Request_get__0(ptr);
const _0_hu_conv = new LSPSRequestId(null, _0);
CommonBase.add_ref_from(_0_hu_conv, this);
this._0 = _0_hu_conv;
const _1 = bindings.LDKLSPS0Message_Request_get__1(ptr);
const _1_hu_conv = LSPS0Request.constr_from_ptr(_1);
CommonBase.add_ref_from(_1_hu_conv, this);
this._1 = _1_hu_conv;
}
}
/** A LSPS0Message of type Response */
export class LSPS0Message_Response extends LSPS0Message {
/* @internal */
constructor(ptr) {
super(null, ptr);
const _0 = bindings.LDKLSPS0Message_Response_get__0(ptr);
const _0_hu_conv = new LSPSRequestId(null, _0);
CommonBase.add_ref_from(_0_hu_conv, this);
this._0 = _0_hu_conv;
const _1 = bindings.LDKLSPS0Message_Response_get__1(ptr);
const _1_hu_conv = LSPS0Response.constr_from_ptr(_1);
CommonBase.add_ref_from(_1_hu_conv, this);
this._1 = _1_hu_conv;
}
}
//# sourceMappingURL=LSPS0Message.mjs.map