Repository navigation
feat(data): give Plutus data its own encoder - #616
Merged
Merged
Conversation
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.
Data.toCBORBytesbuilt a generic CBOR tree and let the CBOR encoder apply one set of options to all of it. Three rules of the node's Plutus data encoder (encodeData) never applied:[index, fields]pair with the list options; the node writes it as a definite two-item array.Datanow writes aDatavalue straight to bytes with these rules under every preset, and lists, maps and constructor fields keep following the codec options. Every other value keeps its bytes under every preset.Data.toCBORBytes,Data.toCBORHex,Data.toDatumHash, the encode side of theDataschemas, redeemers, witness datums, inline datums, UPLC data constants andtoScriptDataHashall use it. For a typical datum it runs several hundred times faster than the tree path. Decoding stays as it was, and decoded transactions keep using the tree path, which still needsCBOR.BoundedBytes.Under
CML_DATA_DEFAULT_OPTIONSthe old tag 102 bytes followed the preset's reference library, which also writes the pair indefinite; the node does not, so the pair now follows the node under every preset.The CBOR encoder now also writes -2^64 as
3bffffffffffffffff, and an integer decoded from a bignum tag keeps that tag when a decoded transaction is written back. A fresh, a decoded and a signed witness set therefore agree on -2^64, and decoded small bignums such asc24101no longer turn into plain integers.Closes #614
Closes #601
Closes #530