UNPKG

@node-dlc/messaging

Version:
64 lines 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CancelType = exports.DlcCancelV0 = exports.DlcCancel = void 0; const bufio_1 = require("@node-dlc/bufio"); const MessageType_1 = require("../MessageType"); class DlcCancel { static deserialize(buf) { const reader = new bufio_1.BufferReader(buf); const type = Number(reader.readUInt16BE()); switch (type) { case MessageType_1.MessageType.DlcCancelV0: return DlcCancelV0.deserialize(buf); default: throw new Error(`DLC Cancel message type must be DlcCancelV0`); // This is a temporary measure while protocol is being developed } } } exports.DlcCancel = DlcCancel; /** * DlcOffer message contains information about a node and indicates its * desire to enter into a new contract. This is the first step toward * creating the funding transaction and CETs. */ class DlcCancelV0 extends DlcCancel { constructor() { super(...arguments); /** * The type for cancel_dlc_v0 message. cancel_dlc_v0 = 52172 */ this.type = DlcCancelV0.type; this.cancelType = 0; } /** * Deserializes an offer_dlc_v0 message * @param buf */ static deserialize(buf) { const instance = new DlcCancelV0(); const reader = new bufio_1.BufferReader(buf); reader.readUInt16BE(); // read type instance.contractId = reader.readBytes(32); instance.cancelType = reader.readUInt8(); return instance; } /** * Serializes the offer_dlc_v0 message into a Buffer */ serialize() { const writer = new bufio_1.BufferWriter(); writer.writeUInt16BE(this.type); writer.writeBytes(this.contractId); writer.writeUInt8(this.cancelType); return writer.toBuffer(); } } exports.DlcCancelV0 = DlcCancelV0; DlcCancelV0.type = MessageType_1.MessageType.DlcCancelV0; var CancelType; (function (CancelType) { CancelType[CancelType["Unknown"] = 0] = "Unknown"; CancelType[CancelType["Market"] = 1] = "Market"; CancelType[CancelType["Error"] = 2] = "Error"; })(CancelType = exports.CancelType || (exports.CancelType = {})); //# sourceMappingURL=DlcCancel.js.map