fix: preserve Map (and bigint) in cloneOutput via structuredClone#831
Open
OscarOzaine wants to merge 1 commit into
Open
fix: preserve Map (and bigint) in cloneOutput via structuredClone#831OscarOzaine wants to merge 1 commit into
OscarOzaine wants to merge 1 commit into
Conversation
cloneOutput used a JSON round-trip, which silently drops Map entries and mangles bigint inside Mesh Data inline datums (e.g. CIP-68 metadata from metadataToCip68). The empty Map then made serializeOutput throw "Cannot convert undefined to a BigInt". Use structuredClone, consistent with how the tx builder already clones txOutput and other queue items in tx-builder-core.ts. Adds regression tests for Map preservation, bigint preservation, deep-copy independence, and plain ADA-only outputs. Fixes MeshJS#704 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cloneOutputdeep-cloned outputs via a JSON round-trip (JSONBig.parse(JSONBig.stringify(...))), which silently dropsMapentries (and manglesbigint) inside a MeshDatainline datum. When an inline datum contains aMap— e.g. CIP-68 metadata produced bymetadataToCip68and used with.txOutInlineDatumValue(..., "Mesh")— theMapwas cloned to an empty{}, and serialization later threwTypeError: Cannot convert undefined to a BigIntintoPlutusData.This switches
cloneOutputtostructuredClone, which preservesMap,bigint,Uint8Arrayand nested structures. It's also consistent with how the tx builder already clonestxOutputand other queue items intx-builder-core.ts.Fixes #704
Root cause
packages/mesh-transaction/src/mesh-tx-builder/index.ts—cloneOutputis called bygetOutputMinLovelaceon every min-ADA calculation, so any output whose inline datum holds aMapwas corrupted during transaction building.Tests
Adds
packages/mesh-transaction/test/clone-output.test.ts:Mapinside a MeshDatainline datum survives cloning (size + entries),bigintfields survive,All existing
@meshsdk/transactiontests pass (24 suites / 128 tests);tsc --noEmitclean; prettier clean.Credit
Thanks to @Daennes for the precise diagnosis and for suggesting
structuredClonein the issue.🤖 Generated with Claude Code