{-# LANGUAGE DataKinds                #-}
{-# LANGUAGE DeriveGeneric            #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE GADTs                    #-}
{-# LANGUAGE PatternSynonyms          #-}
{-# LANGUAGE ViewPatterns             #-}
module Ouroboros.Consensus.Cardano.Block (
    -- * Eras
    module Ouroboros.Consensus.Shelley.Eras
  , CardanoEras
    -- * Block
  , CardanoBlock
    -- Note: by exporting the pattern synonyms as part of the matching data
    -- type (instead of as separate patterns), we get better exhaustiveness
    -- checks from GHC. But GHC expects a data type, not a type family, that's
    -- why we sometimes mention the data type of the instance in these exports
    -- instead of the abstract type family.
  , HardForkBlock (
        BlockByron
      , BlockShelley
      , BlockAllegra
      , BlockMary
      )
    -- * Headers
  , CardanoHeader
  , Header (
        HeaderByron
      , HeaderShelley
      , HeaderAllegra
      , HeaderMary
      )
    -- * Generalised transactions
  , CardanoGenTx
  , GenTx (
        GenTxByron
      , GenTxShelley
      , GenTxAllegra
      , GenTxMary
      )
  , CardanoGenTxId
  , TxId (
        GenTxIdByron
      , GenTxIdShelley
      , GenTxIdAllegra
      , GenTxIdMary
      )
  , CardanoApplyTxErr
  , HardForkApplyTxErr (
        ApplyTxErrByron
      , ApplyTxErrShelley
      , ApplyTxErrAllegra
      , ApplyTxErrMary
      , ApplyTxErrWrongEra
      )
    -- * LedgerError
  , CardanoLedgerError
  , HardForkLedgerError (
        LedgerErrorByron
      , LedgerErrorShelley
      , LedgerErrorAllegra
      , LedgerErrorMary
      , LedgerErrorWrongEra
      )
    -- * OtherEnvelopeError
  , CardanoOtherHeaderEnvelopeError
  , HardForkEnvelopeErr (
        OtherHeaderEnvelopeErrorByron
      , OtherHeaderEnvelopeErrorShelley
      , OtherHeaderEnvelopeErrorAllegra
      , OtherHeaderEnvelopeErrorMary
      , OtherHeaderEnvelopeErrorWrongEra
      )
    -- * TipInfo
  , CardanoTipInfo
  , OneEraTipInfo (
        TipInfoByron
      , TipInfoShelley
      , TipInfoAllegra
      , TipInfoMary
      )
    -- * Query
  , CardanoQuery
  , Query (
        QueryIfCurrentByron
      , QueryIfCurrentShelley
      , QueryIfCurrentAllegra
      , QueryIfCurrentMary
      , QueryAnytimeByron
      , QueryAnytimeShelley
      , QueryAnytimeAllegra
      , QueryAnytimeMary
      , QueryHardFork
     )
  , CardanoQueryResult
  , Either (QueryResultSuccess, QueryResultEraMismatch)
    -- * CodecConfig
  , CardanoCodecConfig
  , CodecConfig (CardanoCodecConfig)
    -- * BlockConfig
  , CardanoBlockConfig
  , BlockConfig (CardanoBlockConfig)
    -- * StorageConfig
  , CardanoStorageConfig
  , StorageConfig (CardanoStorageConfig)
    -- * ConsensusConfig
  , CardanoConsensusConfig
  , ConsensusConfig (CardanoConsensusConfig)
    -- * LedgerConfig
  , CardanoLedgerConfig
  , HardForkLedgerConfig (CardanoLedgerConfig)
    -- * LedgerState
  , CardanoLedgerState
  , LedgerState (
        LedgerStateByron
      , LedgerStateShelley
      , LedgerStateAllegra
      , LedgerStateMary
      )
    -- * ChainDepState
  , CardanoChainDepState
  , HardForkState (
        ChainDepStateByron
      , ChainDepStateShelley
      , ChainDepStateAllegra
      , ChainDepStateMary
      )
    -- * EraMismatch
  , EraMismatch (..)
  ) where

import           Data.SOP.Strict

import           Ouroboros.Consensus.Block (BlockProtocol)
import           Ouroboros.Consensus.HeaderValidation (OtherHeaderEnvelopeError,
                     TipInfo)
import           Ouroboros.Consensus.Ledger.Abstract (LedgerError)
import           Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr,
                     GenTxId)
import           Ouroboros.Consensus.Protocol.Abstract (ChainDepState)
import           Ouroboros.Consensus.TypeFamilyWrappers

import           Ouroboros.Consensus.HardFork.Combinator
import           Ouroboros.Consensus.HardFork.Combinator.AcrossEras
import qualified Ouroboros.Consensus.HardFork.Combinator.State as State

import           Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock)

import           Ouroboros.Consensus.Shelley.Eras
import           Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)

{-------------------------------------------------------------------------------
  The eras of the Cardano bock chain
-------------------------------------------------------------------------------}

-- | The eras in the Cardano blockchain.
--
-- We parameterise over the crypto used in the post-Byron eras: @c@.
--
-- TODO: parameterise ByronBlock over crypto too
type CardanoEras c =
  '[ ByronBlock
   , ShelleyBlock (ShelleyEra c)
   , ShelleyBlock (AllegraEra c)
   , ShelleyBlock (MaryEra c)
   ]

{-------------------------------------------------------------------------------
  The block type of the Cardano block chain
-------------------------------------------------------------------------------}

-- | /The/ Cardano block.
--
-- Thanks to the pattern synonyms, you can treat this as a sum type with
-- constructors 'BlockByron' and 'BlockShelley'.
--
-- > f :: CardanoBlock c -> _
-- > f (BlockByron   b) = _
-- > f (BlockShelley s) = _
-- > f (BlockAllegra a) = _
-- > f (BlockMary    m) = _
--
type CardanoBlock c = HardForkBlock (CardanoEras c)

pattern BlockByron :: ByronBlock -> CardanoBlock c
pattern $bBlockByron :: ByronBlock -> CardanoBlock c
$mBlockByron :: forall r c.
CardanoBlock c -> (ByronBlock -> r) -> (Void# -> r) -> r
BlockByron b = HardForkBlock (OneEraBlock (Z (I b)))

pattern BlockShelley :: ShelleyBlock (ShelleyEra c) -> CardanoBlock c
pattern $bBlockShelley :: ShelleyBlock (ShelleyEra c) -> CardanoBlock c
$mBlockShelley :: forall r c.
CardanoBlock c
-> (ShelleyBlock (ShelleyEra c) -> r) -> (Void# -> r) -> r
BlockShelley b = HardForkBlock (OneEraBlock (S (Z (I b))))

pattern BlockAllegra :: ShelleyBlock (AllegraEra c) -> CardanoBlock c
pattern $bBlockAllegra :: ShelleyBlock (AllegraEra c) -> CardanoBlock c
$mBlockAllegra :: forall r c.
CardanoBlock c
-> (ShelleyBlock (ShelleyEra c) -> r) -> (Void# -> r) -> r
BlockAllegra b = HardForkBlock (OneEraBlock (S (S (Z (I b)))))

pattern BlockMary :: ShelleyBlock (MaryEra c) -> CardanoBlock c
pattern $bBlockMary :: ShelleyBlock (MaryEra c) -> CardanoBlock c
$mBlockMary :: forall r c.
CardanoBlock c
-> (ShelleyBlock (ShelleyEra c) -> r) -> (Void# -> r) -> r
BlockMary b = HardForkBlock (OneEraBlock (S (S (S (Z (I b))))))

{-# COMPLETE BlockByron, BlockShelley, BlockAllegra, BlockMary #-}

{-------------------------------------------------------------------------------
  Headers
-------------------------------------------------------------------------------}

-- | The Cardano header.
type CardanoHeader c = Header (CardanoBlock c)

pattern HeaderByron :: Header ByronBlock -> CardanoHeader c
pattern $bHeaderByron :: Header ByronBlock -> CardanoHeader c
$mHeaderByron :: forall r c.
CardanoHeader c -> (Header ByronBlock -> r) -> (Void# -> r) -> r
HeaderByron h = HardForkHeader (OneEraHeader (Z h))

pattern HeaderShelley ::
     Header (ShelleyBlock (ShelleyEra c))
  -> CardanoHeader c
pattern $bHeaderShelley :: Header (ShelleyBlock (ShelleyEra c)) -> CardanoHeader c
$mHeaderShelley :: forall r c.
CardanoHeader c
-> (Header (ShelleyBlock (ShelleyEra c)) -> r) -> (Void# -> r) -> r
HeaderShelley h = HardForkHeader (OneEraHeader (S (Z h)))

pattern HeaderAllegra ::
     Header (ShelleyBlock (AllegraEra c))
  -> CardanoHeader c
pattern $bHeaderAllegra :: Header (ShelleyBlock (AllegraEra c)) -> CardanoHeader c
$mHeaderAllegra :: forall r c.
CardanoHeader c
-> (Header (ShelleyBlock (ShelleyEra c)) -> r) -> (Void# -> r) -> r
HeaderAllegra h = HardForkHeader (OneEraHeader (S (S (Z h))))

pattern HeaderMary ::
     Header (ShelleyBlock (MaryEra c))
  -> CardanoHeader c
pattern $bHeaderMary :: Header (ShelleyBlock (MaryEra c)) -> CardanoHeader c
$mHeaderMary :: forall r c.
CardanoHeader c
-> (Header (ShelleyBlock (ShelleyEra c)) -> r) -> (Void# -> r) -> r
HeaderMary h = HardForkHeader (OneEraHeader (S (S (S (Z h)))))

{-# COMPLETE HeaderByron, HeaderShelley, HeaderAllegra, HeaderMary #-}

{-------------------------------------------------------------------------------
  Generalised transactions
-------------------------------------------------------------------------------}

-- | The Cardano transaction.
type CardanoGenTx c = GenTx (CardanoBlock c)

pattern GenTxByron :: GenTx ByronBlock -> CardanoGenTx c
pattern $bGenTxByron :: GenTx ByronBlock -> CardanoGenTx c
$mGenTxByron :: forall r c.
CardanoGenTx c -> (GenTx ByronBlock -> r) -> (Void# -> r) -> r
GenTxByron tx = HardForkGenTx (OneEraGenTx (Z tx))

pattern GenTxShelley :: GenTx (ShelleyBlock (ShelleyEra c)) -> CardanoGenTx c
pattern $bGenTxShelley :: GenTx (ShelleyBlock (ShelleyEra c)) -> CardanoGenTx c
$mGenTxShelley :: forall r c.
CardanoGenTx c
-> (GenTx (ShelleyBlock (ShelleyEra c)) -> r) -> (Void# -> r) -> r
GenTxShelley tx = HardForkGenTx (OneEraGenTx (S (Z tx)))

pattern GenTxAllegra :: GenTx (ShelleyBlock (AllegraEra c)) -> CardanoGenTx c
pattern $bGenTxAllegra :: GenTx (ShelleyBlock (AllegraEra c)) -> CardanoGenTx c
$mGenTxAllegra :: forall r c.
CardanoGenTx c
-> (GenTx (ShelleyBlock (ShelleyEra c)) -> r) -> (Void# -> r) -> r
GenTxAllegra tx = HardForkGenTx (OneEraGenTx (S (S (Z tx))))

pattern GenTxMary :: GenTx (ShelleyBlock (MaryEra c)) -> CardanoGenTx c
pattern $bGenTxMary :: GenTx (ShelleyBlock (MaryEra c)) -> CardanoGenTx c
$mGenTxMary :: forall r c.
CardanoGenTx c
-> (GenTx (ShelleyBlock (ShelleyEra c)) -> r) -> (Void# -> r) -> r
GenTxMary tx = HardForkGenTx (OneEraGenTx (S (S (S (Z tx)))))

{-# COMPLETE GenTxByron, GenTxShelley, GenTxAllegra, GenTxMary #-}

-- | The ID of a Cardano transaction.
type CardanoGenTxId c = GenTxId (CardanoBlock c)

pattern GenTxIdByron :: GenTxId ByronBlock -> CardanoGenTxId c
pattern $bGenTxIdByron :: GenTxId ByronBlock -> CardanoGenTxId c
$mGenTxIdByron :: forall r c.
CardanoGenTxId c -> (GenTxId ByronBlock -> r) -> (Void# -> r) -> r
GenTxIdByron txid =
    HardForkGenTxId (OneEraGenTxId (Z (WrapGenTxId txid)))

pattern GenTxIdShelley ::
     GenTxId (ShelleyBlock (ShelleyEra c))
  -> CardanoGenTxId c
pattern $bGenTxIdShelley :: GenTxId (ShelleyBlock (ShelleyEra c)) -> CardanoGenTxId c
$mGenTxIdShelley :: forall r c.
CardanoGenTxId c
-> (GenTxId (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
GenTxIdShelley txid =
    HardForkGenTxId (OneEraGenTxId (S (Z (WrapGenTxId txid))))

pattern GenTxIdAllegra ::
     GenTxId (ShelleyBlock (AllegraEra c))
  -> CardanoGenTxId c
pattern $bGenTxIdAllegra :: GenTxId (ShelleyBlock (AllegraEra c)) -> CardanoGenTxId c
$mGenTxIdAllegra :: forall r c.
CardanoGenTxId c
-> (GenTxId (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
GenTxIdAllegra txid =
    HardForkGenTxId (OneEraGenTxId (S (S (Z (WrapGenTxId txid)))))

pattern GenTxIdMary ::
     GenTxId (ShelleyBlock (MaryEra c))
  -> CardanoGenTxId c
pattern $bGenTxIdMary :: GenTxId (ShelleyBlock (MaryEra c)) -> CardanoGenTxId c
$mGenTxIdMary :: forall r c.
CardanoGenTxId c
-> (GenTxId (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
GenTxIdMary txid =
    HardForkGenTxId (OneEraGenTxId (S (S (S (Z (WrapGenTxId txid))))))

{-# COMPLETE GenTxIdByron, GenTxIdShelley, GenTxIdAllegra, GenTxIdMary #-}

-- | An error resulting from applying a 'CardanoGenTx' to the ledger.
--
-- Thanks to the pattern synonyms, you can treat this as a sum type with
-- constructors 'ApplyTxByronErr', 'ApplyTxErrShelley', and
-- 'ApplyTxErrWrongEra'.
--
-- > toText :: CardanoApplyTxErr c -> Text
-- > toText (ApplyTxErrByron b) = byronApplyTxErrToText b
-- > toText (ApplyTxErrShelley s) = shelleyApplyTxErrToText s
-- > toText (ApplyTxErrAllegra a) = allegraApplyTxErrToText a
-- > toText (ApplyTxErrMary m) = maryApplyTxErrToText m
-- > toText (ApplyTxErrWrongEra eraMismatch) =
-- >   "Transaction from the " <> otherEraName eraMismatch <>
-- >   " era applied to a ledger from the " <>
-- >   ledgerEraName eraMismatch <> " era"
--
type CardanoApplyTxErr c = HardForkApplyTxErr (CardanoEras c)

pattern ApplyTxErrByron :: ApplyTxErr ByronBlock -> CardanoApplyTxErr c
pattern $bApplyTxErrByron :: ApplyTxErr ByronBlock -> CardanoApplyTxErr c
$mApplyTxErrByron :: forall r c.
CardanoApplyTxErr c
-> (ApplyTxErr ByronBlock -> r) -> (Void# -> r) -> r
ApplyTxErrByron err =
    HardForkApplyTxErrFromEra (OneEraApplyTxErr (Z (WrapApplyTxErr err)))

pattern ApplyTxErrShelley ::
     ApplyTxErr (ShelleyBlock (ShelleyEra c))
  -> CardanoApplyTxErr c
pattern $bApplyTxErrShelley :: ApplyTxErr (ShelleyBlock (ShelleyEra c)) -> CardanoApplyTxErr c
$mApplyTxErrShelley :: forall r c.
CardanoApplyTxErr c
-> (ApplyTxErr (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
ApplyTxErrShelley err =
    HardForkApplyTxErrFromEra (OneEraApplyTxErr (S (Z (WrapApplyTxErr err))))

pattern ApplyTxErrAllegra ::
     ApplyTxErr (ShelleyBlock (AllegraEra c))
  -> CardanoApplyTxErr c
pattern $bApplyTxErrAllegra :: ApplyTxErr (ShelleyBlock (AllegraEra c)) -> CardanoApplyTxErr c
$mApplyTxErrAllegra :: forall r c.
CardanoApplyTxErr c
-> (ApplyTxErr (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
ApplyTxErrAllegra err =
    HardForkApplyTxErrFromEra (OneEraApplyTxErr (S (S (Z (WrapApplyTxErr err)))))

pattern ApplyTxErrMary ::
     ApplyTxErr (ShelleyBlock (MaryEra c))
  -> CardanoApplyTxErr c
pattern $bApplyTxErrMary :: ApplyTxErr (ShelleyBlock (MaryEra c)) -> CardanoApplyTxErr c
$mApplyTxErrMary :: forall r c.
CardanoApplyTxErr c
-> (ApplyTxErr (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
ApplyTxErrMary err =
    HardForkApplyTxErrFromEra (OneEraApplyTxErr (S (S (S (Z (WrapApplyTxErr err))))))

pattern ApplyTxErrWrongEra :: EraMismatch -> CardanoApplyTxErr c
pattern $mApplyTxErrWrongEra :: forall r c.
CardanoApplyTxErr c -> (EraMismatch -> r) -> (Void# -> r) -> r
ApplyTxErrWrongEra eraMismatch <-
    HardForkApplyTxErrWrongEra (mkEraMismatch -> eraMismatch)

{-# COMPLETE ApplyTxErrByron
           , ApplyTxErrShelley
           , ApplyTxErrAllegra
           , ApplyTxErrMary
           , ApplyTxErrWrongEra #-}

{-------------------------------------------------------------------------------
  LedgerError
-------------------------------------------------------------------------------}

-- | An error resulting from applying a 'CardanoBlock' to the ledger.
--
-- Thanks to the pattern synonyms, you can treat this as a sum type with
-- constructors 'LedgerErrorByron', 'LedgerErrorShelley', and
-- 'LedgerErrorWrongEra'.
--
-- > toText :: CardanoLedgerError c -> Text
-- > toText (LedgerErrorByron b) = byronLedgerErrorToText b
-- > toText (LedgerErrorShelley s) = shelleyLedgerErrorToText s
-- > toText (LedgerErrorAllegra a) = allegraLedgerErrorToText a
-- > toText (LedgerErrorMary m) = maryLedgerErrorToText m
-- > toText (LedgerErrorWrongEra eraMismatch) =
-- >   "Block from the " <> otherEraName eraMismatch <>
-- >   " era applied to a ledger from the " <>
-- >   ledgerEraName eraMismatch <> " era"
--
type CardanoLedgerError c = HardForkLedgerError (CardanoEras c)

pattern LedgerErrorByron :: LedgerError ByronBlock -> CardanoLedgerError c
pattern $bLedgerErrorByron :: LedgerError ByronBlock -> CardanoLedgerError c
$mLedgerErrorByron :: forall r c.
CardanoLedgerError c
-> (LedgerError ByronBlock -> r) -> (Void# -> r) -> r
LedgerErrorByron err =
    HardForkLedgerErrorFromEra (OneEraLedgerError (Z (WrapLedgerErr err)))

pattern LedgerErrorShelley ::
     LedgerError (ShelleyBlock (ShelleyEra c))
  -> CardanoLedgerError c
pattern $bLedgerErrorShelley :: LedgerError (ShelleyBlock (ShelleyEra c)) -> CardanoLedgerError c
$mLedgerErrorShelley :: forall r c.
CardanoLedgerError c
-> (LedgerError (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
LedgerErrorShelley err =
    HardForkLedgerErrorFromEra
      (OneEraLedgerError (S (Z (WrapLedgerErr err))))

pattern LedgerErrorAllegra ::
     LedgerError (ShelleyBlock (AllegraEra c))
  -> CardanoLedgerError c
pattern $bLedgerErrorAllegra :: LedgerError (ShelleyBlock (AllegraEra c)) -> CardanoLedgerError c
$mLedgerErrorAllegra :: forall r c.
CardanoLedgerError c
-> (LedgerError (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
LedgerErrorAllegra err =
    HardForkLedgerErrorFromEra
      (OneEraLedgerError (S (S (Z (WrapLedgerErr err)))))

pattern LedgerErrorMary ::
     LedgerError (ShelleyBlock (MaryEra c))
  -> CardanoLedgerError c
pattern $bLedgerErrorMary :: LedgerError (ShelleyBlock (MaryEra c)) -> CardanoLedgerError c
$mLedgerErrorMary :: forall r c.
CardanoLedgerError c
-> (LedgerError (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
LedgerErrorMary err =
    HardForkLedgerErrorFromEra
      (OneEraLedgerError (S (S (S (Z (WrapLedgerErr err))))))

pattern LedgerErrorWrongEra :: EraMismatch -> CardanoLedgerError c
pattern $mLedgerErrorWrongEra :: forall r c.
CardanoLedgerError c -> (EraMismatch -> r) -> (Void# -> r) -> r
LedgerErrorWrongEra eraMismatch <-
    HardForkLedgerErrorWrongEra (mkEraMismatch -> eraMismatch)

{-# COMPLETE LedgerErrorByron
           , LedgerErrorShelley
           , LedgerErrorAllegra
           , LedgerErrorMary
           , LedgerErrorWrongEra #-}

{-------------------------------------------------------------------------------
  OtherEnvelopeError
-------------------------------------------------------------------------------}

-- | An error resulting from validating a 'CardanoHeader'.
type CardanoOtherHeaderEnvelopeError c = HardForkEnvelopeErr (CardanoEras c)

pattern OtherHeaderEnvelopeErrorByron
  :: OtherHeaderEnvelopeError ByronBlock
  -> CardanoOtherHeaderEnvelopeError c
pattern $bOtherHeaderEnvelopeErrorByron :: OtherHeaderEnvelopeError ByronBlock
-> CardanoOtherHeaderEnvelopeError c
$mOtherHeaderEnvelopeErrorByron :: forall r c.
CardanoOtherHeaderEnvelopeError c
-> (OtherHeaderEnvelopeError ByronBlock -> r) -> (Void# -> r) -> r
OtherHeaderEnvelopeErrorByron err =
    HardForkEnvelopeErrFromEra
      (OneEraEnvelopeErr (Z (WrapEnvelopeErr err)))

pattern OtherHeaderEnvelopeErrorShelley
  :: OtherHeaderEnvelopeError (ShelleyBlock (ShelleyEra c))
  -> CardanoOtherHeaderEnvelopeError c
pattern $bOtherHeaderEnvelopeErrorShelley :: OtherHeaderEnvelopeError (ShelleyBlock (ShelleyEra c))
-> CardanoOtherHeaderEnvelopeError c
$mOtherHeaderEnvelopeErrorShelley :: forall r c.
CardanoOtherHeaderEnvelopeError c
-> (OtherHeaderEnvelopeError (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
OtherHeaderEnvelopeErrorShelley err =
    HardForkEnvelopeErrFromEra (OneEraEnvelopeErr (S (Z (WrapEnvelopeErr err))))

pattern OtherHeaderEnvelopeErrorAllegra
  :: OtherHeaderEnvelopeError (ShelleyBlock (AllegraEra c))
  -> CardanoOtherHeaderEnvelopeError c
pattern $bOtherHeaderEnvelopeErrorAllegra :: OtherHeaderEnvelopeError (ShelleyBlock (AllegraEra c))
-> CardanoOtherHeaderEnvelopeError c
$mOtherHeaderEnvelopeErrorAllegra :: forall r c.
CardanoOtherHeaderEnvelopeError c
-> (OtherHeaderEnvelopeError (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
OtherHeaderEnvelopeErrorAllegra err =
    HardForkEnvelopeErrFromEra (OneEraEnvelopeErr (S (S (Z (WrapEnvelopeErr err)))))

pattern OtherHeaderEnvelopeErrorMary
  :: OtherHeaderEnvelopeError (ShelleyBlock (MaryEra c))
  -> CardanoOtherHeaderEnvelopeError c
pattern $bOtherHeaderEnvelopeErrorMary :: OtherHeaderEnvelopeError (ShelleyBlock (MaryEra c))
-> CardanoOtherHeaderEnvelopeError c
$mOtherHeaderEnvelopeErrorMary :: forall r c.
CardanoOtherHeaderEnvelopeError c
-> (OtherHeaderEnvelopeError (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
OtherHeaderEnvelopeErrorMary err =
    HardForkEnvelopeErrFromEra (OneEraEnvelopeErr (S (S (S (Z (WrapEnvelopeErr err))))))

pattern OtherHeaderEnvelopeErrorWrongEra
  :: EraMismatch
  -> CardanoOtherHeaderEnvelopeError c
pattern $mOtherHeaderEnvelopeErrorWrongEra :: forall r c.
CardanoOtherHeaderEnvelopeError c
-> (EraMismatch -> r) -> (Void# -> r) -> r
OtherHeaderEnvelopeErrorWrongEra eraMismatch <-
    HardForkEnvelopeErrWrongEra (mkEraMismatch -> eraMismatch)

{-# COMPLETE OtherHeaderEnvelopeErrorByron
           , OtherHeaderEnvelopeErrorShelley
           , OtherHeaderEnvelopeErrorAllegra
           , OtherHeaderEnvelopeErrorMary
           , OtherHeaderEnvelopeErrorWrongEra #-}

{-------------------------------------------------------------------------------
  TipInfo
-------------------------------------------------------------------------------}

-- | The 'TipInfo' of the Cardano chain.
type CardanoTipInfo c = OneEraTipInfo (CardanoEras c)

pattern TipInfoByron :: TipInfo ByronBlock -> CardanoTipInfo c
pattern $bTipInfoByron :: TipInfo ByronBlock -> CardanoTipInfo c
$mTipInfoByron :: forall r c.
CardanoTipInfo c -> (TipInfo ByronBlock -> r) -> (Void# -> r) -> r
TipInfoByron ti = OneEraTipInfo (Z (WrapTipInfo ti))

pattern TipInfoShelley ::
     TipInfo (ShelleyBlock (ShelleyEra c))
  -> CardanoTipInfo c
pattern $bTipInfoShelley :: TipInfo (ShelleyBlock (ShelleyEra c)) -> CardanoTipInfo c
$mTipInfoShelley :: forall r c.
CardanoTipInfo c
-> (TipInfo (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
TipInfoShelley ti = OneEraTipInfo (S (Z (WrapTipInfo ti)))

pattern TipInfoAllegra ::
     TipInfo (ShelleyBlock (AllegraEra c))
  -> CardanoTipInfo c
pattern $bTipInfoAllegra :: TipInfo (ShelleyBlock (AllegraEra c)) -> CardanoTipInfo c
$mTipInfoAllegra :: forall r c.
CardanoTipInfo c
-> (TipInfo (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
TipInfoAllegra ti = OneEraTipInfo (S (S (Z (WrapTipInfo ti))))

pattern TipInfoMary ::
     TipInfo (ShelleyBlock (MaryEra c))
  -> CardanoTipInfo c
pattern $bTipInfoMary :: TipInfo (ShelleyBlock (MaryEra c)) -> CardanoTipInfo c
$mTipInfoMary :: forall r c.
CardanoTipInfo c
-> (TipInfo (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
TipInfoMary ti = OneEraTipInfo (S (S (S (Z (WrapTipInfo ti)))))

{-# COMPLETE TipInfoByron, TipInfoShelley, TipInfoAllegra, TipInfoMary #-}

{-------------------------------------------------------------------------------
  Query
-------------------------------------------------------------------------------}

-- | The 'Query' of Cardano chain.
type CardanoQuery c = Query (CardanoBlock c)

-- | Byron-specific query that can only be answered when the ledger is in the
-- Byron era.
pattern QueryIfCurrentByron
  :: ()
  => CardanoQueryResult c result ~ a
  => Query ByronBlock result
  -> CardanoQuery c a
pattern $bQueryIfCurrentByron :: Query ByronBlock result -> CardanoQuery c a
$mQueryIfCurrentByron :: forall r c a.
CardanoQuery c a
-> (forall result.
    (CardanoQueryResult c result ~ a) =>
    Query ByronBlock result -> r)
-> (Void# -> r)
-> r
QueryIfCurrentByron q = QueryIfCurrent (QZ q)

-- | Shelley-specific query that can only be answered when the ledger is in the
-- Shelley era.
pattern QueryIfCurrentShelley
  :: ()
  => CardanoQueryResult c result ~ a
  => Query (ShelleyBlock (ShelleyEra c)) result
  -> CardanoQuery c a
pattern $bQueryIfCurrentShelley :: Query (ShelleyBlock (ShelleyEra c)) result -> CardanoQuery c a
$mQueryIfCurrentShelley :: forall r c a.
CardanoQuery c a
-> (forall result.
    (CardanoQueryResult c result ~ a) =>
    Query (ShelleyBlock (ShelleyEra c)) result -> r)
-> (Void# -> r)
-> r
QueryIfCurrentShelley q = QueryIfCurrent (QS (QZ q))

-- | Allegra-specific query that can only be answered when the ledger is in the
-- Allegra era.
pattern QueryIfCurrentAllegra
  :: ()
  => CardanoQueryResult c result ~ a
  => Query (ShelleyBlock (AllegraEra c)) result
  -> CardanoQuery c a
pattern $bQueryIfCurrentAllegra :: Query (ShelleyBlock (AllegraEra c)) result -> CardanoQuery c a
$mQueryIfCurrentAllegra :: forall r c a.
CardanoQuery c a
-> (forall result.
    (CardanoQueryResult c result ~ a) =>
    Query (ShelleyBlock (ShelleyEra c)) result -> r)
-> (Void# -> r)
-> r
QueryIfCurrentAllegra q = QueryIfCurrent (QS (QS (QZ q)))

-- | Mary-specific query that can only be answered when the ledger is in the
-- Mary era.
pattern QueryIfCurrentMary
  :: ()
  => CardanoQueryResult c result ~ a
  => Query (ShelleyBlock (MaryEra c)) result
  -> CardanoQuery c a
pattern $bQueryIfCurrentMary :: Query (ShelleyBlock (MaryEra c)) result -> CardanoQuery c a
$mQueryIfCurrentMary :: forall r c a.
CardanoQuery c a
-> (forall result.
    (CardanoQueryResult c result ~ a) =>
    Query (ShelleyBlock (ShelleyEra c)) result -> r)
-> (Void# -> r)
-> r
QueryIfCurrentMary q = QueryIfCurrent (QS (QS (QS (QZ q))))

-- | Query about the Byron era that can be answered anytime, i.e.,
-- independent from where the tip of the ledger is.
--
-- For example, to ask for the start of the Byron era (whether the tip of
-- the ledger is in the Byron, Shelley, ... era), use:
--
-- > QueryAnytimeByron EraStart
--
pattern QueryAnytimeByron
  :: QueryAnytime result
  -> CardanoQuery c result
pattern $bQueryAnytimeByron :: QueryAnytime result -> CardanoQuery c result
$mQueryAnytimeByron :: forall r result c.
CardanoQuery c result
-> (QueryAnytime result -> r) -> (Void# -> r) -> r
QueryAnytimeByron q = QueryAnytime q (EraIndex (Z (K ())))

-- | Query about the Shelley era that can be answered anytime, i.e.,
-- independent from where the tip of the ledger is.
--
-- For example, to ask for the start of the Shelley era (whether the tip of the
-- ledger is in the Byron, Shelley, ... era), use:
--
-- > QueryAnytimeShelley EraStart
--
pattern QueryAnytimeShelley
  :: QueryAnytime result
  -> CardanoQuery c result
pattern $bQueryAnytimeShelley :: QueryAnytime result -> CardanoQuery c result
$mQueryAnytimeShelley :: forall r result c.
CardanoQuery c result
-> (QueryAnytime result -> r) -> (Void# -> r) -> r
QueryAnytimeShelley q = QueryAnytime q (EraIndex (S (Z (K ()))))

-- | Query about the Allegra era that can be answered anytime, i.e.,
-- independent from where the tip of the ledger is.
--
-- For example, to ask for the start of the Allegra era (whether the tip of the
-- ledger is in the Byron, Shelley, ... era), use:
--
-- > QueryAnytimeAllegra EraStart
--
pattern QueryAnytimeAllegra
  :: QueryAnytime result
  -> CardanoQuery c result
pattern $bQueryAnytimeAllegra :: QueryAnytime result -> CardanoQuery c result
$mQueryAnytimeAllegra :: forall r result c.
CardanoQuery c result
-> (QueryAnytime result -> r) -> (Void# -> r) -> r
QueryAnytimeAllegra q = QueryAnytime q (EraIndex (S (S (Z (K ())))))

-- | Query about the Mary era that can be answered anytime, i.e.,
-- independent from where the tip of the ledger is.
--
-- For example, to ask for the start of the Mary era (whether the tip of the
-- ledger is in the Byron, Shelley, ... era), use:
--
-- > QueryAnytimeMary EraStart
--
pattern QueryAnytimeMary
  :: QueryAnytime result
  -> CardanoQuery c result
pattern $bQueryAnytimeMary :: QueryAnytime result -> CardanoQuery c result
$mQueryAnytimeMary :: forall r result c.
CardanoQuery c result
-> (QueryAnytime result -> r) -> (Void# -> r) -> r
QueryAnytimeMary q = QueryAnytime q (EraIndex (S (S (Z (K ())))))

{-# COMPLETE QueryIfCurrentByron
           , QueryIfCurrentShelley
           , QueryIfCurrentAllegra
           , QueryIfCurrentMary
           , QueryAnytimeByron
           , QueryAnytimeShelley
           , QueryAnytimeAllegra
           , QueryAnytimeMary
           , QueryHardFork #-}

-- | The result of a 'CardanoQuery'
--
-- Thanks to the pattern synonyms, you can treat this as a sum type with
-- constructors 'QueryResultSuccess' and 'QueryResultEraMismatch'.
type CardanoQueryResult c = HardForkQueryResult (CardanoEras c)

pattern QueryResultSuccess :: result -> CardanoQueryResult c result
pattern $bQueryResultSuccess :: result -> CardanoQueryResult c result
$mQueryResultSuccess :: forall r result c.
CardanoQueryResult c result -> (result -> r) -> (Void# -> r) -> r
QueryResultSuccess result = Right result

-- | A query from a different era than the ledger's era was sent.
pattern QueryResultEraMismatch :: EraMismatch -> CardanoQueryResult c result
pattern $mQueryResultEraMismatch :: forall r c result.
CardanoQueryResult c result
-> (EraMismatch -> r) -> (Void# -> r) -> r
QueryResultEraMismatch eraMismatch <- Left (mkEraMismatch -> eraMismatch)

{-# COMPLETE QueryResultSuccess, QueryResultEraMismatch #-}

{-------------------------------------------------------------------------------
  CodecConfig
-------------------------------------------------------------------------------}

-- | The 'CodecConfig' for 'CardanoBlock'.
--
-- Thanks to the pattern synonyms, you can treat this as the product of
-- the Byron, Shelley, ... 'CodecConfig's.
type CardanoCodecConfig c = CodecConfig (CardanoBlock c)

pattern CardanoCodecConfig
  :: CodecConfig ByronBlock
  -> CodecConfig (ShelleyBlock (ShelleyEra c))
  -> CodecConfig (ShelleyBlock (AllegraEra c))
  -> CodecConfig (ShelleyBlock (MaryEra c))
  -> CardanoCodecConfig c
pattern $bCardanoCodecConfig :: CodecConfig ByronBlock
-> CodecConfig (ShelleyBlock (ShelleyEra c))
-> CodecConfig (ShelleyBlock (ShelleyEra c))
-> CodecConfig (ShelleyBlock (ShelleyEra c))
-> CardanoCodecConfig c
$mCardanoCodecConfig :: forall r c.
CardanoCodecConfig c
-> (CodecConfig ByronBlock
    -> CodecConfig (ShelleyBlock (ShelleyEra c))
    -> CodecConfig (ShelleyBlock (ShelleyEra c))
    -> CodecConfig (ShelleyBlock (ShelleyEra c))
    -> r)
-> (Void# -> r)
-> r
CardanoCodecConfig cfgByron cfgShelley cfgAllegra cfgMary =
    HardForkCodecConfig {
        hardForkCodecConfigPerEra = PerEraCodecConfig
          (  cfgByron
          :* cfgShelley
          :* cfgAllegra
          :* cfgMary
          :* Nil
          )
      }

{-# COMPLETE CardanoCodecConfig #-}

{-------------------------------------------------------------------------------
  BlockConfig
-------------------------------------------------------------------------------}

-- | The 'BlockConfig' for 'CardanoBlock'.
--
-- Thanks to the pattern synonyms, you can treat this as the product of
-- the Byron, Shelley, ... 'BlockConfig's.
type CardanoBlockConfig c = BlockConfig (CardanoBlock c)

pattern CardanoBlockConfig
  :: BlockConfig ByronBlock
  -> BlockConfig (ShelleyBlock (ShelleyEra c))
  -> BlockConfig (ShelleyBlock (AllegraEra c))
  -> BlockConfig (ShelleyBlock (MaryEra c))
  -> CardanoBlockConfig c
pattern $bCardanoBlockConfig :: BlockConfig ByronBlock
-> BlockConfig (ShelleyBlock (ShelleyEra c))
-> BlockConfig (ShelleyBlock (ShelleyEra c))
-> BlockConfig (ShelleyBlock (ShelleyEra c))
-> CardanoBlockConfig c
$mCardanoBlockConfig :: forall r c.
CardanoBlockConfig c
-> (BlockConfig ByronBlock
    -> BlockConfig (ShelleyBlock (ShelleyEra c))
    -> BlockConfig (ShelleyBlock (ShelleyEra c))
    -> BlockConfig (ShelleyBlock (ShelleyEra c))
    -> r)
-> (Void# -> r)
-> r
CardanoBlockConfig cfgByron cfgShelley cfgAllegra cfgMary =
    HardForkBlockConfig {
        hardForkBlockConfigPerEra = PerEraBlockConfig
          (  cfgByron
          :* cfgShelley
          :* cfgAllegra
          :* cfgMary
          :* Nil
          )
      }

{-# COMPLETE CardanoBlockConfig #-}

{-------------------------------------------------------------------------------
  StorageConfig
-------------------------------------------------------------------------------}

-- | The 'StorageConfig' for 'CardanoBlock'.
--
-- Thanks to the pattern synonyms, you can treat this as the product of
-- the Byron, Shelley, ... 'StorageConfig's.
type CardanoStorageConfig c = StorageConfig (CardanoBlock c)

pattern CardanoStorageConfig
  :: StorageConfig ByronBlock
  -> StorageConfig (ShelleyBlock (ShelleyEra c))
  -> StorageConfig (ShelleyBlock (AllegraEra c))
  -> StorageConfig (ShelleyBlock (MaryEra c))
  -> CardanoStorageConfig c
pattern $bCardanoStorageConfig :: StorageConfig ByronBlock
-> StorageConfig (ShelleyBlock (ShelleyEra c))
-> StorageConfig (ShelleyBlock (ShelleyEra c))
-> StorageConfig (ShelleyBlock (ShelleyEra c))
-> CardanoStorageConfig c
$mCardanoStorageConfig :: forall r c.
CardanoStorageConfig c
-> (StorageConfig ByronBlock
    -> StorageConfig (ShelleyBlock (ShelleyEra c))
    -> StorageConfig (ShelleyBlock (ShelleyEra c))
    -> StorageConfig (ShelleyBlock (ShelleyEra c))
    -> r)
-> (Void# -> r)
-> r
CardanoStorageConfig cfgByron cfgShelley cfgAllegra cfgMary =
    HardForkStorageConfig {
        hardForkStorageConfigPerEra = PerEraStorageConfig
          (  cfgByron
          :* cfgShelley
          :* cfgAllegra
          :* cfgMary
          :* Nil
          )
      }

{-# COMPLETE CardanoStorageConfig #-}

{-------------------------------------------------------------------------------
  ConsensusConfig
-------------------------------------------------------------------------------}

-- | The 'ConsensusConfig' for 'CardanoBlock'.
--
-- Thanks to the pattern synonyms, you can treat this as the product of the
-- Byron, Shelley, ... 'PartialConsensusConfig's.
--
-- NOTE: not 'ConsensusConfig', but 'PartialConsensusConfig'.
type CardanoConsensusConfig c =
  ConsensusConfig (HardForkProtocol (CardanoEras c))

pattern CardanoConsensusConfig
  :: PartialConsensusConfig (BlockProtocol ByronBlock)
  -> PartialConsensusConfig (BlockProtocol (ShelleyBlock (ShelleyEra c)))
  -> PartialConsensusConfig (BlockProtocol (ShelleyBlock (AllegraEra c)))
  -> PartialConsensusConfig (BlockProtocol (ShelleyBlock (MaryEra c)))
  -> CardanoConsensusConfig c
pattern $mCardanoConsensusConfig :: forall r c.
CardanoConsensusConfig c
-> (PartialConsensusConfig (BlockProtocol ByronBlock)
    -> PartialConsensusConfig
         (BlockProtocol (ShelleyBlock (ShelleyEra c)))
    -> PartialConsensusConfig
         (BlockProtocol (ShelleyBlock (ShelleyEra c)))
    -> PartialConsensusConfig
         (BlockProtocol (ShelleyBlock (ShelleyEra c)))
    -> r)
-> (Void# -> r)
-> r
CardanoConsensusConfig cfgByron cfgShelley cfgAllegra cfgMary <-
    HardForkConsensusConfig {
        hardForkConsensusConfigPerEra = PerEraConsensusConfig
          (  WrapPartialConsensusConfig cfgByron
          :* WrapPartialConsensusConfig cfgShelley
          :* WrapPartialConsensusConfig cfgAllegra
          :* WrapPartialConsensusConfig cfgMary
          :* Nil
          )
      }

{-# COMPLETE CardanoConsensusConfig #-}

{-------------------------------------------------------------------------------
  LedgerConfig
-------------------------------------------------------------------------------}

-- | The 'LedgerConfig' for 'CardanoBlock'.
--
-- Thanks to the pattern synonyms, you can treat this as the product of the
-- Byron, Shelley, ... 'PartialLedgerConfig's.
--
-- NOTE: not 'LedgerConfig', but 'PartialLedgerConfig'.
type CardanoLedgerConfig c = HardForkLedgerConfig (CardanoEras c)

pattern CardanoLedgerConfig
  :: PartialLedgerConfig ByronBlock
  -> PartialLedgerConfig (ShelleyBlock (ShelleyEra c))
  -> PartialLedgerConfig (ShelleyBlock (AllegraEra c))
  -> PartialLedgerConfig (ShelleyBlock (MaryEra c))
  -> CardanoLedgerConfig c
pattern $mCardanoLedgerConfig :: forall r c.
CardanoLedgerConfig c
-> (PartialLedgerConfig ByronBlock
    -> PartialLedgerConfig (ShelleyBlock (ShelleyEra c))
    -> PartialLedgerConfig (ShelleyBlock (ShelleyEra c))
    -> PartialLedgerConfig (ShelleyBlock (ShelleyEra c))
    -> r)
-> (Void# -> r)
-> r
CardanoLedgerConfig cfgByron cfgShelley cfgAllegra cfgMary <-
    HardForkLedgerConfig {
        hardForkLedgerConfigPerEra = PerEraLedgerConfig
          (  WrapPartialLedgerConfig cfgByron
          :* WrapPartialLedgerConfig cfgShelley
          :* WrapPartialLedgerConfig cfgAllegra
          :* WrapPartialLedgerConfig cfgMary
          :* Nil
          )
      }

{-# COMPLETE CardanoLedgerConfig #-}

{-------------------------------------------------------------------------------
  LedgerState
-------------------------------------------------------------------------------}

-- | The 'LedgerState' for 'CardanoBlock'.
--
-- NOTE: the 'CardanoLedgerState' contains more than just the current era's
-- 'LedgerState'. We don't give access to those internal details through the
-- pattern synonyms. This is also the reason the pattern synonyms are not
-- bidirectional.
type CardanoLedgerState c = LedgerState (CardanoBlock c)

pattern LedgerStateByron
  :: LedgerState ByronBlock
  -> CardanoLedgerState c
pattern $mLedgerStateByron :: forall r c.
CardanoLedgerState c
-> (LedgerState ByronBlock -> r) -> (Void# -> r) -> r
LedgerStateByron st <-
    HardForkLedgerState
      (State.HardForkState
        (TZ (State.Current { currentState = st })))

pattern LedgerStateShelley
  :: LedgerState (ShelleyBlock (ShelleyEra c))
  -> CardanoLedgerState c
pattern $mLedgerStateShelley :: forall r c.
CardanoLedgerState c
-> (LedgerState (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
LedgerStateShelley st <-
    HardForkLedgerState
      (State.HardForkState
        (TS _ (TZ (State.Current { currentState = st }))))

pattern LedgerStateAllegra
  :: LedgerState (ShelleyBlock (AllegraEra c))
  -> CardanoLedgerState c
pattern $mLedgerStateAllegra :: forall r c.
CardanoLedgerState c
-> (LedgerState (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
LedgerStateAllegra st <-
    HardForkLedgerState
      (State.HardForkState
        (TS _ (TS _ (TZ (State.Current { currentState = st })))))

pattern LedgerStateMary
  :: LedgerState (ShelleyBlock (MaryEra c))
  -> CardanoLedgerState c
pattern $mLedgerStateMary :: forall r c.
CardanoLedgerState c
-> (LedgerState (ShelleyBlock (ShelleyEra c)) -> r)
-> (Void# -> r)
-> r
LedgerStateMary st <-
    HardForkLedgerState
      (State.HardForkState
        (TS _ (TS _ (TS _ (TZ (State.Current { currentState = st }))))))

{-# COMPLETE LedgerStateByron
           , LedgerStateShelley
           , LedgerStateAllegra
           , LedgerStateMary #-}

{-------------------------------------------------------------------------------
  ChainDepState
-------------------------------------------------------------------------------}

-- | The 'ChainDepState' for 'CardanoBlock'.
--
-- NOTE: the 'CardanoChainDepState' contains more than just the current era's
-- 'ChainDepState'. We don't give access to those internal details through the
-- pattern synonyms. This is also the reason the pattern synonyms are not
-- bidirectional.
type CardanoChainDepState c = HardForkChainDepState (CardanoEras c)

pattern ChainDepStateByron
  :: ChainDepState (BlockProtocol ByronBlock)
  -> CardanoChainDepState c
pattern $mChainDepStateByron :: forall r c.
CardanoChainDepState c
-> (ChainDepState (BlockProtocol ByronBlock) -> r)
-> (Void# -> r)
-> r
ChainDepStateByron st <-
    State.HardForkState
      (TZ (State.Current { currentState = WrapChainDepState st }))

pattern ChainDepStateShelley
  :: ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c)))
  -> CardanoChainDepState c
pattern $mChainDepStateShelley :: forall r c.
CardanoChainDepState c
-> (ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c)))
    -> r)
-> (Void# -> r)
-> r
ChainDepStateShelley st <-
    State.HardForkState
      (TS _ (TZ (State.Current { currentState = WrapChainDepState st })))

pattern ChainDepStateAllegra
  :: ChainDepState (BlockProtocol (ShelleyBlock (AllegraEra c)))
  -> CardanoChainDepState c
pattern $mChainDepStateAllegra :: forall r c.
CardanoChainDepState c
-> (ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c)))
    -> r)
-> (Void# -> r)
-> r
ChainDepStateAllegra st <-
    State.HardForkState
      (TS _ (TS _ (TZ (State.Current { currentState = WrapChainDepState st }))))

pattern ChainDepStateMary
  :: ChainDepState (BlockProtocol (ShelleyBlock (MaryEra c)))
  -> CardanoChainDepState c
pattern $mChainDepStateMary :: forall r c.
CardanoChainDepState c
-> (ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c)))
    -> r)
-> (Void# -> r)
-> r
ChainDepStateMary st <-
    State.HardForkState
      (TS _ (TS _ (TS _ (TZ (State.Current { currentState = WrapChainDepState st })))))

{-# COMPLETE ChainDepStateByron
           , ChainDepStateShelley
           , ChainDepStateAllegra
           , ChainDepStateMary #-}