UNPKG

@node-lightning/wire

Version:
60 lines 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.QueryChannelRangeMessage = void 0; const bufio_1 = require("@node-lightning/bufio"); const core_1 = require("@node-lightning/core"); const QueryChannelRangeFlags_1 = require("../flags/QueryChannelRangeFlags"); const MessageType_1 = require("../MessageType"); const readTlvs_1 = require("../serialize/readTlvs"); class QueryChannelRangeMessage { constructor() { /** * Type 263 */ this.type = MessageType_1.MessageType.QueryChannelRange; } static deserialize(payload) { const instance = new QueryChannelRangeMessage(); const reader = new bufio_1.BufferReader(payload); reader.readUInt16BE(); // read type bytes instance.chainHash = reader.readBytes(32); instance.firstBlocknum = reader.readUInt32BE(); instance.numberOfBlocks = reader.readUInt32BE(); // Parse any TLVs that might exist readTlvs_1.readTlvs(reader, (type, valueReader) => { switch (type) { case BigInt(1): { const options = valueReader.readBigSize(); const bitfield = new core_1.BitField(options); instance.timestamps = bitfield.isSet(QueryChannelRangeFlags_1.QueryChannelRangeFlags.timestamps); instance.checksums = bitfield.isSet(QueryChannelRangeFlags_1.QueryChannelRangeFlags.checksums); return true; } default: return false; } }); return instance; } serialize() { const writer = new bufio_1.BufferWriter(); writer.writeUInt16BE(MessageType_1.MessageType.QueryChannelRange); writer.writeBytes(this.chainHash); writer.writeUInt32BE(this.firstBlocknum); writer.writeUInt32BE(this.numberOfBlocks); // write the options TLV if (this.timestamps || this.checksums) { const bitfield = new core_1.BitField(); if (this.timestamps) bitfield.set(QueryChannelRangeFlags_1.QueryChannelRangeFlags.timestamps); if (this.checksums) bitfield.set(QueryChannelRangeFlags_1.QueryChannelRangeFlags.checksums); writer.writeBigSize(1); writer.writeBigSize(bufio_1.BufferReader.bigSizeBytes(bitfield.value)); writer.writeBigSize(bitfield.value); } return writer.toBuffer(); } } exports.QueryChannelRangeMessage = QueryChannelRangeMessage; //# sourceMappingURL=QueryChannelRangeMessage.js.map