lightningdevkit
Version:
Lightning Development Kit
91 lines • 3.58 kB
JavaScript
import { LSPSRequestId } from '../structs/LSPSRequestId.mjs';
import { LSPS2Request } from '../structs/LSPS2Request.mjs';
import { LSPS2Response } from '../structs/LSPS2Response.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* An enum that captures all valid JSON-RPC messages in the bLIP-52 / LSPS2 protocol.
*/
export class LSPS2Message extends CommonBase {
constructor(_dummy, ptr) { super(ptr, bindings.LSPS2Message_free); }
/* @internal */
static constr_from_ptr(ptr) {
const raw_ty = bindings.LDKLSPS2Message_ty_from_ptr(ptr);
switch (raw_ty) {
case 0: return new LSPS2Message_Request(ptr);
case 1: return new LSPS2Message_Response(ptr);
default:
throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
}
clone_ptr() {
const ret = bindings.LSPS2Message_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the LSPS2Message
*/
clone() {
const ret = bindings.LSPS2Message_clone(this.ptr);
const ret_hu_conv = LSPS2Message.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Utility method to constructs a new Request-variant LSPS2Message
*/
static constructor_request(a, b) {
const ret = bindings.LSPS2Message_request(CommonBase.get_ptr_of(a), CommonBase.get_ptr_of(b));
const ret_hu_conv = LSPS2Message.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 LSPS2Message
*/
static constructor_response(a, b) {
const ret = bindings.LSPS2Message_response(CommonBase.get_ptr_of(a), CommonBase.get_ptr_of(b));
const ret_hu_conv = LSPS2Message.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Checks if two LSPS2Messages contain equal inner contents.
* This ignores pointers and is_owned flags and looks at the values in fields.
*/
eq(b) {
const ret = bindings.LSPS2Message_eq(this.ptr, CommonBase.get_ptr_of(b));
return ret;
}
}
/** A LSPS2Message of type Request */
export class LSPS2Message_Request extends LSPS2Message {
/* @internal */
constructor(ptr) {
super(null, ptr);
const _0 = bindings.LDKLSPS2Message_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.LDKLSPS2Message_Request_get__1(ptr);
const _1_hu_conv = LSPS2Request.constr_from_ptr(_1);
CommonBase.add_ref_from(_1_hu_conv, this);
this._1 = _1_hu_conv;
}
}
/** A LSPS2Message of type Response */
export class LSPS2Message_Response extends LSPS2Message {
/* @internal */
constructor(ptr) {
super(null, ptr);
const _0 = bindings.LDKLSPS2Message_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.LDKLSPS2Message_Response_get__1(ptr);
const _1_hu_conv = LSPS2Response.constr_from_ptr(_1);
CommonBase.add_ref_from(_1_hu_conv, this);
this._1 = _1_hu_conv;
}
}
//# sourceMappingURL=LSPS2Message.mjs.map