UNPKG

lightningdevkit

Version:
220 lines 8.77 kB
import { NodeId } from '../structs/NodeId.mjs'; import { SocketAddress } from '../structs/SocketAddress.mjs'; import { NodeAlias } from '../structs/NodeAlias.mjs'; import { Result_UnsignedNodeAnnouncementDecodeErrorZ } from '../structs/Result_UnsignedNodeAnnouncementDecodeErrorZ.mjs'; import { NodeFeatures } from '../structs/NodeFeatures.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * The unsigned part of a [`node_announcement`] message. * * [`node_announcement`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-node_announcement-message */ export class UnsignedNodeAnnouncement extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.UnsignedNodeAnnouncement_free); } /** * The advertised features */ get_features() { const ret = bindings.UnsignedNodeAnnouncement_get_features(this.ptr); const ret_hu_conv = new NodeFeatures(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The advertised features */ set_features(val) { bindings.UnsignedNodeAnnouncement_set_features(this.ptr, CommonBase.get_ptr_of(val)); } /** * A strictly monotonic announcement counter, with gaps allowed */ get_timestamp() { const ret = bindings.UnsignedNodeAnnouncement_get_timestamp(this.ptr); return ret; } /** * A strictly monotonic announcement counter, with gaps allowed */ set_timestamp(val) { bindings.UnsignedNodeAnnouncement_set_timestamp(this.ptr, val); } /** * The `node_id` this announcement originated from (don't rebroadcast the `node_announcement` back * to this node). */ get_node_id() { const ret = bindings.UnsignedNodeAnnouncement_get_node_id(this.ptr); const ret_hu_conv = new NodeId(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The `node_id` this announcement originated from (don't rebroadcast the `node_announcement` back * to this node). */ set_node_id(val) { bindings.UnsignedNodeAnnouncement_set_node_id(this.ptr, CommonBase.get_ptr_of(val)); } /** * An RGB color for UI purposes */ get_rgb() { const ret = bindings.UnsignedNodeAnnouncement_get_rgb(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * An RGB color for UI purposes */ set_rgb(val) { bindings.UnsignedNodeAnnouncement_set_rgb(this.ptr, bindings.encodeUint8Array(val)); } /** * An alias, for UI purposes. * * This should be sanitized before use. There is no guarantee of uniqueness. */ get_alias() { const ret = bindings.UnsignedNodeAnnouncement_get_alias(this.ptr); const ret_hu_conv = new NodeAlias(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * An alias, for UI purposes. * * This should be sanitized before use. There is no guarantee of uniqueness. */ set_alias(val) { bindings.UnsignedNodeAnnouncement_set_alias(this.ptr, CommonBase.get_ptr_of(val)); } /** * List of addresses on which this node is reachable * * Returns a copy of the field. */ get_addresses() { const ret = bindings.UnsignedNodeAnnouncement_get_addresses(this.ptr); const ret_conv_15_len = bindings.getArrayLength(ret); const ret_conv_15_arr = new Array(ret_conv_15_len).fill(null); for (var p = 0; p < ret_conv_15_len; p++) { const ret_conv_15 = bindings.getU64ArrayElem(ret, p); const ret_conv_15_hu_conv = SocketAddress.constr_from_ptr(ret_conv_15); CommonBase.add_ref_from(ret_conv_15_hu_conv, this); ret_conv_15_arr[p] = ret_conv_15_hu_conv; } bindings.freeWasmMemory(ret); return ret_conv_15_arr; } /** * List of addresses on which this node is reachable */ set_addresses(val) { bindings.UnsignedNodeAnnouncement_set_addresses(this.ptr, bindings.encodeUint64Array(val.map(val_conv_15 => CommonBase.get_ptr_of(val_conv_15)))); } /** * Excess address data which was signed as a part of the message which we do not (yet) understand how * to decode. * * This is stored to ensure forward-compatibility as new address types are added to the lightning gossip protocol. * * Returns a copy of the field. */ get_excess_address_data() { const ret = bindings.UnsignedNodeAnnouncement_get_excess_address_data(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Excess address data which was signed as a part of the message which we do not (yet) understand how * to decode. * * This is stored to ensure forward-compatibility as new address types are added to the lightning gossip protocol. */ set_excess_address_data(val) { bindings.UnsignedNodeAnnouncement_set_excess_address_data(this.ptr, bindings.encodeUint8Array(val)); } /** * Excess data which was signed as a part of the message which we do not (yet) understand how * to decode. * * This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol. * * Returns a copy of the field. */ get_excess_data() { const ret = bindings.UnsignedNodeAnnouncement_get_excess_data(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Excess data which was signed as a part of the message which we do not (yet) understand how * to decode. * * This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol. */ set_excess_data(val) { bindings.UnsignedNodeAnnouncement_set_excess_data(this.ptr, bindings.encodeUint8Array(val)); } /** * Constructs a new UnsignedNodeAnnouncement given each field */ static constructor_new(features_arg, timestamp_arg, node_id_arg, rgb_arg, alias_arg, addresses_arg, excess_address_data_arg, excess_data_arg) { const ret = bindings.UnsignedNodeAnnouncement_new(CommonBase.get_ptr_of(features_arg), timestamp_arg, CommonBase.get_ptr_of(node_id_arg), bindings.encodeUint8Array(rgb_arg), CommonBase.get_ptr_of(alias_arg), bindings.encodeUint64Array(addresses_arg.map(addresses_arg_conv_15 => CommonBase.get_ptr_of(addresses_arg_conv_15))), bindings.encodeUint8Array(excess_address_data_arg), bindings.encodeUint8Array(excess_data_arg)); const ret_hu_conv = new UnsignedNodeAnnouncement(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } clone_ptr() { const ret = bindings.UnsignedNodeAnnouncement_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the UnsignedNodeAnnouncement */ clone() { const ret = bindings.UnsignedNodeAnnouncement_clone(this.ptr); const ret_hu_conv = new UnsignedNodeAnnouncement(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the UnsignedNodeAnnouncement. */ hash() { const ret = bindings.UnsignedNodeAnnouncement_hash(this.ptr); return ret; } /** * Checks if two UnsignedNodeAnnouncements contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. * Two objects with NULL inner values will be considered "equal" here. */ eq(b) { const ret = bindings.UnsignedNodeAnnouncement_eq(this.ptr, CommonBase.get_ptr_of(b)); CommonBase.add_ref_from(this, b); return ret; } /** * Serialize the UnsignedNodeAnnouncement object into a byte array which can be read by UnsignedNodeAnnouncement_read */ write() { const ret = bindings.UnsignedNodeAnnouncement_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a UnsignedNodeAnnouncement from a byte array, created by UnsignedNodeAnnouncement_write */ static constructor_read(ser) { const ret = bindings.UnsignedNodeAnnouncement_read(bindings.encodeUint8Array(ser)); const ret_hu_conv = Result_UnsignedNodeAnnouncementDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } } //# sourceMappingURL=UnsignedNodeAnnouncement.mjs.map