Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Genesis.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
Expand Down Expand Up @@ -90,16 +91,15 @@ newtype AlonzoExtraConfig = AlonzoExtraConfig
deriving (Eq)
deriving newtype (NFData, NoThunks, Show)

instance DecCBOR AlonzoExtraConfig
instance DecCBOR AlonzoExtraConfig where
decCBOR = decode (RecD AlonzoExtraConfig <! D (decodeNullMaybe decodeCostModelsLenient))
{-# INLINE decCBOR #-}

instance EncCBOR AlonzoExtraConfig

instance FromCBOR AlonzoExtraConfig where
fromCBOR =
eraDecoder @AlonzoEra $
decode $
RecD AlonzoExtraConfig
<! D (decodeNullMaybe decodeCostModelsLenient)
fromCBOR = fromEraCBOR @AlonzoEra
{-# INLINE fromCBOR #-}

instance ToCBOR AlonzoExtraConfig where
toCBOR x@(AlonzoExtraConfig _) =
Expand Down Expand Up @@ -184,24 +184,26 @@ instance EraGenesis AlonzoEra where
type Genesis AlonzoEra = AlonzoGenesis

-- | Genesis types are always encoded with the version of era they are defined in.
instance DecCBOR AlonzoGenesis
instance DecCBOR AlonzoGenesis where
decCBOR =
decode $
RecD AlonzoGenesis
<! From
<! D (decodeCostModel PlutusV1)
<! From
<! From
<! From
<! From
<! From
<! From
<! From
{-# INLINE decCBOR #-}

instance EncCBOR AlonzoGenesis

instance FromCBOR AlonzoGenesis where
fromCBOR =
eraDecoder @AlonzoEra $
decode $
RecD AlonzoGenesis
<! From
<! D (decodeCostModel PlutusV1)
<! From
<! From
<! From
<! From
<! From
<! From
<! From
fromCBOR = fromEraCBOR @AlonzoEra
{-# INLINE fromCBOR #-}

instance ToCBOR AlonzoGenesis where
toCBOR x@(AlonzoGenesis _ _ _ _ _ _ _ _ _) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Cardano.Crypto.Signing.Redeem.VerificationKey (
redeemVKB64F,
)
import Cardano.Ledger.Binary (
DecCBOR,
DecCBOR (..),
EncCBOR,
FromCBOR (..),
ToCBOR (..),
Expand All @@ -34,7 +34,9 @@ newtype RedeemSigningKey

instance EncCBOR RedeemSigningKey

instance DecCBOR RedeemSigningKey
instance DecCBOR RedeemSigningKey where
decCBOR = RedeemSigningKey <$> decCBOR
{-# INLINE decCBOR #-}

-- Note that there is deliberately no Ord instance. The crypto libraries
-- encourage using key /hashes/ not keys for things like sets, map etc.
Expand Down
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.21.0.0

* Remove `ToCBOR` and `FromCBOR` instances for `DefaultVote`
* Add `conwayLedgerTransitionTRC`
* Deprecate
- `constitutionScriptL` in favor of new `constitutionGuardrailsScriptHashL`
Expand Down
10 changes: 5 additions & 5 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ instance NFData ConwayGenesis

-- | Genesis are always encoded with the version of era they are defined in.
instance FromCBOR ConwayGenesis where
fromCBOR =
eraDecoder @ConwayEra $
decode $
RecD ConwayGenesis <! From <! From <! From <! From <! From
fromCBOR = fromEraCBOR @ConwayEra
{-# INLINE fromCBOR #-}

instance ToCBOR ConwayGenesis where
toCBOR x@(ConwayGenesis _ _ _ _ _) =
Expand All @@ -86,7 +84,9 @@ instance ToCBOR ConwayGenesis where
!> To cgDelegs
!> To cgInitialDReps

instance DecCBOR ConwayGenesis
instance DecCBOR ConwayGenesis where
decCBOR = decode (RecD ConwayGenesis <! From <! From <! From <! From <! From)
{-# INLINE decCBOR #-}

instance EncCBOR ConwayGenesis

Expand Down
26 changes: 11 additions & 15 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,14 @@ import Cardano.Ledger.Binary (
ToCBOR (..),
decNoShareCBOR,
decodeRecordNamedT,
decodeWord8,
encodeWord8,
)
import Cardano.Ledger.Binary.Coders (
Encode (..),
encode,
(!>),
)
import Cardano.Ledger.Binary.Plain (
decodeWord8,
encodeWord8,
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Compactible (CompactForm)
import Cardano.Ledger.Conway.Era (ConwayEra)
Expand Down Expand Up @@ -537,23 +535,21 @@ data DefaultVote
DefaultNoConfidence
deriving (Eq, Show)

instance FromCBOR DefaultVote where
fromCBOR = do
instance EncCBOR DefaultVote where
encCBOR DefaultNo = encodeWord8 0
encCBOR DefaultAbstain = encodeWord8 1
encCBOR DefaultNoConfidence = encodeWord8 2
{-# INLINE encCBOR #-}

instance DecCBOR DefaultVote where
decCBOR = do
tag <- decodeWord8
case tag of
0 -> pure DefaultNo
1 -> pure DefaultAbstain
2 -> pure DefaultNoConfidence
_ -> fail $ "Invalid DefaultVote tag " ++ show tag

instance ToCBOR DefaultVote where
toCBOR DefaultNo = encodeWord8 0
toCBOR DefaultAbstain = encodeWord8 1
toCBOR DefaultNoConfidence = encodeWord8 2

instance EncCBOR DefaultVote

instance DecCBOR DefaultVote
{-# INLINE decCBOR #-}

defaultStakePoolVote ::
ConwayEraAccounts era =>
Expand Down
12 changes: 6 additions & 6 deletions eras/dijkstra/impl/src/Cardano/Ledger/Dijkstra/Genesis.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
Expand Down Expand Up @@ -37,11 +38,8 @@ instance EraGenesis DijkstraEra where
type Genesis DijkstraEra = DijkstraGenesis

instance FromCBOR DijkstraGenesis where
fromCBOR =
eraDecoder @DijkstraEra $
decode $
RecD DijkstraGenesis
<! From
fromCBOR = fromEraCBOR @DijkstraEra
{-# INLINE fromCBOR #-}

instance ToCBOR DijkstraGenesis where
toCBOR dg@(DijkstraGenesis _) =
Expand All @@ -50,6 +48,8 @@ instance ToCBOR DijkstraGenesis where
Rec DijkstraGenesis
!> To dgUpgradePParams

instance DecCBOR DijkstraGenesis
instance DecCBOR DijkstraGenesis where
decCBOR = decode (RecD DijkstraGenesis <! From)
{-# INLINE decCBOR #-}

instance EncCBOR DijkstraGenesis
74 changes: 38 additions & 36 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import Cardano.Ledger.Binary (
enforceDecoderVersion,
enforceEncodingVersion,
shelleyProtVer,
toPlainDecoder,
toPlainEncoding,
)
import Cardano.Ledger.Coin (Coin)
Expand Down Expand Up @@ -427,7 +426,42 @@ instance FromJSON ShelleyGenesisStaking where
<*> (forceElemsToWHNF <$> obj .: "stake")

-- | Genesis are always encoded with the version of era they are defined in.
instance DecCBOR ShelleyGenesis
instance DecCBOR ShelleyGenesis where
decCBOR =
decodeRecordNamed "ShelleyGenesis" (const 15) $ do
sgSystemStart <- decCBOR
sgNetworkMagic <- decCBOR
sgNetworkId <- decCBOR
sgActiveSlotsCoeff <- activeSlotsCoeffDecCBOR
sgSecurityParam <- decCBOR
sgEpochLength <- decCBOR
sgSlotsPerKESPeriod <- decCBOR
sgMaxKESEvolutions <- decCBOR
sgSlotLength <- decCBOR
sgUpdateQuorum <- decCBOR
sgMaxLovelaceSupply <- decCBOR
sgProtocolParams <- decCBOR
sgGenDelegs <- decCBOR
sgInitialFunds <- decCBOR
sgStaking <- decCBOR
pure $
ShelleyGenesis
sgSystemStart
sgNetworkMagic
sgNetworkId
sgActiveSlotsCoeff
sgSecurityParam
(EpochSize sgEpochLength)
sgSlotsPerKESPeriod
sgMaxKESEvolutions
sgSlotLength
sgUpdateQuorum
sgMaxLovelaceSupply
sgProtocolParams
sgGenDelegs
sgInitialFunds
sgStaking
{-# INLINE decCBOR #-}

instance EncCBOR ShelleyGenesis

Expand Down Expand Up @@ -469,40 +503,8 @@ instance ToCBOR ShelleyGenesis where
<> encCBOR sgStaking

instance FromCBOR ShelleyGenesis where
fromCBOR = toPlainDecoder Nothing shelleyProtVer $ do
decodeRecordNamed "ShelleyGenesis" (const 15) $ do
sgSystemStart <- decCBOR
sgNetworkMagic <- decCBOR
sgNetworkId <- decCBOR
sgActiveSlotsCoeff <- activeSlotsCoeffDecCBOR
sgSecurityParam <- decCBOR
sgEpochLength <- decCBOR
sgSlotsPerKESPeriod <- decCBOR
sgMaxKESEvolutions <- decCBOR
sgSlotLength <- decCBOR
sgUpdateQuorum <- decCBOR
sgMaxLovelaceSupply <- decCBOR
sgProtocolParams <- decCBOR
sgGenDelegs <- decCBOR
sgInitialFunds <- decCBOR
sgStaking <- decCBOR
pure $
ShelleyGenesis
sgSystemStart
sgNetworkMagic
sgNetworkId
sgActiveSlotsCoeff
sgSecurityParam
(EpochSize sgEpochLength)
sgSlotsPerKESPeriod
sgMaxKESEvolutions
sgSlotLength
sgUpdateQuorum
sgMaxLovelaceSupply
sgProtocolParams
sgGenDelegs
sgInitialFunds
sgStaking
fromCBOR = fromEraCBOR @ShelleyEra
{-# INLINE fromCBOR #-}

-- | Serialize `PositiveUnitInterval` type in the same way `Rational` is serialized,
-- however ensure there is no usage of tag 30 by enforcing Shelley protocol version.
Expand Down
26 changes: 15 additions & 11 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

Expand All @@ -20,11 +21,17 @@ import Cardano.Ledger.Binary (
FromCBOR (..),
ToCBOR (..),
shelleyProtVer,
toPlainDecoder,
toPlainEncoding,
)
import Cardano.Ledger.Binary.Coders (Decode (..), Encode (..), decode, encode, (!>), (<!))
import Cardano.Ledger.Core (PParams, TranslationContext, emptyPParams)
import Cardano.Ledger.Binary.Coders (
Decode (..),
Encode (..),
decode,
encode,
(!>),
(<!),
)
import Cardano.Ledger.Core (PParams, TranslationContext, emptyPParams, fromEraCBOR)
import Cardano.Ledger.Keys
import Cardano.Ledger.Shelley.Era (ShelleyEra)
import Cardano.Ledger.Shelley.Genesis (ShelleyGenesis (..))
Expand Down Expand Up @@ -55,17 +62,14 @@ instance ToCBOR FromByronTranslationContext where
!> To fbtcMaxLovelaceSupply

instance FromCBOR FromByronTranslationContext where
fromCBOR =
toPlainDecoder Nothing shelleyProtVer $
decode $
RecD FromByronTranslationContext
<! From
<! From
<! From
fromCBOR = fromEraCBOR @ShelleyEra
{-# INLINE fromCBOR #-}

instance EncCBOR FromByronTranslationContext

instance DecCBOR FromByronTranslationContext
instance DecCBOR FromByronTranslationContext where
decCBOR = decode (RecD FromByronTranslationContext <! From <! From <! From)
{-# INLINE decCBOR #-}

instance FromJSON FromByronTranslationContext where
parseJSON = withObject "FromByronTranslationContext" $ \o -> do
Expand Down
1 change: 1 addition & 0 deletions libs/cardano-ledger-binary/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.8.0.0

* Remove default implementation for `DecCBOR` class
* Change `Version` from `Word64` to `Word32`
- Add `mkVersion32` and `getVersion32`
* Remove `listLenBound` from `EncCBORGroup`
Expand Down
Loading