-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort metadata keys for no-schema json for canonical CBOR #517
Conversation
709f74c
to
1cae747
Compare
. traverse (\(k,v) -> (,) (convKey k) <$> conv v) | ||
. List.sortOn fst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON map was previously sorted lexicographically by keys and then it was processed down the line as a list of pairs until it got serialised to CBOR. So this place was deciding about the sorting order of the object fields' names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will work but I think a more robust solution would be to do something similar to HashableScriptData
. We should serialize the metadata to CBOR once and carry around the canonical representation. I think this distinction is useful for the reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. This would complicate things a bit because here we're converting here our type:
. toShelleyMetadata |
So I guess I'd have to modify
SerialiseAsCBOR
to handle different metadata types 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would look like HashableScriptData
's SerialiseAsCBOR
instance:
instance SerialiseAsCBOR HashableScriptData where
serialiseToCBOR (HashableScriptData origBytes _) = origBytes
Upon constructing "HashableTxMetaData" you would already have the CBOR of the metadata.
1cae747
to
6597f5f
Compare
6597f5f
to
6cd7f73
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work ❤️
-> ByteString -- ^ json string to test | ||
-> TxMetadata -- ^ expected metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> ByteString -- ^ json string to test | |
-> TxMetadata -- ^ expected metadata | |
-> ByteString -- ^ Json string to test | |
-> TxMetadata -- ^ Expected metadata |
tmkValue <- | ||
fromShelleyMetadatum | ||
<$> (CBOR.decodeFullDecoder' CBOR.shelleyProtVer "TxMetadataKey" CBOR.decCBOR tmkBytes | ||
:: Either CBOR.DecoderError (Shelley.Metadatum)) |
Check warning
Code scanning / HLint
Redundant bracket
d039af6
to
6cd7f73
Compare
Changelog
Context
This PR changes sorting for
--json-metadata-no-schema
JSON to canonical CBOR. It changes transaction file output CBOR representation (reorders metadata keys for this case), so it's marked as a breaking change.Note that there's always
--json-metadata-schema
JSON format available which allows to specify metadata keys ordering. See example.Fixes IntersectMBO/cardano-node#4335
Checklist