From cb89f4329f41b67943e88d84030fcea77060e3d6 Mon Sep 17 00:00:00 2001 From: alvrs Date: Mon, 3 Jul 2023 18:34:07 +0100 Subject: [PATCH] early return if no dynamic fields --- packages/protocol-parser/src/encodeRecord.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/protocol-parser/src/encodeRecord.ts b/packages/protocol-parser/src/encodeRecord.ts index d542cfac4a..23a1c16fea 100644 --- a/packages/protocol-parser/src/encodeRecord.ts +++ b/packages/protocol-parser/src/encodeRecord.ts @@ -11,6 +11,8 @@ export function encodeRecord(schema: Schema, values: readonly (StaticPrimitiveTy .map((value, i) => encodeField(schema.staticFields[i], value).replace(/^0x/, "")) .join(""); + if (schema.dynamicFields.length === 0) return `0x${staticData}`; + const dynamicDataItems = dynamicValues.map((value, i) => encodeField(schema.dynamicFields[i], value).replace(/^0x/, "") ); @@ -20,12 +22,9 @@ export function encodeRecord(schema: Schema, values: readonly (StaticPrimitiveTy const dynamicData = dynamicDataItems.join(""); - const packedCounter = - schema.dynamicFields.length > 0 - ? `${encodeField("uint56", dynamicTotalByteLength).replace(/^0x/, "")}${dynamicFieldByteLengths - .map((length) => encodeField("uint40", length).replace(/^0x/, "")) - .join("")}`.padEnd(64, "0") - : ""; + const packedCounter = `${encodeField("uint56", dynamicTotalByteLength).replace(/^0x/, "")}${dynamicFieldByteLengths + .map((length) => encodeField("uint40", length).replace(/^0x/, "")) + .join("")}`.padEnd(64, "0"); return `0x${staticData}${packedCounter}${dynamicData}`; }