{-# LANGUAGE AllowAmbiguousTypes   #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module Ouroboros.Consensus.Protocol.Translate (TranslateProto (..)) where

import           Ouroboros.Consensus.Protocol.Abstract
import           Ouroboros.Consensus.Ticked (Ticked)

-- | Translate across protocols
class TranslateProto protoFrom protoTo
  where
  translateConsensusConfig ::
    ConsensusConfig protoFrom -> ConsensusConfig protoTo
  -- | Translate the ticked ledger view.
  translateTickedLedgerView ::
    Ticked (LedgerView protoFrom) -> Ticked (LedgerView protoTo)
  translateChainDepState ::
    ChainDepState protoFrom -> ChainDepState protoTo

-- | Degenerate instance - we may always translate from a protocol to itself.
instance TranslateProto singleProto singleProto
  where
  translateConsensusConfig :: ConsensusConfig singleProto -> ConsensusConfig singleProto
translateConsensusConfig = ConsensusConfig singleProto -> ConsensusConfig singleProto
forall a. a -> a
id
  translateTickedLedgerView :: Ticked (LedgerView singleProto) -> Ticked (LedgerView singleProto)
translateTickedLedgerView = Ticked (LedgerView singleProto) -> Ticked (LedgerView singleProto)
forall a. a -> a
id
  translateChainDepState :: ChainDepState singleProto -> ChainDepState singleProto
translateChainDepState = ChainDepState singleProto -> ChainDepState singleProto
forall a. a -> a
id