lightningdevkit
Version:
Lightning Development Kit
91 lines • 3.58 kB
JavaScript
import { LSPSRequestId } from '../structs/LSPSRequestId.mjs';
import { LSPS1Request } from '../structs/LSPS1Request.mjs';
import { LSPS1Response } from '../structs/LSPS1Response.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* An enum that captures all valid JSON-RPC messages in the bLIP-51 / LSPS1 protocol.
*/
export class LSPS1Message extends CommonBase {
constructor(_dummy, ptr) { super(ptr, bindings.LSPS1Message_free); }
/* @internal */
static constr_from_ptr(ptr) {
const raw_ty = bindings.LDKLSPS1Message_ty_from_ptr(ptr);
switch (raw_ty) {
case 0: return new LSPS1Message_Request(ptr);
case 1: return new LSPS1Message_Response(ptr);
default:
throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
}
clone_ptr() {
const ret = bindings.LSPS1Message_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the LSPS1Message
*/
clone() {
const ret = bindings.LSPS1Message_clone(this.ptr);
const ret_hu_conv = LSPS1Message.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Utility method to constructs a new Request-variant LSPS1Message
*/
static constructor_request(a, b) {
const ret = bindings.LSPS1Message_request(CommonBase.get_ptr_of(a), CommonBase.get_ptr_of(b));
const ret_hu_conv = LSPS1Message.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 LSPS1Message
*/
static constructor_response(a, b) {
const ret = bindings.LSPS1Message_response(CommonBase.get_ptr_of(a), CommonBase.get_ptr_of(b));
const ret_hu_conv = LSPS1Message.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Checks if two LSPS1Messages contain equal inner contents.
* This ignores pointers and is_owned flags and looks at the values in fields.
*/
eq(b) {
const ret = bindings.LSPS1Message_eq(this.ptr, CommonBase.get_ptr_of(b));
return ret;
}
}
/** A LSPS1Message of type Request */
export class LSPS1Message_Request extends LSPS1Message {
/* @internal */
constructor(ptr) {
super(null, ptr);
const _0 = bindings.LDKLSPS1Message_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.LDKLSPS1Message_Request_get__1(ptr);
const _1_hu_conv = LSPS1Request.constr_from_ptr(_1);
CommonBase.add_ref_from(_1_hu_conv, this);
this._1 = _1_hu_conv;
}
}
/** A LSPS1Message of type Response */
export class LSPS1Message_Response extends LSPS1Message {
/* @internal */
constructor(ptr) {
super(null, ptr);
const _0 = bindings.LDKLSPS1Message_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.LDKLSPS1Message_Response_get__1(ptr);
const _1_hu_conv = LSPS1Response.constr_from_ptr(_1);
CommonBase.add_ref_from(_1_hu_conv, this);
this._1 = _1_hu_conv;
}
}
//# sourceMappingURL=LSPS1Message.mjs.map