Skip to content

Commit

Permalink
[ADP-3215] Move KnownEras to Cardano.Read.Ledger.Eras (#4719)
Browse files Browse the repository at this point in the history
This pull request moves the module `Cardano.Wallet.Read.Eras.KnownEras`
to `Cardano.Read.Ledger.Eras.KnownEras`. This is almost a pure
refactoring, except that this pull request also adds a small function
`indexOfEra`.

### Issue Number

ADP-3215
  • Loading branch information
HeinrichApfelmus authored Aug 5, 2024
2 parents 2cbb59a + 95096bb commit 4659ef6
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 112 deletions.
3 changes: 2 additions & 1 deletion lib/read/cardano-wallet-read.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ library
Cardano.Read.Ledger.Block.HeaderHash
Cardano.Read.Ledger.Block.SlotNo
Cardano.Read.Ledger.Block.Txs
Cardano.Read.Ledger.Eras
Cardano.Read.Ledger.Eras.KnownEras
Cardano.Read.Ledger.Tx.Inputs
Cardano.Read.Ledger.Tx.Outputs
Cardano.Read.Ledger.Tx.TxId
Expand Down Expand Up @@ -83,7 +85,6 @@ library
Cardano.Wallet.Read.Eras
Cardano.Wallet.Read.Eras.EraFun
Cardano.Wallet.Read.Eras.EraValue
Cardano.Wallet.Read.Eras.KnownEras
Cardano.Wallet.Read.Hash
Cardano.Wallet.Read.Tx
Cardano.Wallet.Read.Tx.Gen
Expand Down
2 changes: 1 addition & 1 deletion lib/read/lib/Cardano/Read/Ledger/Block/BHeader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Cardano.Ledger.Block
import Cardano.Read.Ledger.Block.Block
( Block (..)
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand Down
6 changes: 4 additions & 2 deletions lib/read/lib/Cardano/Read/Ledger/Block/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ import Prelude
import Cardano.Ledger.Api
( StandardCrypto
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
, Byron
, Conway
, Era (..)
, EraValue (..)
, IsEra (..)
, Mary
, Shelley
)
import Cardano.Wallet.Read.Eras
( EraValue (..)
, eraValue
)
import Ouroboros.Consensus.Protocol.Praos
Expand Down
2 changes: 1 addition & 1 deletion lib/read/lib/Cardano/Read/Ledger/Block/BlockNo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Prelude
import Cardano.Read.Ledger.Block.BHeader
( BHeader (..)
)
import Cardano.Wallet.Read.Eras.KnownEras
import Cardano.Read.Ledger.Eras
( Era (..)
, IsEra (..)
)
Expand Down
2 changes: 1 addition & 1 deletion lib/read/lib/Cardano/Read/Ledger/Block/HeaderHash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Cardano.Protocol.TPraos.BHeader
import Cardano.Read.Ledger.Block.Block
( Block (..)
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand Down
2 changes: 1 addition & 1 deletion lib/read/lib/Cardano/Read/Ledger/Block/SlotNo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Prelude
import Cardano.Read.Ledger.Block.BHeader
( BHeader (..)
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Era (..)
, IsEra (..)
)
Expand Down
2 changes: 1 addition & 1 deletion lib/read/lib/Cardano/Read/Ledger/Block/Txs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Cardano.Ledger.Binary
import Cardano.Read.Ledger.Block.Block
( Block (..)
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Byron
, Era (..)
, IsEra (..)
Expand Down
9 changes: 9 additions & 0 deletions lib/read/lib/Cardano/Read/Ledger/Eras.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{- |
Copyright: © 2024 Cardano Foundation
License: Apache-2.0
-}
module Cardano.Read.Ledger.Eras
( module Cardano.Read.Ledger.Eras.KnownEras
) where

import Cardano.Read.Ledger.Eras.KnownEras
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}

-- |
-- Copyright: © 2020-2022 IOHK
-- License: Apache-2.0
--
-- A type list of known eras, useful for indexed-by-era operations.
{- |
Copyright: © 2020-2022 IOHK, 2024 Cardano Foundation
License: Apache-2.0
module Cardano.Wallet.Read.Eras.KnownEras
( KnownEras
, knownEraIndices
, Era (..)
A type list of known eras, useful for indexing types by era.
-}
module Cardano.Read.Ledger.Eras.KnownEras
( Era (..)
, IsEra (..)

, KnownEras
, knownEraIndices
, indexOfEra

, Allegra
, Alonzo
, Babbage
Expand Down Expand Up @@ -70,10 +72,21 @@ instance IsEra Alonzo where theEra = Alonzo
instance IsEra Babbage where theEra = Babbage
instance IsEra Conway where theEra = Conway

-- | Type-level list of known eras.
-- | Type-level list of known eras, in chronological order.
type KnownEras =
'[Byron, Shelley, Allegra, Mary, Alonzo, Babbage, Conway]

-- | Official numbering of the KnownEras.
-- | Official numbering of the 'KnownEras'.
knownEraIndices :: [Int]
knownEraIndices = [0 .. lengthSList (Proxy :: Proxy KnownEras) - 1]

-- | Official number of the member of 'KnownEras'.
indexOfEra :: Era era -> Int
indexOfEra e = case e of
Byron -> 0
Shelley -> 1
Allegra -> 2
Mary -> 3
Alonzo -> 4
Babbage -> 5
Conway -> 6
6 changes: 4 additions & 2 deletions lib/read/lib/Cardano/Read/Ledger/Tx/CBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ import Cardano.Ledger.Binary.Decoding
, decodeFullAnnotator
, shelleyProtVer
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Era (..)
, EraValue
, IsEra (..)
)
import Cardano.Wallet.Read.Eras
( EraValue
, K (..)
, applyEraFunValue
, extractEraValue
Expand Down
6 changes: 4 additions & 2 deletions lib/read/lib/Cardano/Read/Ledger/Tx/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ module Cardano.Read.Ledger.Tx.Cardano

import Prelude

import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
, Conway
, EraValue
, Mary
, Shelley
)
import Cardano.Wallet.Read.Eras
( EraValue (..)
, eraValue
)
import Cardano.Wallet.Read.Tx
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/Certificates.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import Cardano.Ledger.Conway.TxCert
import Cardano.Ledger.Shelley.TxCert
( ShelleyTxCert
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -48,6 +45,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/CollateralInputs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import Cardano.Ledger.Api
import Cardano.Ledger.Core
( bodyTxL
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -44,6 +41,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/CollateralOutputs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ import Cardano.Ledger.Babbage.TxBody
import Cardano.Ledger.Core
( bodyTxL
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -53,6 +50,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/ExtraSigs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ import Cardano.Ledger.Keys
( KeyHash
, KeyRole (..)
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -45,6 +42,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/Fee.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import Cardano.Ledger.Core
( bodyTxL
, feeTxBodyL
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -44,6 +41,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ import Cardano.Ledger.Core
import Cardano.Ledger.TxIn
( TxId (..)
)
import Cardano.Read.Ledger.Eras
( Era (..)
, IsEra (..)
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read
( Tx
)
import Cardano.Wallet.Read.Eras
( Era (..)
, IsEra (..)
)
import Control.Lens
( (^.)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/Inputs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import Cardano.Ledger.Core
( bodyTxL
, inputsTxBodyL
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -42,6 +39,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/Integrity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ import Cardano.Ledger.Api
import Cardano.Ledger.Core
( bodyTxL
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -49,6 +46,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
8 changes: 4 additions & 4 deletions lib/read/lib/Cardano/Read/Ledger/Tx/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import Cardano.Ledger.Core
import Cardano.Ledger.Shelley.TxAuxData
( ShelleyTxAuxData
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Eras
import Cardano.Read.Ledger.Eras
( Allegra
, Alonzo
, Babbage
Expand All @@ -48,6 +45,9 @@ import Cardano.Wallet.Read.Eras
, Mary
, Shelley
)
import Cardano.Read.Ledger.Tx.Eras
( onTx
)
import Cardano.Wallet.Read.Tx
( Tx (..)
)
Expand Down
Loading

0 comments on commit 4659ef6

Please sign in to comment.