Skip to content

Commit

Permalink
fix(protocol-parser): only append packed counter if there is dynamic …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
alvrs committed Jul 3, 2023
1 parent 54a19b2 commit 70f1be8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/protocol-parser/src/encodeRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

0 comments on commit 70f1be8

Please sign in to comment.