Skip to content

fix(data): render Plutus data in toString and toJSON - #727

Open
emmanuel-musau wants to merge 1 commit into
mainfrom
fix/to-string-plutus-data
Open

emmanuel-musau wants to merge 1 commit into
mainfrom
fix/to-string-plutus-data

Conversation

@emmanuel-musau

Copy link
Copy Markdown
Collaborator

toString threw Do not know how to serialize a BigInt on any InlineDatum, UTxO, TxOut, TransactionOutput or Redeemer whose data held an integer or a constructor. Their toJSON returned the data as it is, and Inspectable.format is a plain JSON.stringify. Data without integers rendered wrongly: the byte string ab as {"0": 171} and the map {1: 2} as {}.

The new Data.toJSON returns data in the encoded form DataSchema already writes: an integer as a decimal string, a byte string as hex, a map as [key, value] pairs and a constructor as { index, fields }. InlineDatum, Redeemer, RedeemerMap and TransactionWitnessSet use it, which also fixes TxOut, UTxO and BabbageTransactionOutput through the datum. RedeemerValue, which RedeemerMap.get returns, had no toJSON and gains one.

BabbageTransactionOutput.toString threw on every output, datum or not, because Value.toJSON returned coin as a bigint. It now writes coin as a decimal string, as MultiAsset already writes quantities.

console.log and util.inspect still show the data itself, with bigint integers and Uint8Array bytes. The changeset is a minor, since toJSON().data and toJSON().coin change type.

In this form an integer and a byte string can render the same, Data.int(12n) and the bytes 12 both as "12", and an empty map and an empty list both as []. It only affects display; CBOR, hashes and transaction ids do not go through toJSON.

Closes #685

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.

toString throws on any datum or output that holds an integer

1 participant