From b97e379cda05d22b453013a3d46cf44119cf8082 Mon Sep 17 00:00:00 2001 From: Lucsanszky Date: Fri, 16 Feb 2024 01:29:39 +0100 Subject: [PATCH] Remove `EpochInterval` and co. from `BaseTypes` Both `EpochInterval` and `addEpochInterval` was moved to `cardano-slotting` in `cardano-base` as part of https://github.com/IntersectMBO/cardano-base/pull/456. Import them from there. --- libs/cardano-ledger-binary/CHANGELOG.md | 4 ++-- .../cardano-ledger-binary.cabal | 4 ++-- .../Cardano/Ledger/Binary/Decoding/DecCBOR.hs | 4 +++- .../Cardano/Ledger/Binary/Encoding/EncCBOR.hs | 4 +++- .../src/Cardano/Ledger/BaseTypes.hs | 18 +++--------------- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/libs/cardano-ledger-binary/CHANGELOG.md b/libs/cardano-ledger-binary/CHANGELOG.md index 6e642172901..a89be044813 100644 --- a/libs/cardano-ledger-binary/CHANGELOG.md +++ b/libs/cardano-ledger-binary/CHANGELOG.md @@ -1,8 +1,8 @@ # Version history for `cardano-ledger-binary` -## 1.3.0.1 +## 1.3.1.0 -* +* Add `EncCBOR` and `DecCBOR` instances for `EpochInterval` ## 1.3.0.0 diff --git a/libs/cardano-ledger-binary/cardano-ledger-binary.cabal b/libs/cardano-ledger-binary/cardano-ledger-binary.cabal index c645e97b464..52def83c028 100644 --- a/libs/cardano-ledger-binary/cardano-ledger-binary.cabal +++ b/libs/cardano-ledger-binary/cardano-ledger-binary.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: cardano-ledger-binary -version: 1.3.0.0 +version: 1.3.1.0 license: Apache-2.0 maintainer: operations@iohk.io author: IOHK @@ -53,7 +53,7 @@ library cardano-binary >=1.7, cardano-crypto-class >=2.1, cardano-crypto-praos >=2.1, - cardano-slotting, + cardano-slotting >=0.2, cardano-strict-containers >=0.1.2, cborg >=0.2.9, containers, diff --git a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs index 88d96cc363b..8fda4114b83 100644 --- a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs +++ b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs @@ -51,7 +51,7 @@ import Cardano.Ledger.Binary.Crypto import Cardano.Ledger.Binary.Decoding.Decoder import Cardano.Ledger.Binary.Version (Version, byronProtVer) import Cardano.Slotting.Block (BlockNo (..)) -import Cardano.Slotting.Slot (EpochNo (..), EpochSize (..), SlotNo (..), WithOrigin (..)) +import Cardano.Slotting.Slot (EpochInterval (..), EpochNo (..), EpochSize (..), SlotNo (..), WithOrigin (..)) import Cardano.Slotting.Time (SystemStart (..)) import Codec.CBOR.ByteArray (ByteArray (..)) import Codec.CBOR.ByteArray.Sliced (SlicedByteArray, fromByteArray) @@ -646,6 +646,8 @@ instance DecCBOR BlockNo where decCBOR = fromPlainDecoder decode {-# INLINE decCBOR #-} +deriving instance DecCBOR EpochInterval + -------------------------------------------------------------------------------- -- Plutus -------------------------------------------------------------------------------- diff --git a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs index c6752288a95..ea0e4637deb 100644 --- a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs +++ b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs @@ -107,7 +107,7 @@ import Cardano.Ledger.Binary.Crypto import Cardano.Ledger.Binary.Encoding.Encoder import Cardano.Ledger.Binary.Version (Version, byronProtVer, getVersion64) import Cardano.Slotting.Block (BlockNo (..)) -import Cardano.Slotting.Slot (EpochNo (..), EpochSize (..), SlotNo (..), WithOrigin (..)) +import Cardano.Slotting.Slot (EpochInterval (..), EpochNo (..), EpochSize (..), SlotNo (..), WithOrigin (..)) import Cardano.Slotting.Time (SystemStart (..)) import Codec.CBOR.ByteArray (ByteArray (..)) import Codec.CBOR.ByteArray.Sliced (SlicedByteArray (SBA), fromByteArray) @@ -1147,6 +1147,8 @@ instance EncCBOR BlockNo where encCBOR = fromPlainEncoding . Serialise.encode encodedSizeExpr size = encodedSizeExpr size . fmap unBlockNo +deriving instance EncCBOR EpochInterval + -------------------------------------------------------------------------------- -- Plutus -------------------------------------------------------------------------------- diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs index f019cdf5613..0896c90ee80 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs @@ -53,8 +53,6 @@ module Cardano.Ledger.BaseTypes ( activeSlotLog, module Data.Maybe.Strict, BlocksMade (..), - EpochInterval (..), - addEpochInterval, kindObject, -- * Indices @@ -124,10 +122,12 @@ import Cardano.Ledger.SafeHash (HashWithCrypto (..), SafeHash, SafeToHash) import Cardano.Slotting.Block as Slotting (BlockNo (..)) import Cardano.Slotting.EpochInfo (EpochInfo, hoistEpochInfo) import Cardano.Slotting.Slot as Slotting ( + EpochInterval (..), EpochNo (..), EpochSize (..), SlotNo (..), WithOrigin (..), + addEpochInterval, binOpEpochNo, ) import Cardano.Slotting.Time (SystemStart) @@ -169,7 +169,7 @@ import Data.Text (Text) import qualified Data.Text as Text import Data.Text.Encoding (encodeUtf8) import Data.Typeable (Typeable) -import Data.Word (Word16, Word32, Word64, Word8) +import Data.Word (Word16, Word64, Word8) import GHC.Exception.Type (Exception) import GHC.Generics (Generic) import GHC.Stack (HasCallStack) @@ -836,18 +836,6 @@ toAnchorPairs vote@(Anchor _ _) = instance Default Network where def = Mainnet --- | Denotes a positive change in the EpochNo -newtype EpochInterval = EpochInterval - { unEpochInterval :: Word32 - } - deriving (Eq, Ord, Generic) - deriving (Show) via Quiet EpochInterval - deriving newtype (NoThunks, NFData, ToJSON, FromJSON, EncCBOR, DecCBOR, ToCBOR, FromCBOR) - --- | Add a EpochInterval (a positive change) to an EpochNo to get a new EpochNo -addEpochInterval :: EpochNo -> EpochInterval -> EpochNo -addEpochInterval (EpochNo n) (EpochInterval m) = EpochNo (n + fromIntegral m) - class Inject t s where inject :: t -> s default inject :: t ~ s => t -> s