Skip to content

cloneOutput helper function Map support #704

@Daennes

Description

@Daennes

Summary

The cloneOutput helper function currently uses JSON.stringify and JSON.parse to perform cloning. However, this approach does not support Map objects.
https://github.com/MeshJS/mesh/blob/main/packages/mesh-transaction/src/mesh-tx-builder/index.ts#L1799-L1801

As a result, when a Mesh Data object containing a Map is used as inline output data, the Map contents are lost during the cloning process.

Mesh Data Object can contain Maps
https://github.com/MeshJS/mesh/blob/main/packages/mesh-common/src/types/data.ts#L6

I encountered this issue when generating CIP68 metadata with metadataToCip68 and then using it in .txOutInlineDatumValue(cip68Metadatum, "Mesh") while creating a transaction.

Could be fixed with structuredClone

export const cloneOutput = (output: Output): Output => {
  return structuredClone(output);
};

Steps to reproduce the bug

No response

Actual Result

Empty Map and error in TX creation

Error:

Error: TypeError: Cannot convert undefined to a BigInt
    at BigInt (<anonymous>)
    at toPlutusData (.../node_modules/@meshsdk/core-cst/dist/index.js:4092:13)
    at .../node_modules/@meshsdk/core-cst/dist/index.js:4068:22
    at Array.forEach (<anonymous>)
    at toPlutusList (.../node_modules/@meshsdk/core-cst/dist/index.js:4067:11)
    at toPlutusData (.../node_modules/@meshsdk/core-cst/dist/index.js:4093:13)
    at fromBuilderToPlutusData (.../node_modules/@meshsdk/core-cst/dist/index.js:4167:12)
    at CardanoSDKSerializer.serializeOutput (.../node_modules/@meshsdk/core-cst/dist/index.js:6026:29)
    at getOutputMinLovelace (.../node_modules/@meshsdk/transaction/dist/index.js:5114:18)
    at _MeshTxBuilder.calculateMinLovelaceForOutput (.../node_modules/@meshsdk/transaction/dist/index.js:5028:12)

Expected Result

Non empty Map after clone and working TX

SDK version

1.9.0-beta.71

Environment type

  • Node.js
  • Browser
  • Browser Extension
  • Other

Environment details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions