UNPKG

@node-lightning/wire

Version:
61 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorMessage = void 0; const bufio_1 = require("@node-lightning/bufio"); const MessageType_1 = require("../MessageType"); /** * This message is defined in BOLT #1 and is used for telling * a peer that something is incorrect. The message can indicate * which channel is in error, or if channelId is zero, it refers * to all channels. * * These message can indicate protocol violations or internal * errors that make channels unusable or that make further * communication unusable. */ class ErrorMessage { constructor() { /** * Message type 17 */ this.type = MessageType_1.MessageType.Error; /** * Data field may be empty. May contain the raw, hex-encoded * transaction in reply to a invalid signature check in * funding_created, funding_signed, closing_signed, or * commitment_signed messages. */ this.data = Buffer.alloc(0); } /** * Deserializes an error message into an ErrorMessage * instance. */ static deserialize(payload) { const reader = new bufio_1.BufferReader(payload); reader.readUInt16BE(); // read type const instance = new ErrorMessage(); instance.channelId = reader.readBytes(32); const len = reader.readUInt16BE(); instance.data = reader.readBytes(len); return instance; } /** * Serialize the ErorrMessage into a Buffer that * can be send on the wire. */ serialize() { const len = 2 + // type 32 + // channel_id 2 + // len this.data.length; const writer = new bufio_1.BufferWriter(Buffer.alloc(len)); writer.writeUInt16BE(this.type); writer.writeBytes(this.channelId); writer.writeUInt16BE(this.data.length); writer.writeBytes(this.data); return writer.toBuffer(); } } exports.ErrorMessage = ErrorMessage; //# sourceMappingURL=ErrorMessage.js.map