From 70f1be8eb300361d065df72ef51b1b733f86ce8e Mon Sep 17 00:00:00 2001 From: alvrs Date: Thu, 29 Jun 2023 18:42:46 +0100 Subject: [PATCH] fix(protocol-parser): only append packed counter if there is dynamic data --- packages/protocol-parser/src/encodeRecord.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/protocol-parser/src/encodeRecord.ts b/packages/protocol-parser/src/encodeRecord.ts index 14c3f19a07..d542cfac4a 100644 --- a/packages/protocol-parser/src/encodeRecord.ts +++ b/packages/protocol-parser/src/encodeRecord.ts @@ -20,9 +20,12 @@ export function encodeRecord(schema: Schema, values: readonly (StaticPrimitiveTy const dynamicData = dynamicDataItems.join(""); - const packedCounter = `${encodeField("uint56", dynamicTotalByteLength).replace(/^0x/, "")}${dynamicFieldByteLengths - .map((length) => encodeField("uint40", length).replace(/^0x/, "")) - .join("")}`.padEnd(64, "0"); + const packedCounter = + schema.dynamicFields.length > 0 + ? `${encodeField("uint56", dynamicTotalByteLength).replace(/^0x/, "")}${dynamicFieldByteLengths + .map((length) => encodeField("uint40", length).replace(/^0x/, "")) + .join("")}`.padEnd(64, "0") + : ""; return `0x${staticData}${packedCounter}${dynamicData}`; }