UNPKG

lightningdevkit

Version:
96 lines 3.55 kB
import { BlindedMessagePath } from '../structs/BlindedMessagePath.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * The destination of an onion message. */ export class Destination extends CommonBase { constructor(_dummy, ptr) { super(ptr, bindings.Destination_free); } /* @internal */ static constr_from_ptr(ptr) { const raw_ty = bindings.LDKDestination_ty_from_ptr(ptr); switch (raw_ty) { case 0: return new Destination_Node(ptr); case 1: return new Destination_BlindedPath(ptr); default: throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } } clone_ptr() { const ret = bindings.Destination_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the Destination */ clone() { const ret = bindings.Destination_clone(this.ptr); const ret_hu_conv = Destination.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Utility method to constructs a new Node-variant Destination */ static constructor_node(a) { const ret = bindings.Destination_node(bindings.encodeUint8Array(a)); const ret_hu_conv = Destination.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Utility method to constructs a new BlindedPath-variant Destination */ static constructor_blinded_path(a) { const ret = bindings.Destination_blinded_path(CommonBase.get_ptr_of(a)); const ret_hu_conv = Destination.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the Destination. */ hash() { const ret = bindings.Destination_hash(this.ptr); return ret; } /** * Checks if two Destinations contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. */ eq(b) { const ret = bindings.Destination_eq(this.ptr, CommonBase.get_ptr_of(b)); return ret; } /** * Attempts to resolve the [`IntroductionNode::DirectedShortChannelId`] of a * [`Destination::BlindedPath`] to a [`IntroductionNode::NodeId`], if applicable, using the * provided [`ReadOnlyNetworkGraph`]. */ resolve(network_graph) { bindings.Destination_resolve(this.ptr, CommonBase.get_ptr_of(network_graph)); CommonBase.add_ref_from(this, network_graph); } } /** A Destination of type Node */ export class Destination_Node extends Destination { /* @internal */ constructor(ptr) { super(null, ptr); const node = bindings.LDKDestination_Node_get_node(ptr); const node_conv = bindings.decodeUint8Array(node); this.node = node_conv; } } /** A Destination of type BlindedPath */ export class Destination_BlindedPath extends Destination { /* @internal */ constructor(ptr) { super(null, ptr); const blinded_path = bindings.LDKDestination_BlindedPath_get_blinded_path(ptr); const blinded_path_hu_conv = new BlindedMessagePath(null, blinded_path); CommonBase.add_ref_from(blinded_path_hu_conv, this); this.blinded_path = blinded_path_hu_conv; } } //# sourceMappingURL=Destination.mjs.map