@node-dlc/messaging
Version:
DLC Messaging Protocol
51 lines • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DlcCancelV0 = exports.CancelType = exports.DlcCancel = void 0;
const bufio_1 = require("@node-dlc/bufio");
const MessageType_1 = require("../MessageType");
/**
* DlcCancel message contains information about a node's desire to cancel
* a DLC contract negotiation.
*/
class DlcCancel {
constructor() {
/**
* The type for dlc_cancel message. dlc_cancel = 52172
*/
this.type = DlcCancel.type;
this.cancelType = 0;
}
/**
* Deserializes a dlc_cancel message
* @param buf
*/
static deserialize(buf) {
const instance = new DlcCancel();
const reader = new bufio_1.BufferReader(buf);
reader.readUInt16BE(); // read type
instance.contractId = reader.readBytes(32);
instance.cancelType = reader.readUInt8();
return instance;
}
/**
* Serializes the dlc_cancel 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.DlcCancel = DlcCancel;
DlcCancel.type = MessageType_1.MessageType.DlcCancel;
var CancelType;
(function (CancelType) {
CancelType[CancelType["Unknown"] = 0] = "Unknown";
CancelType[CancelType["Market"] = 1] = "Market";
CancelType[CancelType["Error"] = 2] = "Error";
})(CancelType = exports.CancelType || (exports.CancelType = {}));
// Backward compatibility alias
exports.DlcCancelV0 = DlcCancel;
//# sourceMappingURL=DlcCancel.js.map