"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OracleEventContainerV0 = 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");
const OracleAttestationV0_1 = require("./OracleAttestationV0");
/**
 * OracleEventContainer contains information about the oracles to be used in
 * executing a DLC.
 */
class OracleEventContainerV0 {
    constructor() {
        /**
         * The type for oracle_info_v0 message. oracle_info_v0 = 42770
         */
        this.type = OracleEventContainerV0.type;
    }
    /**
     * Deserializes an oracle_info_v0 message
     * @param buf
     */
    static deserialize(buf) {
        const instance = new OracleEventContainerV0();
        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();
        const uriLength = reader.readBigSize();
        const uriBuf = reader.readBytes(Number(uriLength));
        instance.uri = uriBuf.toString();
        instance.announcement = OracleAnnouncementV0_1.OracleAnnouncementV0.deserialize((0, getTlv_1.getTlv)(reader));
        instance.attestation = OracleAttestationV0_1.OracleAttestationV0.deserialize((0, getTlv_1.getTlv)(reader));
        const outcomeLength = reader.readBigSize();
        const outcomeBuf = reader.readBytes(Number(outcomeLength));
        instance.outcome = outcomeBuf.toString();
        return instance;
    }
    validate() {
        this.announcement.validate();
    }
    /**
     * 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.writeBigSize(this.oracleName.length);
        dataWriter.writeBytes(Buffer.from(this.oracleName));
        dataWriter.writeBigSize(this.uri.length);
        dataWriter.writeBytes(Buffer.from(this.uri));
        dataWriter.writeBytes(this.announcement.serialize());
        dataWriter.writeBytes(this.attestation.serialize());
        dataWriter.writeBigSize(this.outcome.length);
        dataWriter.writeBytes(Buffer.from(this.outcome));
        writer.writeBigSize(dataWriter.size);
        writer.writeBytes(dataWriter.toBuffer());
        return writer.toBuffer();
    }
}
exports.OracleEventContainerV0 = OracleEventContainerV0;
OracleEventContainerV0.type = MessageType_1.MessageType.OracleEventContainerV0;
//# sourceMappingURL=OracleEventContainerV0.js.map