Skip to content

Properly handle BigInt <-> JSON #43

@brendanrbrown

Description

@brendanrbrown

We need to serialize BigInt values to JSON in the offchain code. However, BigInt is not supported in JSON, and the standard JavaScript conversions via parse or stringify fail either with runtime exceptions or by silently overflowing.

For now, TrustlessSidechain.Utils.Codecs.bigIntCodec throws an exception when attempting to serialize a value that is out of the range of a PureScript Int.

We can probably do better using an existing JavaScript package like this one for serializing BigInt.

Or, we could reconsider the use of BigInt in the first place for values that need to be serialized to JSON.

For some details see https://github.com/input-output-hk/trustless-sidechain/pull/711#discussion_r1510989411

and the code Note [BigInt values and JSON].

This issue is moot if we move the offchain code to Haskell, as discussed here: https://github.com/input-output-hk/trustless-sidechain/discussions/710


IOG Jira: https://input-output.atlassian.net/browse/ETCM-6865

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAdd or improve a user-facing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions