"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OracleIdentifierV0 = void 0;
const bufio_1 = require("@node-dlc/bufio");
const MessageType_1 = require("../MessageType");
class OracleIdentifierV0 {
    constructor() {
        /**
         * The type for oracle_identifier message. oracle_identifier = 61472
         */
        this.type = OracleIdentifierV0.type;
    }
    /**
     * Deserializes an oracle_event message
     * @param buf
     */
    static deserialize(buf) {
        const instance = new OracleIdentifierV0();
        const reader = new bufio_1.BufferReader(buf);
        reader.readBigSize(); // read type
        instance.length = reader.readBigSize();
        const oracleNameLength = reader.readBigSize();
        const oracleNameBuf = reader.readBytes(Number(oracleNameLength));
        instance.oracleName = oracleNameBuf.toString();
        instance.oraclePubkey = reader.readBytes(32);
        return instance;
    }
    validate() {
        return;
    }
    /**
     * Converts oracle_event to JSON
     */
    toJSON() {
        return {
            type: this.type,
            oracleName: this.oracleName,
            oraclePubkey: this.oraclePubkey.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.oracleName.length);
        dataWriter.writeBytes(Buffer.from(this.oracleName));
        dataWriter.writeBytes(this.oraclePubkey);
        writer.writeBigSize(dataWriter.size);
        writer.writeBytes(dataWriter.toBuffer());
        return writer.toBuffer();
    }
}
exports.OracleIdentifierV0 = OracleIdentifierV0;
OracleIdentifierV0.type = MessageType_1.MessageType.OracleIdentifierV0;
//# sourceMappingURL=OracleIdentifierV0.js.map