{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

module Cardano.Api.Eon.ShelleyToMaryEra
  ( ShelleyToMaryEra (..)
  , shelleyToMaryEraConstraints
  , shelleyToMaryEraToShelleyBasedEra
  , ShelleyToMaryEraConstraints
  )
where

import           Cardano.Api.Eon.Convert
import           Cardano.Api.Eon.ShelleyBasedEra
import           Cardano.Api.Eras.Core
import           Cardano.Api.Modes
import           Cardano.Api.Query.Types

import           Cardano.Binary
import qualified Cardano.Crypto.Hash.Blake2b as Blake2b
import qualified Cardano.Crypto.Hash.Class as C
import qualified Cardano.Crypto.VRF as C
import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.BaseTypes as L
import qualified Cardano.Ledger.Core as L
import qualified Cardano.Ledger.SafeHash as L
import qualified Cardano.Ledger.Shelley.TxCert as L
import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus
import qualified Ouroboros.Consensus.Protocol.Praos.Common as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus

import           Data.Aeson
import           Data.Typeable (Typeable)

data ShelleyToMaryEra era where
  ShelleyToMaryEraShelley :: ShelleyToMaryEra ShelleyEra
  ShelleyToMaryEraAllegra :: ShelleyToMaryEra AllegraEra
  ShelleyToMaryEraMary :: ShelleyToMaryEra MaryEra

deriving instance Show (ShelleyToMaryEra era)

deriving instance Eq (ShelleyToMaryEra era)

instance Eon ShelleyToMaryEra where
  inEonForEra :: forall a era.
a -> (ShelleyToMaryEra era -> a) -> CardanoEra era -> a
inEonForEra a
no ShelleyToMaryEra era -> a
yes = \case
    CardanoEra era
ByronEra -> a
no
    CardanoEra era
ShelleyEra -> ShelleyToMaryEra era -> a
yes ShelleyToMaryEra era
ShelleyToMaryEra ShelleyEra
ShelleyToMaryEraShelley
    CardanoEra era
AllegraEra -> ShelleyToMaryEra era -> a
yes ShelleyToMaryEra era
ShelleyToMaryEra AllegraEra
ShelleyToMaryEraAllegra
    CardanoEra era
MaryEra -> ShelleyToMaryEra era -> a
yes ShelleyToMaryEra era
ShelleyToMaryEra MaryEra
ShelleyToMaryEraMary
    CardanoEra era
AlonzoEra -> a
no
    CardanoEra era
BabbageEra -> a
no
    CardanoEra era
ConwayEra -> a
no

instance ToCardanoEra ShelleyToMaryEra where
  toCardanoEra :: forall era. ShelleyToMaryEra era -> CardanoEra era
toCardanoEra = \case
    ShelleyToMaryEra era
ShelleyToMaryEraShelley -> CardanoEra era
CardanoEra ShelleyEra
ShelleyEra
    ShelleyToMaryEra era
ShelleyToMaryEraAllegra -> CardanoEra era
CardanoEra AllegraEra
AllegraEra
    ShelleyToMaryEra era
ShelleyToMaryEraMary -> CardanoEra era
CardanoEra MaryEra
MaryEra

instance Convert ShelleyToMaryEra CardanoEra where
  convert :: forall era. ShelleyToMaryEra era -> CardanoEra era
convert = ShelleyToMaryEra era -> CardanoEra era
forall era. ShelleyToMaryEra era -> CardanoEra era
forall (eon :: * -> *) era.
ToCardanoEra eon =>
eon era -> CardanoEra era
toCardanoEra

instance Convert ShelleyToMaryEra ShelleyBasedEra where
  convert :: forall era. ShelleyToMaryEra era -> ShelleyBasedEra era
convert = \case
    ShelleyToMaryEra era
ShelleyToMaryEraShelley -> ShelleyBasedEra era
ShelleyBasedEra ShelleyEra
ShelleyBasedEraShelley
    ShelleyToMaryEra era
ShelleyToMaryEraAllegra -> ShelleyBasedEra era
ShelleyBasedEra AllegraEra
ShelleyBasedEraAllegra
    ShelleyToMaryEra era
ShelleyToMaryEraMary -> ShelleyBasedEra era
ShelleyBasedEra MaryEra
ShelleyBasedEraMary

type ShelleyToMaryEraConstraints era =
  ( C.HashAlgorithm (L.HASH (L.EraCrypto (ShelleyLedgerEra era)))
  , C.Signable (L.VRF (L.EraCrypto (ShelleyLedgerEra era))) L.Seed
  , Consensus.PraosProtocolSupportsNode (ConsensusProtocol era)
  , Consensus.ShelleyBlock (ConsensusProtocol era) (ShelleyLedgerEra era) ~ ConsensusBlockForEra era
  , Consensus.ShelleyCompatible (ConsensusProtocol era) (ShelleyLedgerEra era)
  , L.ADDRHASH (Consensus.PraosProtocolSupportsNodeCrypto (ConsensusProtocol era)) ~ Blake2b.Blake2b_224
  , L.Crypto (L.EraCrypto (ShelleyLedgerEra era))
  , L.Era (ShelleyLedgerEra era)
  , L.EraCrypto (ShelleyLedgerEra era) ~ L.StandardCrypto
  , L.EraPParams (ShelleyLedgerEra era)
  , L.EraTx (ShelleyLedgerEra era)
  , L.EraTxBody (ShelleyLedgerEra era)
  , L.EraTxOut (ShelleyLedgerEra era)
  , L.HashAnnotated (L.TxBody (ShelleyLedgerEra era)) L.EraIndependentTxBody L.StandardCrypto
  , L.ProtVerAtMost (ShelleyLedgerEra era) 4
  , L.ProtVerAtMost (ShelleyLedgerEra era) 6
  , L.ProtVerAtMost (ShelleyLedgerEra era) 8
  , L.ShelleyEraTxBody (ShelleyLedgerEra era)
  , L.ShelleyEraTxCert (ShelleyLedgerEra era)
  , L.TxCert (ShelleyLedgerEra era) ~ L.ShelleyTxCert (ShelleyLedgerEra era)
  , FromCBOR (Consensus.ChainDepState (ConsensusProtocol era))
  , FromCBOR (DebugLedgerState era)
  , IsCardanoEra era
  , IsShelleyBasedEra era
  , ToJSON (DebugLedgerState era)
  , Typeable era
  )

shelleyToMaryEraConstraints
  :: ()
  => ShelleyToMaryEra era
  -> (ShelleyToMaryEraConstraints era => a)
  -> a
shelleyToMaryEraConstraints :: forall era a.
ShelleyToMaryEra era -> (ShelleyToMaryEraConstraints era => a) -> a
shelleyToMaryEraConstraints = \case
  ShelleyToMaryEra era
ShelleyToMaryEraShelley -> a -> a
(ShelleyToMaryEraConstraints era => a) -> a
forall a. a -> a
id
  ShelleyToMaryEra era
ShelleyToMaryEraAllegra -> a -> a
(ShelleyToMaryEraConstraints era => a) -> a
forall a. a -> a
id
  ShelleyToMaryEra era
ShelleyToMaryEraMary -> a -> a
(ShelleyToMaryEraConstraints era => a) -> a
forall a. a -> a
id

{-# DEPRECATED shelleyToMaryEraToShelleyBasedEra "Use 'convert' instead." #-}
shelleyToMaryEraToShelleyBasedEra :: ShelleyToMaryEra era -> ShelleyBasedEra era
shelleyToMaryEraToShelleyBasedEra :: forall era. ShelleyToMaryEra era -> ShelleyBasedEra era
shelleyToMaryEraToShelleyBasedEra = ShelleyToMaryEra era -> ShelleyBasedEra era
forall era. ShelleyToMaryEra era -> ShelleyBasedEra era
forall a (f :: a -> *) (g :: a -> *) (era :: a).
Convert f g =>
f era -> g era
convert