UNPKG

@node-dlc/messaging

Version:
74 lines 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OrderIrcInfoV0 = exports.OrderIrcInfo = void 0; const bufio_1 = require("@node-dlc/bufio"); const MessageType_1 = require("../MessageType"); class OrderIrcInfo { static deserialize(buf) { const reader = new bufio_1.BufferReader(buf); const type = Number(reader.readBigSize()); switch (type) { case MessageType_1.MessageType.OrderIrcInfoV0: return OrderIrcInfoV0.deserialize(buf); default: throw new Error(`Order irc info TLV type must be OrderIrcInfoV0`); } } } exports.OrderIrcInfo = OrderIrcInfo; /** * OrderMetadata message contains information about a node and indicates its * desire to enter into a new contract. This is the first step toward * order negotiation. */ class OrderIrcInfoV0 extends OrderIrcInfo { constructor() { super(...arguments); /** * The type for order_metadata_v0 message. order_metadata_v0 = 62774 */ this.type = OrderIrcInfoV0.type; } /** * Deserializes an offer_dlc_v0 message * @param buf */ static deserialize(buf) { const instance = new OrderIrcInfoV0(); const reader = new bufio_1.BufferReader(buf); reader.readBigSize(); // read type instance.length = reader.readBigSize(); const nickLength = reader.readBigSize(); const nickBuf = reader.readBytes(Number(nickLength)); instance.nick = nickBuf.toString(); instance.pubKey = reader.readBytes(33); return instance; } /** * Converts order_metadata_v0 to JSON */ toJSON() { return { type: this.type, nick: this.nick, pubKey: this.pubKey.toString('hex'), }; } /** * Serializes the oracle_event message into a Buffer */ serialize() { const writer = new bufio_1.BufferWriter(); writer.writeBigSize(this.type); const dataWriter = new bufio_1.BufferWriter(); dataWriter.writeBigSize(this.nick.length); dataWriter.writeBytes(Buffer.from(this.nick)); dataWriter.writeBytes(this.pubKey); writer.writeBigSize(dataWriter.size); writer.writeBytes(dataWriter.toBuffer()); return writer.toBuffer(); } } exports.OrderIrcInfoV0 = OrderIrcInfoV0; OrderIrcInfoV0.type = MessageType_1.MessageType.OrderIrcInfoV0; //# sourceMappingURL=OrderIrcInfo.js.map