@node-dlc/messaging
Version:
DLC Messaging Protocol
58 lines • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OracleInfoV0 = void 0;
const bufio_1 = require("@node-dlc/bufio");
const MessageType_1 = require("../MessageType");
const getTlv_1 = require("../serialize/getTlv");
const OracleAnnouncementV0_1 = require("./OracleAnnouncementV0");
/**
* OracleInfo contains information about the oracles to be used in
* executing a DLC.
*/
class OracleInfoV0 {
constructor() {
/**
* The type for oracle_info_v0 message. oracle_info_v0 = 42770
*/
this.type = OracleInfoV0.type;
}
/**
* Deserializes an oracle_info_v0 message
* @param buf
*/
static deserialize(buf) {
const instance = new OracleInfoV0();
const reader = new bufio_1.BufferReader(buf);
reader.readBigSize(); // read type
instance.length = reader.readBigSize();
instance.announcement = OracleAnnouncementV0_1.OracleAnnouncementV0.deserialize((0, getTlv_1.getTlv)(reader));
return instance;
}
validate() {
this.announcement.validate();
}
/**
* Converts oracle_info_v0 to JSON
*/
toJSON() {
return {
type: this.type,
announcement: this.announcement.toJSON(),
};
}
/**
* Serializes the oracle_info_v0 message into a Buffer
*/
serialize() {
const writer = new bufio_1.BufferWriter();
writer.writeBigSize(this.type);
const dataWriter = new bufio_1.BufferWriter();
dataWriter.writeBytes(this.announcement.serialize());
writer.writeBigSize(dataWriter.size);
writer.writeBytes(dataWriter.toBuffer());
return writer.toBuffer();
}
}
exports.OracleInfoV0 = OracleInfoV0;
OracleInfoV0.type = MessageType_1.MessageType.OracleInfoV0;
//# sourceMappingURL=OracleInfoV0.js.map