"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeGetConfirmOrChallengeResp = exports.serializeGetConfirmOrChallengeResp = void 0;
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const lib_types_1 = require("@shardeum-foundation/lib-types");
const cGetConfirmOrChallengeResponseVersion = 1;
function serializeGetConfirmOrChallengeResp(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cGetConfirmOrChallengeResp);
    }
    stream.writeUInt8(cGetConfirmOrChallengeResponseVersion);
    stream.writeString(obj.txId);
    stream.writeString(obj.appliedVoteHash);
    if (obj.result) {
        stream.writeUInt8(1);
        stream.writeString(lib_types_1.Utils.safeStringify(obj.result));
    }
    else {
        stream.writeUInt8(0);
    }
    stream.writeUInt32(obj.uniqueCount);
}
exports.serializeGetConfirmOrChallengeResp = serializeGetConfirmOrChallengeResp;
function deserializeGetConfirmOrChallengeResp(stream) {
    const version = stream.readUInt8();
    if (version > cGetConfirmOrChallengeResponseVersion) {
        throw new Error('GetConfirmOrChallengeResponse version mismatch');
    }
    const txId = stream.readString();
    const appliedVoteHash = stream.readString();
    const hasResult = stream.readUInt8() === 1;
    let result;
    if (hasResult) {
        result = lib_types_1.Utils.safeJsonParse(stream.readString());
    }
    const uniqueCount = stream.readUInt32();
    return {
        txId,
        appliedVoteHash,
        result,
        uniqueCount,
    };
}
exports.deserializeGetConfirmOrChallengeResp = deserializeGetConfirmOrChallengeResp;
//# sourceMappingURL=GetConfirmOrChallengeResp.js.map