"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializePoqoDataAndReceiptResp = exports.serializePoqoDataAndReceiptReq = void 0;
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const lib_types_1 = require("@shardeum-foundation/lib-types");
const SignedReceipt_1 = require("./SignedReceipt");
const cPoqoDataAndReceiptReqVersion = 1;
function serializePoqoDataAndReceiptReq(stream, inp, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cPoqoDataAndReceiptReq);
    }
    stream.writeUInt8(cPoqoDataAndReceiptReqVersion);
    stream.writeString(inp.finalState.txid);
    stream.writeString(lib_types_1.Utils.safeStringify(inp.finalState.stateList));
    stream.writeUInt32(inp.txGroupCycle);
    (0, SignedReceipt_1.serializeSignedReceipt)(stream, inp.receipt);
}
exports.serializePoqoDataAndReceiptReq = serializePoqoDataAndReceiptReq;
function deserializePoqoDataAndReceiptResp(stream) {
    const version = stream.readUInt8();
    if (version !== cPoqoDataAndReceiptReqVersion) {
        throw new Error('PoqoDataAndReceiptReq version mismatch');
    }
    const txid = stream.readString();
    const stateList = lib_types_1.Utils.safeJsonParse(stream.readString());
    const txGroupCycle = stream.readUInt32();
    const signedReceipt = (0, SignedReceipt_1.deserializeSignedReceipt)(stream);
    return {
        finalState: {
            txid: txid,
            stateList: stateList,
        },
        receipt: signedReceipt,
        txGroupCycle: txGroupCycle,
    };
}
exports.deserializePoqoDataAndReceiptResp = deserializePoqoDataAndReceiptResp;
//# sourceMappingURL=PoqoDataAndReceiptReq.js.map