Skip to content

fix: keep lovelace amounts that do not fit in a JS number - #847

Open
SashaMIT wants to merge 1 commit into
MeshJS:mainfrom
SashaMIT:codered-value-json-bigint
Open

SashaMIT wants to merge 1 commit into
MeshJS:mainfrom
SashaMIT:codered-value-json-bigint

Conversation

@SashaMIT

Copy link
Copy Markdown

Summary

MeshValue.toJSON summed asset quantities with Number. A JS number cannot hold every lovelace amount. 9007199254740993 lovelace (about 9 billion ADA, under the 45 billion supply) came back as 9007199254740992.

Quantities are now summed as bigint. A value that still fits in a JS number stays a number, so existing JSON output is unchanged. A value that does not fit is passed to integer() as a bigint.

Test plan

  • On tip, toJSON of lovelace 9007199254740993 returned the number 9007199254740992.
  • After the change, that quantity is the bigint 9007199254740993, and 1000000 lovelace is still the number 1000000.
  • npm test in @meshsdk/common was not run here. The new case is in test/data/value/convertor.test.ts.

Made with Cursor

MeshValue.toJSON passed the quantity through Number, so 9007199254740993 lovelace became 9007199254740992.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant