-
Notifications
You must be signed in to change notification settings - Fork 172
Remove default implementation for the DecCBOR class #5532
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
base: master
Are you sure you want to change the base?
Conversation
libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs
Show resolved
Hide resolved
lehins
left a comment
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.
There is really no need for all of those extra top level definitions for reusability in both types of decoders, they only bring noise.
It is better to use special helper fromEraCBOR (see my suggestion)
We could even potentially add a newtype like this to Cardano.Ledger.Core.Era:
newtype EraDecoder era a = EraDecoder a
instance (Era era, DecCBOR a) => FromCBOR (EraDecoder era) where
fromCBOR = fromEraCBOR @era
which can then be used to do deriving via.
| decCBOR = do | ||
| sbs <- decCBOR @ShortByteString | ||
| maybe (fail "Invalid hash size") pure $ hashFromBytesShort sbs | ||
| {-# INLINE decCBOR #-} |
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.
We actually need to create a DecCBOR instance for PackedBytes. For now that instance will simply biggy back on FromCBOR instance, but then we will need to export some functionality for safe construction of PackedBytes from this module: `https://github.com/IntersectMBO/cardano-base/blob/d78f2f350017f0b3a1c57f483a2c323676756622/cardano-crypto-class/src/Cardano/Crypto/PackedBytes.hs
| decCBOR = do | |
| sbs <- decCBOR @ShortByteString | |
| maybe (fail "Invalid hash size") pure $ hashFromBytesShort sbs | |
| {-# INLINE decCBOR #-} | |
| decCBOR = hashFromPackedBytes <$> decCBOR | |
| {-# INLINE decCBOR #-} |
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.
Ah I see - that's a hidden module so even the FromCBOR instance is not exported. I guess this is blocked on exposing at least that from base?
libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs
Show resolved
Hide resolved
c7f8ec1 to
277ebdb
Compare
Description
First part of #5513: we remove the default implementation for
DecCBORthroughFromCBOR, so that types that contain Bytestrings are more easily routed to the version-aware decodingChecklist
CHANGELOG.mdfiles updated for packages with externally visible changes.NOTE: New section is never added with the code changes. (See RELEASING.md).
.cabalandCHANGELOG.mdfiles when necessary, according to theversioning process.
.cabalfiles updated when necessary.NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
scripts/fourmolize.sh).scripts/cabal-format.sh).scripts/gen-cddl.sh)hie.yamlupdated (usescripts/gen-hie.sh).