"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeRequestStateForTxPostReq = exports.serializeRequestStateForTxPostReq = exports.cRequestStateForTxPostReqVersion = void 0;
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
exports.cRequestStateForTxPostReqVersion = 1;
function serializeRequestStateForTxPostReq(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cRequestStateForTxPostReq);
    }
    stream.writeUInt8(exports.cRequestStateForTxPostReqVersion);
    stream.writeString(obj.txid);
    stream.writeBigUInt64(BigInt(obj.timestamp));
    stream.writeString(obj.key);
    stream.writeString(obj.hash);
}
exports.serializeRequestStateForTxPostReq = serializeRequestStateForTxPostReq;
function deserializeRequestStateForTxPostReq(stream) {
    const version = stream.readUInt8();
    if (version > exports.cRequestStateForTxPostReqVersion) {
        throw new Error('RequestStateForTxPostReq version mismatch');
    }
    const txid = stream.readString();
    const timestamp = Number(stream.readBigUInt64());
    const key = stream.readString();
    const hash = stream.readString();
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.RequestStateForTxPostReq, { txid, timestamp, key, hash });
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return { txid, timestamp, key, hash };
}
exports.deserializeRequestStateForTxPostReq = deserializeRequestStateForTxPostReq;
//# sourceMappingURL=RequestStateForTxPostReq.js.map