-- | Conversions from ouroboros-consensus types to the Byron spec types
--
-- Intended for unqualified import.
module Ouroboros.Consensus.ByronSpec.Ledger.Conversions (
    -- * Spec to consensus
    fromByronSpecPrevHash
  , fromByronSpecSlotNo
    -- * Consensus to spec
  , toByronSpecSlotNo
  ) where

import           Ouroboros.Consensus.Block

import qualified Byron.Spec.Chain.STS.Block as Spec
import qualified Byron.Spec.Ledger.Core as Spec

{-------------------------------------------------------------------------------
  Spec to consensus
-------------------------------------------------------------------------------}

fromByronSpecPrevHash :: (Spec.Hash -> HeaderHash b)
                      -> Spec.Hash -> ChainHash b
fromByronSpecPrevHash :: (Hash -> HeaderHash b) -> Hash -> ChainHash b
fromByronSpecPrevHash Hash -> HeaderHash b
f Hash
h
  | Hash
h Hash -> Hash -> Bool
forall a. Eq a => a -> a -> Bool
== Hash
Spec.genesisHash = ChainHash b
forall b. ChainHash b
GenesisHash
  | Bool
otherwise             = HeaderHash b -> ChainHash b
forall b. HeaderHash b -> ChainHash b
BlockHash (Hash -> HeaderHash b
f Hash
h)

fromByronSpecSlotNo :: Spec.Slot -> SlotNo
fromByronSpecSlotNo :: Slot -> SlotNo
fromByronSpecSlotNo (Spec.Slot Word64
slot) = Word64 -> SlotNo
SlotNo Word64
slot

{-------------------------------------------------------------------------------
  Consensus to spec
-------------------------------------------------------------------------------}

toByronSpecSlotNo :: SlotNo -> Spec.Slot
toByronSpecSlotNo :: SlotNo -> Slot
toByronSpecSlotNo (SlotNo Word64
slot) = Word64 -> Slot
Spec.Slot Word64
slot