"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cProposalVersion = void 0;
exports.serializeProposal = serializeProposal;
exports.deserializeProposal = deserializeProposal;
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
exports.cProposalVersion = 1;
function serializeProposal(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cProposalVersion);
    }
    stream.writeUInt8(exports.cProposalVersion);
    stream.writeUInt8(obj.applied ? 1 : 0);
    stream.writeUInt8(obj.cant_preApply ? 1 : 0);
    stream.writeUInt16(obj.accountIDs.length);
    for (let i = 0; i < obj.accountIDs.length; i++) {
        // eslint-disable-next-line security/detect-object-injection
        stream.writeString(obj.accountIDs[i]);
    }
    stream.writeUInt16(obj.beforeStateHashes.length);
    for (let i = 0; i < obj.beforeStateHashes.length; i++) {
        // eslint-disable-next-line security/detect-object-injection
        stream.writeString(obj.beforeStateHashes[i]);
    }
    stream.writeUInt16(obj.afterStateHashes.length);
    for (let i = 0; i < obj.afterStateHashes.length; i++) {
        // eslint-disable-next-line security/detect-object-injection
        stream.writeString(obj.afterStateHashes[i]);
    }
    stream.writeString(obj.appReceiptDataHash);
    stream.writeString(obj.txid);
    stream.writeString(obj.executionShardKey);
}
function deserializeProposal(stream) {
    const version = stream.readUInt8();
    if (version > exports.cProposalVersion) {
        throw new Error(`ProposalDeserializer expected version ${exports.cProposalVersion}, got ${version}`);
    }
    const applied = stream.readUInt8() === 1;
    const cant_preApply = stream.readUInt8() === 1;
    const accountIDsLength = stream.readUInt16();
    const accountIDs = [];
    for (let i = 0; i < accountIDsLength; i++) {
        accountIDs.push(stream.readString());
    }
    const beforeStateHashesLength = stream.readUInt16();
    const beforeStateHashes = [];
    for (let i = 0; i < beforeStateHashesLength; i++) {
        beforeStateHashes.push(stream.readString());
    }
    const afterStateHashesLength = stream.readUInt16();
    const afterStateHashes = [];
    for (let i = 0; i < afterStateHashesLength; i++) {
        afterStateHashes.push(stream.readString());
    }
    const appReceiptDataHash = stream.readString();
    const txid = stream.readString();
    const executionShardKey = stream.readString();
    return {
        applied,
        cant_preApply,
        accountIDs,
        beforeStateHashes,
        afterStateHashes,
        appReceiptDataHash,
        txid,
        executionShardKey,
    };
}
//# sourceMappingURL=Proposal.js.map