{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}

-- The Shelley ledger uses promoted data kinds which we have to use, but we do
-- not export any from this API. We also use them unticked as nature intended.
{-# LANGUAGE DataKinds #-}
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}


-- | Queries from local clients to the node.
--
module Cardano.Api.Query (

    -- * Queries
    QueryInMode(..),
    QueryInEra(..),
    QueryInShelleyBasedEra(..),
    QueryUTxOFilter(..),
    UTxO(..),
    UTxOInAnyEra(..),

    -- * Internal conversion functions
    toConsensusQuery,
    fromConsensusQueryResult,

    -- * Wrapper types used in queries
    SerialisedDebugLedgerState(..),
    ProtocolState(..),

    DebugLedgerState(..),

    EraHistory(..),
    SystemStart(..),

    SlotsInEpoch(..),
    SlotsToEpochEnd(..),

    slotToEpoch,

    LedgerState(..),

    getProgress,

    -- * Internal conversion functions
    toLedgerUTxO,
    fromLedgerUTxO,
  ) where

import           Data.Aeson (ToJSON (..), object, (.=))
import           Data.Bifunctor (bimap)
import           Data.Map (Map)
import qualified Data.Map as Map
import           Data.Maybe (mapMaybe)
import           Data.SOP.Strict (SListI)
import           Data.Set (Set)
import qualified Data.Set as Set
import           Data.Typeable
import           Prelude

import           Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..))

import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus
import           Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch)
import qualified Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus
import qualified Ouroboros.Consensus.HardFork.Combinator.Degenerate as Consensus
import qualified Ouroboros.Consensus.HardFork.History as History
import qualified Ouroboros.Consensus.HardFork.History.Qry as Qry

import           Ouroboros.Consensus.BlockchainTime.WallClock.Types (RelativeTime, SlotLength)
import qualified Ouroboros.Consensus.Byron.Ledger as Consensus
import           Ouroboros.Consensus.Cardano.Block (StandardCrypto, LedgerState(..))
import qualified Ouroboros.Consensus.Cardano.Block as Consensus
import qualified Ouroboros.Consensus.Ledger.Query as Consensus
import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus
import           Ouroboros.Network.Block (Serialised)

import           Cardano.Binary
import           Cardano.Slotting.Time (SystemStart(..))

import qualified Cardano.Chain.Update.Validation.Interface as Byron.Update
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Era as Ledger

import qualified Shelley.Spec.Ledger.API as Shelley
import qualified Shelley.Spec.Ledger.LedgerState as Shelley

import           Cardano.Api.Address
import           Cardano.Api.Block
import           Cardano.Api.Certificate
import           Cardano.Api.Eras
import           Cardano.Api.GenesisParameters
import           Cardano.Api.KeysShelley
import           Cardano.Api.Modes
import           Cardano.Api.NetworkId
import           Cardano.Api.Orphans ()
import           Cardano.Api.ProtocolParameters
import           Cardano.Api.TxBody
import           Cardano.Api.Value

import           Data.Word (Word64)

-- ----------------------------------------------------------------------------
-- Queries
--

data QueryInMode mode result where
  QueryCurrentEra
    :: ConsensusModeIsMultiEra mode
    -> QueryInMode mode AnyCardanoEra

  QueryInEra
    :: EraInMode era mode
    -> QueryInEra era result
    -> QueryInMode mode (Either EraMismatch result)

  QueryEraHistory
    :: ConsensusModeIsMultiEra mode
    -> QueryInMode mode (EraHistory mode)

  QuerySystemStart
    :: QueryInMode mode SystemStart

data EraHistory mode where
  EraHistory
    :: ConsensusBlockForMode mode ~ Consensus.HardForkBlock xs
    => ConsensusMode mode
    -> History.Interpreter xs
    -> EraHistory mode

getProgress :: SlotNo -> EraHistory mode -> Either Qry.PastHorizonException (RelativeTime, SlotLength)
getProgress :: SlotNo
-> EraHistory mode
-> Either PastHorizonException (RelativeTime, SlotLength)
getProgress SlotNo
slotNo (EraHistory ConsensusMode mode
_ Interpreter xs
interpreter) = Interpreter xs
-> Qry (RelativeTime, SlotLength)
-> Either PastHorizonException (RelativeTime, SlotLength)
forall (xs :: [*]) a.
HasCallStack =>
Interpreter xs -> Qry a -> Either PastHorizonException a
Qry.interpretQuery Interpreter xs
interpreter (SlotNo -> Qry (RelativeTime, SlotLength)
Qry.slotToWallclock SlotNo
slotNo)

--TODO: add support for these
--     QueryEraStart   :: ConsensusModeIsMultiEra mode
--                     -> EraInMode era mode
--                     -> QueryInMode mode (Maybe EraStart)

newtype SlotsInEpoch = SlotsInEpoch Word64

newtype SlotsToEpochEnd = SlotsToEpochEnd Word64

slotToEpoch :: SlotNo -> EraHistory mode -> Either Qry.PastHorizonException (EpochNo, SlotsInEpoch, SlotsToEpochEnd)
slotToEpoch :: SlotNo
-> EraHistory mode
-> Either
     PastHorizonException (EpochNo, SlotsInEpoch, SlotsToEpochEnd)
slotToEpoch SlotNo
slotNo (EraHistory ConsensusMode mode
_ Interpreter xs
interpreter) = case Interpreter xs
-> Qry (EpochNo, Word64, Word64)
-> Either PastHorizonException (EpochNo, Word64, Word64)
forall (xs :: [*]) a.
HasCallStack =>
Interpreter xs -> Qry a -> Either PastHorizonException a
Qry.interpretQuery Interpreter xs
interpreter (SlotNo -> Qry (EpochNo, Word64, Word64)
Qry.slotToEpoch SlotNo
slotNo) of
  Right (EpochNo
epochNumber, Word64
slotsInEpoch, Word64
slotsToEpochEnd) -> (EpochNo, SlotsInEpoch, SlotsToEpochEnd)
-> Either
     PastHorizonException (EpochNo, SlotsInEpoch, SlotsToEpochEnd)
forall a b. b -> Either a b
Right (EpochNo
epochNumber, Word64 -> SlotsInEpoch
SlotsInEpoch Word64
slotsInEpoch, Word64 -> SlotsToEpochEnd
SlotsToEpochEnd Word64
slotsToEpochEnd)
  Left PastHorizonException
e -> PastHorizonException
-> Either
     PastHorizonException (EpochNo, SlotsInEpoch, SlotsToEpochEnd)
forall a b. a -> Either a b
Left PastHorizonException
e

deriving instance Show (QueryInMode mode result)

data QueryInEra era result where
     QueryByronUpdateState :: QueryInEra ByronEra ByronUpdateState

     QueryInShelleyBasedEra :: ShelleyBasedEra era
                            -> QueryInShelleyBasedEra era result
                            -> QueryInEra era result

deriving instance Show (QueryInEra era result)


data QueryInShelleyBasedEra era result where
     QueryChainPoint
       :: QueryInShelleyBasedEra era ChainPoint

     QueryEpoch
       :: QueryInShelleyBasedEra era EpochNo

     QueryGenesisParameters
       :: QueryInShelleyBasedEra era GenesisParameters

     QueryProtocolParameters
       :: QueryInShelleyBasedEra era ProtocolParameters

     QueryProtocolParametersUpdate
       :: QueryInShelleyBasedEra era
            (Map (Hash GenesisKey) ProtocolParametersUpdate)

     QueryStakeDistribution
       :: QueryInShelleyBasedEra era (Map (Hash StakePoolKey) Rational)

     QueryUTxO
       :: QueryUTxOFilter
       -> QueryInShelleyBasedEra era (UTxO era)

     QueryStakeAddresses
       :: Set StakeCredential
       -> NetworkId
       -> QueryInShelleyBasedEra era (Map StakeAddress Lovelace,
                                      Map StakeAddress PoolId)

     QueryStakePools
       :: QueryInShelleyBasedEra era (Set PoolId)

     QueryStakePoolParameters
       :: Set PoolId
       -> QueryInShelleyBasedEra era (Map PoolId StakePoolParameters)

     -- TODO: add support for RewardProvenance
     -- QueryPoolRanking
     --   :: QueryInShelleyBasedEra era RewardProvenance

     QueryDebugLedgerState
       :: QueryInShelleyBasedEra era (SerialisedDebugLedgerState era)

     QueryProtocolState
       :: QueryInShelleyBasedEra era (ProtocolState era)

deriving instance Show (QueryInShelleyBasedEra era result)


-- ----------------------------------------------------------------------------
-- Wrapper types used in queries
--

-- | Getting the /whole/ UTxO is obviously not efficient since the result can
-- be huge. Filtering by address is also not efficient because it requires a
-- linear search.
--
-- The 'QueryUTxOFilterByTxIn' is efficient since it fits with the structure of
-- the UTxO (which is indexed by 'TxIn').
--
data QueryUTxOFilter =
     -- | /O(n) time and space/ for utxo size n
     QueryUTxOWhole

     -- | /O(n) time, O(m) space/ for utxo size n, and address set size m
   | QueryUTxOByAddress (Set AddressAny)

     -- | /O(m log n) time, O(m) space/ for utxo size n, and address set size m
   | QueryUTxOByTxIn (Set TxIn)
  deriving (QueryUTxOFilter -> QueryUTxOFilter -> Bool
(QueryUTxOFilter -> QueryUTxOFilter -> Bool)
-> (QueryUTxOFilter -> QueryUTxOFilter -> Bool)
-> Eq QueryUTxOFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryUTxOFilter -> QueryUTxOFilter -> Bool
$c/= :: QueryUTxOFilter -> QueryUTxOFilter -> Bool
== :: QueryUTxOFilter -> QueryUTxOFilter -> Bool
$c== :: QueryUTxOFilter -> QueryUTxOFilter -> Bool
Eq, Int -> QueryUTxOFilter -> ShowS
[QueryUTxOFilter] -> ShowS
QueryUTxOFilter -> String
(Int -> QueryUTxOFilter -> ShowS)
-> (QueryUTxOFilter -> String)
-> ([QueryUTxOFilter] -> ShowS)
-> Show QueryUTxOFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryUTxOFilter] -> ShowS
$cshowList :: [QueryUTxOFilter] -> ShowS
show :: QueryUTxOFilter -> String
$cshow :: QueryUTxOFilter -> String
showsPrec :: Int -> QueryUTxOFilter -> ShowS
$cshowsPrec :: Int -> QueryUTxOFilter -> ShowS
Show)

--TODO: provide appropriate instances for these types as needed, e.g. JSON

newtype ByronUpdateState = ByronUpdateState Byron.Update.State
  deriving Int -> ByronUpdateState -> ShowS
[ByronUpdateState] -> ShowS
ByronUpdateState -> String
(Int -> ByronUpdateState -> ShowS)
-> (ByronUpdateState -> String)
-> ([ByronUpdateState] -> ShowS)
-> Show ByronUpdateState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ByronUpdateState] -> ShowS
$cshowList :: [ByronUpdateState] -> ShowS
show :: ByronUpdateState -> String
$cshow :: ByronUpdateState -> String
showsPrec :: Int -> ByronUpdateState -> ShowS
$cshowsPrec :: Int -> ByronUpdateState -> ShowS
Show

newtype UTxO era = UTxO (Map TxIn (TxOut era))
  deriving (UTxO era -> UTxO era -> Bool
(UTxO era -> UTxO era -> Bool)
-> (UTxO era -> UTxO era -> Bool) -> Eq (UTxO era)
forall era. UTxO era -> UTxO era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UTxO era -> UTxO era -> Bool
$c/= :: forall era. UTxO era -> UTxO era -> Bool
== :: UTxO era -> UTxO era -> Bool
$c== :: forall era. UTxO era -> UTxO era -> Bool
Eq, Int -> UTxO era -> ShowS
[UTxO era] -> ShowS
UTxO era -> String
(Int -> UTxO era -> ShowS)
-> (UTxO era -> String) -> ([UTxO era] -> ShowS) -> Show (UTxO era)
forall era. Int -> UTxO era -> ShowS
forall era. [UTxO era] -> ShowS
forall era. UTxO era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UTxO era] -> ShowS
$cshowList :: forall era. [UTxO era] -> ShowS
show :: UTxO era -> String
$cshow :: forall era. UTxO era -> String
showsPrec :: Int -> UTxO era -> ShowS
$cshowsPrec :: forall era. Int -> UTxO era -> ShowS
Show)

data UTxOInAnyEra where
  UTxOInAnyEra :: CardanoEra era
               -> UTxO era
               -> UTxOInAnyEra

deriving instance Show UTxOInAnyEra

instance IsCardanoEra era => ToJSON (UTxO era) where
  toJSON :: UTxO era -> Value
toJSON (UTxO Map TxIn (TxOut era)
m) = Map TxIn (TxOut era) -> Value
forall a. ToJSON a => a -> Value
toJSON Map TxIn (TxOut era)
m

newtype SerialisedDebugLedgerState era
  = SerialisedDebugLedgerState (Serialised (Shelley.NewEpochState (ShelleyLedgerEra era)))

data DebugLedgerState era where
  DebugLedgerState :: ShelleyLedgerEra era ~ ledgerera => Shelley.NewEpochState ledgerera -> DebugLedgerState era

instance (Typeable era, Shelley.TransLedgerState FromCBOR (ShelleyLedgerEra era)) => FromCBOR (DebugLedgerState era) where
  fromCBOR :: Decoder s (DebugLedgerState era)
fromCBOR = NewEpochState (ShelleyLedgerEra era) -> DebugLedgerState era
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
NewEpochState ledgerera -> DebugLedgerState era
DebugLedgerState (NewEpochState (ShelleyLedgerEra era) -> DebugLedgerState era)
-> Decoder s (NewEpochState (ShelleyLedgerEra era))
-> Decoder s (DebugLedgerState era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall s. Decoder s (NewEpochState (ShelleyLedgerEra era))
forall a s. FromCBOR a => Decoder s a
fromCBOR :: Decoder s (Shelley.NewEpochState (ShelleyLedgerEra era)))

-- TODO: Shelley based era class!
instance ( IsShelleyBasedEra era
         , ShelleyLedgerEra era ~ ledgerera
         , Consensus.ShelleyBasedEra ledgerera
         , ToJSON (Core.PParams ledgerera)
         , ToJSON (Core.PParamsDelta ledgerera)
         , ToJSON (Core.TxOut ledgerera)) => ToJSON (DebugLedgerState era) where
  toJSON :: DebugLedgerState era -> Value
toJSON (DebugLedgerState NewEpochState ledgerera
newEpochS) = [Pair] -> Value
object [ Text
"lastEpoch" Text -> EpochNo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NewEpochState ledgerera -> EpochNo
forall era. NewEpochState era -> EpochNo
Shelley.nesEL NewEpochState ledgerera
newEpochS
                                          , Text
"blocksBefore" Text -> BlocksMade (Crypto ledgerera) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NewEpochState ledgerera -> BlocksMade (Crypto ledgerera)
forall era. NewEpochState era -> BlocksMade (Crypto era)
Shelley.nesBprev NewEpochState ledgerera
newEpochS
                                          , Text
"blocksCurrent" Text -> BlocksMade (Crypto ledgerera) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NewEpochState ledgerera -> BlocksMade (Crypto ledgerera)
forall era. NewEpochState era -> BlocksMade (Crypto era)
Shelley.nesBcur NewEpochState ledgerera
newEpochS
                                          , Text
"stateBefore" Text -> EpochState ledgerera -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NewEpochState ledgerera -> EpochState ledgerera
forall era. NewEpochState era -> EpochState era
Shelley.nesEs NewEpochState ledgerera
newEpochS
                                          , Text
"possibleRewardUpdate" Text -> StrictMaybe (PulsingRewUpdate (Crypto ledgerera)) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NewEpochState ledgerera
-> StrictMaybe (PulsingRewUpdate (Crypto ledgerera))
forall era.
NewEpochState era -> StrictMaybe (PulsingRewUpdate (Crypto era))
Shelley.nesRu NewEpochState ledgerera
newEpochS
                                          , Text
"stakeDistrib" Text -> PoolDistr (Crypto ledgerera) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= NewEpochState ledgerera -> PoolDistr (Crypto ledgerera)
forall era. NewEpochState era -> PoolDistr (Crypto era)
Shelley.nesPd NewEpochState ledgerera
newEpochS
                                          ]

newtype ProtocolState era
  = ProtocolState (Serialised (Shelley.ChainDepState (Ledger.Crypto (ShelleyLedgerEra era))))

toShelleyAddrSet :: CardanoEra era
                 -> Set AddressAny
                 -> Set (Shelley.Addr Consensus.StandardCrypto)
toShelleyAddrSet :: CardanoEra era -> Set AddressAny -> Set (Addr StandardCrypto)
toShelleyAddrSet CardanoEra era
era =
    [Addr StandardCrypto] -> Set (Addr StandardCrypto)
forall a. Ord a => [a] -> Set a
Set.fromList
  ([Addr StandardCrypto] -> Set (Addr StandardCrypto))
-> (Set AddressAny -> [Addr StandardCrypto])
-> Set AddressAny
-> Set (Addr StandardCrypto)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AddressInEra era -> Addr StandardCrypto)
-> [AddressInEra era] -> [Addr StandardCrypto]
forall a b. (a -> b) -> [a] -> [b]
map AddressInEra era -> Addr StandardCrypto
forall era. AddressInEra era -> Addr StandardCrypto
toShelleyAddr
    -- Ignore any addresses that are not appropriate for the era,
    -- e.g. Shelley addresses in the Byron era, as these would not
    -- appear in the UTxO anyway.
  ([AddressInEra era] -> [Addr StandardCrypto])
-> (Set AddressAny -> [AddressInEra era])
-> Set AddressAny
-> [Addr StandardCrypto]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AddressAny -> Maybe (AddressInEra era))
-> [AddressAny] -> [AddressInEra era]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (CardanoEra era -> AddressAny -> Maybe (AddressInEra era)
forall era.
CardanoEra era -> AddressAny -> Maybe (AddressInEra era)
anyAddressInEra CardanoEra era
era)
  ([AddressAny] -> [AddressInEra era])
-> (Set AddressAny -> [AddressAny])
-> Set AddressAny
-> [AddressInEra era]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set AddressAny -> [AddressAny]
forall a. Set a -> [a]
Set.toList


toLedgerUTxO :: ShelleyLedgerEra era ~ ledgerera
             => Ledger.Crypto ledgerera ~ StandardCrypto
             => ShelleyBasedEra era
             -> UTxO era
             -> Shelley.UTxO ledgerera
toLedgerUTxO :: ShelleyBasedEra era -> UTxO era -> UTxO ledgerera
toLedgerUTxO ShelleyBasedEra era
era (UTxO Map TxIn (TxOut era)
utxo) =
    Map (TxIn StandardCrypto) (TxOut ledgerera) -> UTxO ledgerera
forall era. Map (TxIn (Crypto era)) (TxOut era) -> UTxO era
Shelley.UTxO
  (Map (TxIn StandardCrypto) (TxOut ledgerera) -> UTxO ledgerera)
-> (Map TxIn (TxOut era)
    -> Map (TxIn StandardCrypto) (TxOut ledgerera))
-> Map TxIn (TxOut era)
-> UTxO ledgerera
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(TxIn StandardCrypto, TxOut ledgerera)]
-> Map (TxIn StandardCrypto) (TxOut ledgerera)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
  ([(TxIn StandardCrypto, TxOut ledgerera)]
 -> Map (TxIn StandardCrypto) (TxOut ledgerera))
-> (Map TxIn (TxOut era)
    -> [(TxIn StandardCrypto, TxOut ledgerera)])
-> Map TxIn (TxOut era)
-> Map (TxIn StandardCrypto) (TxOut ledgerera)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((TxIn, TxOut era) -> (TxIn StandardCrypto, TxOut ledgerera))
-> [(TxIn, TxOut era)] -> [(TxIn StandardCrypto, TxOut ledgerera)]
forall a b. (a -> b) -> [a] -> [b]
map ((TxIn -> TxIn StandardCrypto)
-> (TxOut era -> TxOut ledgerera)
-> (TxIn, TxOut era)
-> (TxIn StandardCrypto, TxOut ledgerera)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap TxIn -> TxIn StandardCrypto
toShelleyTxIn (ShelleyBasedEra era -> TxOut era -> TxOut ledgerera
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut era -> TxOut ledgerera
toShelleyTxOut ShelleyBasedEra era
era))
  ([(TxIn, TxOut era)] -> [(TxIn StandardCrypto, TxOut ledgerera)])
-> (Map TxIn (TxOut era) -> [(TxIn, TxOut era)])
-> Map TxIn (TxOut era)
-> [(TxIn StandardCrypto, TxOut ledgerera)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map TxIn (TxOut era) -> [(TxIn, TxOut era)]
forall k a. Map k a -> [(k, a)]
Map.toList
  (Map TxIn (TxOut era) -> UTxO ledgerera)
-> Map TxIn (TxOut era) -> UTxO ledgerera
forall a b. (a -> b) -> a -> b
$ Map TxIn (TxOut era)
utxo

fromLedgerUTxO :: ShelleyLedgerEra era ~ ledgerera
               => Ledger.Crypto ledgerera ~ StandardCrypto
               => ShelleyBasedEra era
               -> Shelley.UTxO ledgerera
               -> UTxO era
fromLedgerUTxO :: ShelleyBasedEra era -> UTxO ledgerera -> UTxO era
fromLedgerUTxO ShelleyBasedEra era
era (Shelley.UTxO Map (TxIn (Crypto ledgerera)) (TxOut ledgerera)
utxo) =
    Map TxIn (TxOut era) -> UTxO era
forall era. Map TxIn (TxOut era) -> UTxO era
UTxO
  (Map TxIn (TxOut era) -> UTxO era)
-> (Map (TxIn StandardCrypto) (TxOut ledgerera)
    -> Map TxIn (TxOut era))
-> Map (TxIn StandardCrypto) (TxOut ledgerera)
-> UTxO era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(TxIn, TxOut era)] -> Map TxIn (TxOut era)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
  ([(TxIn, TxOut era)] -> Map TxIn (TxOut era))
-> (Map (TxIn StandardCrypto) (TxOut ledgerera)
    -> [(TxIn, TxOut era)])
-> Map (TxIn StandardCrypto) (TxOut ledgerera)
-> Map TxIn (TxOut era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((TxIn StandardCrypto, TxOut ledgerera) -> (TxIn, TxOut era))
-> [(TxIn StandardCrypto, TxOut ledgerera)] -> [(TxIn, TxOut era)]
forall a b. (a -> b) -> [a] -> [b]
map ((TxIn StandardCrypto -> TxIn)
-> (TxOut ledgerera -> TxOut era)
-> (TxIn StandardCrypto, TxOut ledgerera)
-> (TxIn, TxOut era)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap TxIn StandardCrypto -> TxIn
fromShelleyTxIn (ShelleyBasedEra era -> TxOut ledgerera -> TxOut era
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera) =>
ShelleyBasedEra era -> TxOut ledgerera -> TxOut era
fromShelleyTxOut ShelleyBasedEra era
era))
  ([(TxIn StandardCrypto, TxOut ledgerera)] -> [(TxIn, TxOut era)])
-> (Map (TxIn StandardCrypto) (TxOut ledgerera)
    -> [(TxIn StandardCrypto, TxOut ledgerera)])
-> Map (TxIn StandardCrypto) (TxOut ledgerera)
-> [(TxIn, TxOut era)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map (TxIn StandardCrypto) (TxOut ledgerera)
-> [(TxIn StandardCrypto, TxOut ledgerera)]
forall k a. Map k a -> [(k, a)]
Map.toList
  (Map (TxIn StandardCrypto) (TxOut ledgerera) -> UTxO era)
-> Map (TxIn StandardCrypto) (TxOut ledgerera) -> UTxO era
forall a b. (a -> b) -> a -> b
$ Map (TxIn StandardCrypto) (TxOut ledgerera)
Map (TxIn (Crypto ledgerera)) (TxOut ledgerera)
utxo

fromShelleyPoolDistr :: Shelley.PoolDistr StandardCrypto
                     -> Map (Hash StakePoolKey) Rational
fromShelleyPoolDistr :: PoolDistr StandardCrypto -> Map (Hash StakePoolKey) Rational
fromShelleyPoolDistr =
    --TODO: write an appropriate property to show it is safe to use
    -- Map.fromListAsc or to use Map.mapKeysMonotonic
    [(Hash StakePoolKey, Rational)] -> Map (Hash StakePoolKey) Rational
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
  ([(Hash StakePoolKey, Rational)]
 -> Map (Hash StakePoolKey) Rational)
-> (PoolDistr StandardCrypto -> [(Hash StakePoolKey, Rational)])
-> PoolDistr StandardCrypto
-> Map (Hash StakePoolKey) Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((KeyHash 'StakePool StandardCrypto,
  IndividualPoolStake StandardCrypto)
 -> (Hash StakePoolKey, Rational))
-> [(KeyHash 'StakePool StandardCrypto,
     IndividualPoolStake StandardCrypto)]
-> [(Hash StakePoolKey, Rational)]
forall a b. (a -> b) -> [a] -> [b]
map ((KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey)
-> (IndividualPoolStake StandardCrypto -> Rational)
-> (KeyHash 'StakePool StandardCrypto,
    IndividualPoolStake StandardCrypto)
-> (Hash StakePoolKey, Rational)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey
StakePoolKeyHash IndividualPoolStake StandardCrypto -> Rational
forall crypto. IndividualPoolStake crypto -> Rational
Shelley.individualPoolStake)
  ([(KeyHash 'StakePool StandardCrypto,
   IndividualPoolStake StandardCrypto)]
 -> [(Hash StakePoolKey, Rational)])
-> (PoolDistr StandardCrypto
    -> [(KeyHash 'StakePool StandardCrypto,
         IndividualPoolStake StandardCrypto)])
-> PoolDistr StandardCrypto
-> [(Hash StakePoolKey, Rational)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map
  (KeyHash 'StakePool StandardCrypto)
  (IndividualPoolStake StandardCrypto)
-> [(KeyHash 'StakePool StandardCrypto,
     IndividualPoolStake StandardCrypto)]
forall k a. Map k a -> [(k, a)]
Map.toList
  (Map
   (KeyHash 'StakePool StandardCrypto)
   (IndividualPoolStake StandardCrypto)
 -> [(KeyHash 'StakePool StandardCrypto,
      IndividualPoolStake StandardCrypto)])
-> (PoolDistr StandardCrypto
    -> Map
         (KeyHash 'StakePool StandardCrypto)
         (IndividualPoolStake StandardCrypto))
-> PoolDistr StandardCrypto
-> [(KeyHash 'StakePool StandardCrypto,
     IndividualPoolStake StandardCrypto)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PoolDistr StandardCrypto
-> Map
     (KeyHash 'StakePool StandardCrypto)
     (IndividualPoolStake StandardCrypto)
forall crypto.
PoolDistr crypto
-> Map (KeyHash 'StakePool crypto) (IndividualPoolStake crypto)
Shelley.unPoolDistr

fromShelleyDelegations :: Map (Shelley.Credential Shelley.Staking StandardCrypto)
                              (Shelley.KeyHash Shelley.StakePool StandardCrypto)
                       -> Map StakeCredential PoolId
fromShelleyDelegations :: Map
  (Credential 'Staking StandardCrypto)
  (KeyHash 'StakePool StandardCrypto)
-> Map StakeCredential (Hash StakePoolKey)
fromShelleyDelegations =
    --TODO: write an appropriate property to show it is safe to use
    -- Map.fromListAsc or to use Map.mapKeysMonotonic
    -- In this case it may not be: the Ord instances for Shelley.Credential
    -- do not match the one for StakeCredential
    [(StakeCredential, Hash StakePoolKey)]
-> Map StakeCredential (Hash StakePoolKey)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
  ([(StakeCredential, Hash StakePoolKey)]
 -> Map StakeCredential (Hash StakePoolKey))
-> (Map
      (Credential 'Staking StandardCrypto)
      (KeyHash 'StakePool StandardCrypto)
    -> [(StakeCredential, Hash StakePoolKey)])
-> Map
     (Credential 'Staking StandardCrypto)
     (KeyHash 'StakePool StandardCrypto)
-> Map StakeCredential (Hash StakePoolKey)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Credential 'Staking StandardCrypto,
  KeyHash 'StakePool StandardCrypto)
 -> (StakeCredential, Hash StakePoolKey))
-> [(Credential 'Staking StandardCrypto,
     KeyHash 'StakePool StandardCrypto)]
-> [(StakeCredential, Hash StakePoolKey)]
forall a b. (a -> b) -> [a] -> [b]
map ((Credential 'Staking StandardCrypto -> StakeCredential)
-> (KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey)
-> (Credential 'Staking StandardCrypto,
    KeyHash 'StakePool StandardCrypto)
-> (StakeCredential, Hash StakePoolKey)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Credential 'Staking StandardCrypto -> StakeCredential
fromShelleyStakeCredential KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey
StakePoolKeyHash)
  ([(Credential 'Staking StandardCrypto,
   KeyHash 'StakePool StandardCrypto)]
 -> [(StakeCredential, Hash StakePoolKey)])
-> (Map
      (Credential 'Staking StandardCrypto)
      (KeyHash 'StakePool StandardCrypto)
    -> [(Credential 'Staking StandardCrypto,
         KeyHash 'StakePool StandardCrypto)])
-> Map
     (Credential 'Staking StandardCrypto)
     (KeyHash 'StakePool StandardCrypto)
-> [(StakeCredential, Hash StakePoolKey)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map
  (Credential 'Staking StandardCrypto)
  (KeyHash 'StakePool StandardCrypto)
-> [(Credential 'Staking StandardCrypto,
     KeyHash 'StakePool StandardCrypto)]
forall k a. Map k a -> [(k, a)]
Map.toList

fromShelleyRewardAccounts :: Shelley.RewardAccounts Consensus.StandardCrypto
                          -> Map StakeCredential Lovelace
fromShelleyRewardAccounts :: RewardAccounts StandardCrypto -> Map StakeCredential Lovelace
fromShelleyRewardAccounts =
    --TODO: write an appropriate property to show it is safe to use
    -- Map.fromListAsc or to use Map.mapKeysMonotonic
    [(StakeCredential, Lovelace)] -> Map StakeCredential Lovelace
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
  ([(StakeCredential, Lovelace)] -> Map StakeCredential Lovelace)
-> (RewardAccounts StandardCrypto -> [(StakeCredential, Lovelace)])
-> RewardAccounts StandardCrypto
-> Map StakeCredential Lovelace
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Credential 'Staking StandardCrypto, Coin)
 -> (StakeCredential, Lovelace))
-> [(Credential 'Staking StandardCrypto, Coin)]
-> [(StakeCredential, Lovelace)]
forall a b. (a -> b) -> [a] -> [b]
map ((Credential 'Staking StandardCrypto -> StakeCredential)
-> (Coin -> Lovelace)
-> (Credential 'Staking StandardCrypto, Coin)
-> (StakeCredential, Lovelace)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Credential 'Staking StandardCrypto -> StakeCredential
fromShelleyStakeCredential Coin -> Lovelace
fromShelleyLovelace)
  ([(Credential 'Staking StandardCrypto, Coin)]
 -> [(StakeCredential, Lovelace)])
-> (RewardAccounts StandardCrypto
    -> [(Credential 'Staking StandardCrypto, Coin)])
-> RewardAccounts StandardCrypto
-> [(StakeCredential, Lovelace)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAccounts StandardCrypto
-> [(Credential 'Staking StandardCrypto, Coin)]
forall k a. Map k a -> [(k, a)]
Map.toList


-- ----------------------------------------------------------------------------
-- Conversions of queries into the consensus types.
--

toConsensusQuery :: forall mode block result.
                    ConsensusBlockForMode mode ~ block
                 => QueryInMode mode result
                 -> Some (Consensus.Query block)
toConsensusQuery :: QueryInMode mode result -> Some (Query block)
toConsensusQuery (QueryCurrentEra ConsensusModeIsMultiEra mode
CardanoModeIsMultiEra) =
    Query
  (HardForkBlock
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  (EraIndex
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
-> Some
     (Query
        (HardForkBlock
           '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
             ShelleyBlock (AllegraEra StandardCrypto),
             ShelleyBlock (MaryEra StandardCrypto),
             ShelleyBlock (AlonzoEra StandardCrypto)]))
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (Query
   (HardForkBlock
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
   (EraIndex
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
 -> Some
      (Query
         (HardForkBlock
            '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
              ShelleyBlock (AllegraEra StandardCrypto),
              ShelleyBlock (MaryEra StandardCrypto),
              ShelleyBlock (AlonzoEra StandardCrypto)])))
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (EraIndex
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
-> Some
     (Query
        (HardForkBlock
           '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
             ShelleyBlock (AllegraEra StandardCrypto),
             ShelleyBlock (MaryEra StandardCrypto),
             ShelleyBlock (AlonzoEra StandardCrypto)]))
forall a b. (a -> b) -> a -> b
$ BlockQuery
  (HardForkBlock
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  (EraIndex
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (EraIndex
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall blk result. BlockQuery blk result -> Query blk result
Consensus.BlockQuery (BlockQuery
   (HardForkBlock
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
   (EraIndex
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
 -> Query
      (HardForkBlock
         '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
           ShelleyBlock (AllegraEra StandardCrypto),
           ShelleyBlock (MaryEra StandardCrypto),
           ShelleyBlock (AlonzoEra StandardCrypto)])
      (EraIndex
         '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
           ShelleyBlock (AllegraEra StandardCrypto),
           ShelleyBlock (MaryEra StandardCrypto),
           ShelleyBlock (AlonzoEra StandardCrypto)]))
-> BlockQuery
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (EraIndex
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (EraIndex
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall a b. (a -> b) -> a -> b
$
      QueryHardFork
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
  (EraIndex
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
-> BlockQuery
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (EraIndex
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs1 :: [*]) x a.
IsNonEmpty xs1 =>
QueryHardFork (x : xs1) a -> BlockQuery (HardForkBlock (x : xs1)) a
Consensus.QueryHardFork
        QueryHardFork
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
  (EraIndex
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). QueryHardFork xs (EraIndex xs)
Consensus.GetCurrentEra

toConsensusQuery (QueryInEra EraInMode era mode
ByronEraInByronMode QueryInEra era result
QueryByronUpdateState) =
    Query
  (HardForkBlock '[ByronBlock])
  (HardForkQueryResult '[ByronBlock] State)
-> Some (Query (HardForkBlock '[ByronBlock]))
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (Query
   (HardForkBlock '[ByronBlock])
   (HardForkQueryResult '[ByronBlock] State)
 -> Some (Query (HardForkBlock '[ByronBlock])))
-> Query
     (HardForkBlock '[ByronBlock])
     (HardForkQueryResult '[ByronBlock] State)
-> Some (Query (HardForkBlock '[ByronBlock]))
forall a b. (a -> b) -> a -> b
$ BlockQuery
  (HardForkBlock '[ByronBlock])
  (HardForkQueryResult '[ByronBlock] State)
-> Query
     (HardForkBlock '[ByronBlock])
     (HardForkQueryResult '[ByronBlock] State)
forall blk result. BlockQuery blk result -> Query blk result
Consensus.BlockQuery (BlockQuery
   (HardForkBlock '[ByronBlock])
   (HardForkQueryResult '[ByronBlock] State)
 -> Query
      (HardForkBlock '[ByronBlock])
      (HardForkQueryResult '[ByronBlock] State))
-> BlockQuery
     (HardForkBlock '[ByronBlock])
     (HardForkQueryResult '[ByronBlock] State)
-> Query
     (HardForkBlock '[ByronBlock])
     (HardForkQueryResult '[ByronBlock] State)
forall a b. (a -> b) -> a -> b
$
      BlockQuery ByronBlock State
-> BlockQuery
     (HardForkBlock '[ByronBlock])
     (HardForkQueryResult '[ByronBlock] State)
forall b a result.
(HardForkQueryResult '[b] result ~ a) =>
BlockQuery b result -> BlockQuery (HardForkBlock '[b]) a
Consensus.DegenQuery
        BlockQuery ByronBlock State
Consensus.GetUpdateInterfaceState

toConsensusQuery (QueryEraHistory ConsensusModeIsMultiEra mode
CardanoModeIsMultiEra) =
    Query
  (HardForkBlock
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  (Interpreter
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
-> Some
     (Query
        (HardForkBlock
           '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
             ShelleyBlock (AllegraEra StandardCrypto),
             ShelleyBlock (MaryEra StandardCrypto),
             ShelleyBlock (AlonzoEra StandardCrypto)]))
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (Query
   (HardForkBlock
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
   (Interpreter
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
 -> Some
      (Query
         (HardForkBlock
            '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
              ShelleyBlock (AllegraEra StandardCrypto),
              ShelleyBlock (MaryEra StandardCrypto),
              ShelleyBlock (AlonzoEra StandardCrypto)])))
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (Interpreter
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
-> Some
     (Query
        (HardForkBlock
           '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
             ShelleyBlock (AllegraEra StandardCrypto),
             ShelleyBlock (MaryEra StandardCrypto),
             ShelleyBlock (AlonzoEra StandardCrypto)]))
forall a b. (a -> b) -> a -> b
$ BlockQuery
  (HardForkBlock
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  (Interpreter
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (Interpreter
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall blk result. BlockQuery blk result -> Query blk result
Consensus.BlockQuery (BlockQuery
   (HardForkBlock
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
   (Interpreter
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
 -> Query
      (HardForkBlock
         '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
           ShelleyBlock (AllegraEra StandardCrypto),
           ShelleyBlock (MaryEra StandardCrypto),
           ShelleyBlock (AlonzoEra StandardCrypto)])
      (Interpreter
         '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
           ShelleyBlock (AllegraEra StandardCrypto),
           ShelleyBlock (MaryEra StandardCrypto),
           ShelleyBlock (AlonzoEra StandardCrypto)]))
-> BlockQuery
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (Interpreter
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (Interpreter
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall a b. (a -> b) -> a -> b
$
      QueryHardFork
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
  (Interpreter
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
-> BlockQuery
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (Interpreter
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs1 :: [*]) x a.
IsNonEmpty xs1 =>
QueryHardFork (x : xs1) a -> BlockQuery (HardForkBlock (x : xs1)) a
Consensus.QueryHardFork
        QueryHardFork
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
  (Interpreter
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
forall (xs :: [*]). QueryHardFork xs (Interpreter xs)
Consensus.GetInterpreter

toConsensusQuery QueryInMode mode result
QuerySystemStart = Query block SystemStart -> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some Query block SystemStart
forall blk. Query blk SystemStart
Consensus.GetSystemStart

toConsensusQuery (QueryInEra EraInMode era mode
ByronEraInCardanoMode QueryInEra era result
QueryByronUpdateState) =
    Query
  (HardForkBlock
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  (CardanoQueryResult StandardCrypto State)
-> Some
     (Query
        (HardForkBlock
           '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
             ShelleyBlock (AllegraEra StandardCrypto),
             ShelleyBlock (MaryEra StandardCrypto),
             ShelleyBlock (AlonzoEra StandardCrypto)]))
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (Query
   (HardForkBlock
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
   (CardanoQueryResult StandardCrypto State)
 -> Some
      (Query
         (HardForkBlock
            '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
              ShelleyBlock (AllegraEra StandardCrypto),
              ShelleyBlock (MaryEra StandardCrypto),
              ShelleyBlock (AlonzoEra StandardCrypto)])))
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (CardanoQueryResult StandardCrypto State)
-> Some
     (Query
        (HardForkBlock
           '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
             ShelleyBlock (AllegraEra StandardCrypto),
             ShelleyBlock (MaryEra StandardCrypto),
             ShelleyBlock (AlonzoEra StandardCrypto)]))
forall a b. (a -> b) -> a -> b
$ BlockQuery
  (HardForkBlock
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  (CardanoQueryResult StandardCrypto State)
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (CardanoQueryResult StandardCrypto State)
forall blk result. BlockQuery blk result -> Query blk result
Consensus.BlockQuery (BlockQuery
   (HardForkBlock
      '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
        ShelleyBlock (AllegraEra StandardCrypto),
        ShelleyBlock (MaryEra StandardCrypto),
        ShelleyBlock (AlonzoEra StandardCrypto)])
   (CardanoQueryResult StandardCrypto State)
 -> Query
      (HardForkBlock
         '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
           ShelleyBlock (AllegraEra StandardCrypto),
           ShelleyBlock (MaryEra StandardCrypto),
           ShelleyBlock (AlonzoEra StandardCrypto)])
      (CardanoQueryResult StandardCrypto State))
-> BlockQuery
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (CardanoQueryResult StandardCrypto State)
-> Query
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (CardanoQueryResult StandardCrypto State)
forall a b. (a -> b) -> a -> b
$
      BlockQuery ByronBlock State
-> BlockQuery
     (HardForkBlock
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     (CardanoQueryResult StandardCrypto State)
forall c a result.
(CardanoQueryResult c result ~ a) =>
BlockQuery ByronBlock result -> CardanoQuery c a
Consensus.QueryIfCurrentByron
        BlockQuery ByronBlock State
Consensus.GetUpdateInterfaceState

toConsensusQuery (QueryInEra EraInMode era mode
erainmode (QueryInShelleyBasedEra ShelleyBasedEra era
era QueryInShelleyBasedEra era result
q)) =
    case EraInMode era mode
erainmode of
      EraInMode era mode
ByronEraInByronMode     -> case ShelleyBasedEra era
era of {}
      EraInMode era mode
ShelleyEraInShelleyMode -> EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
forall era ledgerera mode block (xs :: [*]) result.
(ConsensusBlockForEra era ~ ShelleyBlock ledgerera,
 Crypto ledgerera ~ StandardCrypto,
 ConsensusBlockForMode mode ~ block, block ~ HardForkBlock xs) =>
EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
q
      EraInMode era mode
ByronEraInCardanoMode   -> case ShelleyBasedEra era
era of {}
      EraInMode era mode
ShelleyEraInCardanoMode -> EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
forall era ledgerera mode block (xs :: [*]) result.
(ConsensusBlockForEra era ~ ShelleyBlock ledgerera,
 Crypto ledgerera ~ StandardCrypto,
 ConsensusBlockForMode mode ~ block, block ~ HardForkBlock xs) =>
EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
q
      EraInMode era mode
AllegraEraInCardanoMode -> EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
forall era ledgerera mode block (xs :: [*]) result.
(ConsensusBlockForEra era ~ ShelleyBlock ledgerera,
 Crypto ledgerera ~ StandardCrypto,
 ConsensusBlockForMode mode ~ block, block ~ HardForkBlock xs) =>
EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
q
      EraInMode era mode
MaryEraInCardanoMode    -> EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
forall era ledgerera mode block (xs :: [*]) result.
(ConsensusBlockForEra era ~ ShelleyBlock ledgerera,
 Crypto ledgerera ~ StandardCrypto,
 ConsensusBlockForMode mode ~ block, block ~ HardForkBlock xs) =>
EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
q
      EraInMode era mode
AlonzoEraInCardanoMode  -> EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
forall era ledgerera mode block (xs :: [*]) result.
(ConsensusBlockForEra era ~ ShelleyBlock ledgerera,
 Crypto ledgerera ~ StandardCrypto,
 ConsensusBlockForMode mode ~ block, block ~ HardForkBlock xs) =>
EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
q


toConsensusQueryShelleyBased
  :: forall era ledgerera mode block xs result.
     ConsensusBlockForEra era ~ Consensus.ShelleyBlock ledgerera
  => Ledger.Crypto ledgerera ~ Consensus.StandardCrypto
  => ConsensusBlockForMode mode ~ block
  => block ~ Consensus.HardForkBlock xs
  => EraInMode era mode
  -> QueryInShelleyBasedEra era result
  -> Some (Consensus.Query block)
toConsensusQueryShelleyBased :: EraInMode era mode
-> QueryInShelleyBasedEra era result -> Some (Query block)
toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryChainPoint =
    Query
  block (HardForkQueryResult xs (Point (ShelleyBlock ledgerera)))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery
     (ShelleyBlock ledgerera) (Point (ShelleyBlock ledgerera))
-> Query
     block (HardForkQueryResult xs (Point (ShelleyBlock ledgerera)))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery
  (ShelleyBlock ledgerera) (Point (ShelleyBlock ledgerera))
forall era.
BlockQuery (ShelleyBlock era) (Point (ShelleyBlock era))
Consensus.GetLedgerTip)

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryEpoch =
    Query block (HardForkQueryResult xs EpochNo) -> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery (ShelleyBlock ledgerera) EpochNo
-> Query block (HardForkQueryResult xs EpochNo)
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery (ShelleyBlock ledgerera) EpochNo
forall era. BlockQuery (ShelleyBlock era) EpochNo
Consensus.GetEpochNo)

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryGenesisParameters =
    Query block (HardForkQueryResult xs (CompactGenesis ledgerera))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery (ShelleyBlock ledgerera) (CompactGenesis ledgerera)
-> Query block (HardForkQueryResult xs (CompactGenesis ledgerera))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery (ShelleyBlock ledgerera) (CompactGenesis ledgerera)
forall era. BlockQuery (ShelleyBlock era) (CompactGenesis era)
Consensus.GetGenesisConfig)

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryProtocolParameters =
    Query block (HardForkQueryResult xs (PParams ledgerera))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery (ShelleyBlock ledgerera) (PParams ledgerera)
-> Query block (HardForkQueryResult xs (PParams ledgerera))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery (ShelleyBlock ledgerera) (PParams ledgerera)
forall era. BlockQuery (ShelleyBlock era) (PParams era)
Consensus.GetCurrentPParams)

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryProtocolParametersUpdate =
    Query block (HardForkQueryResult xs (ProposedPPUpdates ledgerera))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery
     (ShelleyBlock ledgerera) (ProposedPPUpdates ledgerera)
-> Query
     block (HardForkQueryResult xs (ProposedPPUpdates ledgerera))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery (ShelleyBlock ledgerera) (ProposedPPUpdates ledgerera)
forall era. BlockQuery (ShelleyBlock era) (ProposedPPUpdates era)
Consensus.GetProposedPParamsUpdates)

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryStakeDistribution =
    Query block (HardForkQueryResult xs (PoolDistr StandardCrypto))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery (ShelleyBlock ledgerera) (PoolDistr StandardCrypto)
-> Query block (HardForkQueryResult xs (PoolDistr StandardCrypto))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery (ShelleyBlock ledgerera) (PoolDistr StandardCrypto)
forall era.
BlockQuery (ShelleyBlock era) (PoolDistr (EraCrypto era))
Consensus.GetStakeDistribution)

toConsensusQueryShelleyBased EraInMode era mode
erainmode (QueryUTxO QueryUTxOFilter
QueryUTxOWhole) =
    Query block (HardForkQueryResult xs (UTxO ledgerera))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery (ShelleyBlock ledgerera) (UTxO ledgerera)
-> Query block (HardForkQueryResult xs (UTxO ledgerera))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery (ShelleyBlock ledgerera) (UTxO ledgerera)
forall era. BlockQuery (ShelleyBlock era) (UTxO era)
Consensus.GetUTxOWhole)

toConsensusQueryShelleyBased EraInMode era mode
erainmode (QueryUTxO (QueryUTxOByAddress Set AddressAny
addrs)) =
    Query block (HardForkQueryResult xs (UTxO ledgerera))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery (ShelleyBlock ledgerera) (UTxO ledgerera)
-> Query block (HardForkQueryResult xs (UTxO ledgerera))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode (Set (Addr (EraCrypto ledgerera))
-> BlockQuery (ShelleyBlock ledgerera) (UTxO ledgerera)
forall era.
Set (Addr (EraCrypto era))
-> BlockQuery (ShelleyBlock era) (UTxO era)
Consensus.GetUTxOByAddress Set (Addr StandardCrypto)
Set (Addr (EraCrypto ledgerera))
addrs'))
  where
    addrs' :: Set (Shelley.Addr Consensus.StandardCrypto)
    addrs' :: Set (Addr StandardCrypto)
addrs' = CardanoEra era -> Set AddressAny -> Set (Addr StandardCrypto)
forall era.
CardanoEra era -> Set AddressAny -> Set (Addr StandardCrypto)
toShelleyAddrSet (EraInMode era mode -> CardanoEra era
forall era mode. EraInMode era mode -> CardanoEra era
eraInModeToEra EraInMode era mode
erainmode) Set AddressAny
addrs

toConsensusQueryShelleyBased EraInMode era mode
erainmode (QueryUTxO (QueryUTxOByTxIn Set TxIn
txins)) =
    Query block (HardForkQueryResult xs (UTxO ledgerera))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery (ShelleyBlock ledgerera) (UTxO ledgerera)
-> Query block (HardForkQueryResult xs (UTxO ledgerera))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode (Set (TxIn (EraCrypto ledgerera))
-> BlockQuery (ShelleyBlock ledgerera) (UTxO ledgerera)
forall era.
Set (TxIn (EraCrypto era))
-> BlockQuery (ShelleyBlock era) (UTxO era)
Consensus.GetUTxOByTxIn Set (TxIn StandardCrypto)
Set (TxIn (EraCrypto ledgerera))
txins'))
  where
    txins' :: Set (Shelley.TxIn Consensus.StandardCrypto)
    txins' :: Set (TxIn StandardCrypto)
txins' = (TxIn -> TxIn StandardCrypto)
-> Set TxIn -> Set (TxIn StandardCrypto)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map TxIn -> TxIn StandardCrypto
toShelleyTxIn Set TxIn
txins

toConsensusQueryShelleyBased EraInMode era mode
erainmode (QueryStakeAddresses Set StakeCredential
creds NetworkId
_nId) =
    Query
  block
  (HardForkQueryResult
     xs
     (Map
        (Credential 'Staking StandardCrypto)
        (KeyHash 'StakePool StandardCrypto),
      RewardAccounts StandardCrypto))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery
     (ShelleyBlock ledgerera)
     (Map
        (Credential 'Staking StandardCrypto)
        (KeyHash 'StakePool StandardCrypto),
      RewardAccounts StandardCrypto)
-> Query
     block
     (HardForkQueryResult
        xs
        (Map
           (Credential 'Staking StandardCrypto)
           (KeyHash 'StakePool StandardCrypto),
         RewardAccounts StandardCrypto))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode
            (Set (Credential 'Staking (EraCrypto ledgerera))
-> BlockQuery
     (ShelleyBlock ledgerera)
     (Delegations (EraCrypto ledgerera),
      RewardAccounts (EraCrypto ledgerera))
forall era.
Set (Credential 'Staking (EraCrypto era))
-> BlockQuery
     (ShelleyBlock era)
     (Delegations (EraCrypto era), RewardAccounts (EraCrypto era))
Consensus.GetFilteredDelegationsAndRewardAccounts Set (Credential 'Staking StandardCrypto)
Set (Credential 'Staking (EraCrypto ledgerera))
creds'))
  where
    creds' :: Set (Shelley.Credential Shelley.Staking StandardCrypto)
    creds' :: Set (Credential 'Staking StandardCrypto)
creds' = (StakeCredential -> Credential 'Staking StandardCrypto)
-> Set StakeCredential -> Set (Credential 'Staking StandardCrypto)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map StakeCredential -> Credential 'Staking StandardCrypto
toShelleyStakeCredential Set StakeCredential
creds

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryStakePools =
    Query
  block
  (HardForkQueryResult xs (Set (KeyHash 'StakePool StandardCrypto)))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery
     (ShelleyBlock ledgerera) (Set (KeyHash 'StakePool StandardCrypto))
-> Query
     block
     (HardForkQueryResult xs (Set (KeyHash 'StakePool StandardCrypto)))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode BlockQuery
  (ShelleyBlock ledgerera) (Set (KeyHash 'StakePool StandardCrypto))
forall era.
BlockQuery
  (ShelleyBlock era) (Set (KeyHash 'StakePool (EraCrypto era)))
Consensus.GetStakePools)

toConsensusQueryShelleyBased EraInMode era mode
erainmode (QueryStakePoolParameters Set (Hash StakePoolKey)
poolids) =
    Query
  block
  (HardForkQueryResult
     xs
     (Map
        (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery
     (ShelleyBlock ledgerera)
     (Map
        (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto))
-> Query
     block
     (HardForkQueryResult
        xs
        (Map
           (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode (Set (KeyHash 'StakePool (EraCrypto ledgerera))
-> BlockQuery
     (ShelleyBlock ledgerera)
     (Map
        (KeyHash 'StakePool (EraCrypto ledgerera))
        (PoolParams (EraCrypto ledgerera)))
forall era.
Set (KeyHash 'StakePool (EraCrypto era))
-> BlockQuery
     (ShelleyBlock era)
     (Map
        (KeyHash 'StakePool (EraCrypto era)) (PoolParams (EraCrypto era)))
Consensus.GetStakePoolParams Set (KeyHash 'StakePool StandardCrypto)
Set (KeyHash 'StakePool (EraCrypto ledgerera))
poolids'))
  where
    poolids' :: Set (Shelley.KeyHash Shelley.StakePool Consensus.StandardCrypto)
    poolids' :: Set (KeyHash 'StakePool StandardCrypto)
poolids' = (Hash StakePoolKey -> KeyHash 'StakePool StandardCrypto)
-> Set (Hash StakePoolKey)
-> Set (KeyHash 'StakePool StandardCrypto)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map (\(StakePoolKeyHash kh) -> KeyHash 'StakePool StandardCrypto
kh) Set (Hash StakePoolKey)
poolids

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryDebugLedgerState =
    Query
  block
  (HardForkQueryResult xs (Serialised (NewEpochState ledgerera)))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery
     (ShelleyBlock ledgerera) (Serialised (NewEpochState ledgerera))
-> Query
     block
     (HardForkQueryResult xs (Serialised (NewEpochState ledgerera)))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode (BlockQuery (ShelleyBlock ledgerera) (NewEpochState ledgerera)
-> BlockQuery
     (ShelleyBlock ledgerera) (Serialised (NewEpochState ledgerera))
forall era result.
BlockQuery (ShelleyBlock era) result
-> BlockQuery (ShelleyBlock era) (Serialised result)
Consensus.GetCBOR BlockQuery (ShelleyBlock ledgerera) (NewEpochState ledgerera)
forall era. BlockQuery (ShelleyBlock era) (NewEpochState era)
Consensus.DebugNewEpochState))

toConsensusQueryShelleyBased EraInMode era mode
erainmode QueryInShelleyBasedEra era result
QueryProtocolState =
    Query
  block
  (HardForkQueryResult
     xs (Serialised (ChainDepState StandardCrypto)))
-> Some (Query block)
forall k (f :: k -> *) (a :: k). f a -> Some f
Some (EraInMode era mode
-> BlockQuery
     (ShelleyBlock ledgerera)
     (Serialised (ChainDepState StandardCrypto))
-> Query
     block
     (HardForkQueryResult
        xs (Serialised (ChainDepState StandardCrypto)))
forall era mode erablock modeblock result result' (xs :: [*]).
(ConsensusBlockForEra era ~ erablock,
 ConsensusBlockForMode mode ~ modeblock,
 modeblock ~ HardForkBlock xs,
 HardForkQueryResult xs result ~ result') =>
EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode (BlockQuery (ShelleyBlock ledgerera) (ChainDepState StandardCrypto)
-> BlockQuery
     (ShelleyBlock ledgerera)
     (Serialised (ChainDepState StandardCrypto))
forall era result.
BlockQuery (ShelleyBlock era) result
-> BlockQuery (ShelleyBlock era) (Serialised result)
Consensus.GetCBOR BlockQuery (ShelleyBlock ledgerera) (ChainDepState StandardCrypto)
forall era.
BlockQuery (ShelleyBlock era) (ChainDepState (EraCrypto era))
Consensus.DebugChainDepState))

consensusQueryInEraInMode
  :: forall era mode erablock modeblock result result' xs.
     ConsensusBlockForEra era   ~ erablock
  => ConsensusBlockForMode mode ~ modeblock
  => modeblock ~ Consensus.HardForkBlock xs
  => Consensus.HardForkQueryResult xs result ~ result'
  => EraInMode era mode
  -> Consensus.BlockQuery erablock  result
  -> Consensus.Query modeblock result'
consensusQueryInEraInMode :: EraInMode era mode
-> BlockQuery erablock result -> Query modeblock result'
consensusQueryInEraInMode EraInMode era mode
erainmode =
    BlockQuery modeblock result' -> Query modeblock result'
forall blk result. BlockQuery blk result -> Query blk result
Consensus.BlockQuery
  (BlockQuery modeblock result' -> Query modeblock result')
-> (BlockQuery erablock result -> BlockQuery modeblock result')
-> BlockQuery erablock result
-> Query modeblock result'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. case EraInMode era mode
erainmode of
      EraInMode era mode
ByronEraInByronMode     -> BlockQuery erablock result -> BlockQuery modeblock result'
forall b a result.
(HardForkQueryResult '[b] result ~ a) =>
BlockQuery b result -> BlockQuery (HardForkBlock '[b]) a
Consensus.DegenQuery
      EraInMode era mode
ShelleyEraInShelleyMode -> BlockQuery erablock result -> BlockQuery modeblock result'
forall b a result.
(HardForkQueryResult '[b] result ~ a) =>
BlockQuery b result -> BlockQuery (HardForkBlock '[b]) a
Consensus.DegenQuery
      EraInMode era mode
ByronEraInCardanoMode   -> BlockQuery erablock result -> BlockQuery modeblock result'
forall c a result.
(CardanoQueryResult c result ~ a) =>
BlockQuery ByronBlock result -> CardanoQuery c a
Consensus.QueryIfCurrentByron
      EraInMode era mode
ShelleyEraInCardanoMode -> BlockQuery erablock result -> BlockQuery modeblock result'
forall c a result.
(CardanoQueryResult c result ~ a) =>
BlockQuery (ShelleyBlock (ShelleyEra c)) result -> CardanoQuery c a
Consensus.QueryIfCurrentShelley
      EraInMode era mode
AllegraEraInCardanoMode -> BlockQuery erablock result -> BlockQuery modeblock result'
forall c a result.
(CardanoQueryResult c result ~ a) =>
BlockQuery (ShelleyBlock (AllegraEra c)) result -> CardanoQuery c a
Consensus.QueryIfCurrentAllegra
      EraInMode era mode
MaryEraInCardanoMode    -> BlockQuery erablock result -> BlockQuery modeblock result'
forall c a result.
(CardanoQueryResult c result ~ a) =>
BlockQuery (ShelleyBlock (MaryEra c)) result -> CardanoQuery c a
Consensus.QueryIfCurrentMary
      EraInMode era mode
AlonzoEraInCardanoMode  -> BlockQuery erablock result -> BlockQuery modeblock result'
forall c a result.
(CardanoQueryResult c result ~ a) =>
BlockQuery (ShelleyBlock (AlonzoEra c)) result -> CardanoQuery c a
Consensus.QueryIfCurrentAlonzo

-- ----------------------------------------------------------------------------
-- Conversions of query results from the consensus types.
--

fromConsensusQueryResult :: forall mode block result result'.
                            ConsensusBlockForMode mode ~ block
                         => QueryInMode mode result
                         -> Consensus.Query block result'
                         -> result'
                         -> result
fromConsensusQueryResult :: QueryInMode mode result -> Query block result' -> result' -> result
fromConsensusQueryResult (QueryEraHistory ConsensusModeIsMultiEra mode
CardanoModeIsMultiEra) Query block result'
q' result'
r' =
    case Query block result'
q' of
      Consensus.BlockQuery (Consensus.QueryHardFork Consensus.GetInterpreter)
        -> ConsensusMode CardanoMode
-> Interpreter
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
-> EraHistory CardanoMode
forall mode (xs :: [*]).
(ConsensusBlockForMode mode ~ HardForkBlock xs) =>
ConsensusMode mode -> Interpreter xs -> EraHistory mode
EraHistory ConsensusMode CardanoMode
CardanoMode result'
Interpreter
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
r'
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult QueryInMode mode result
QuerySystemStart Query block result'
q' result'
r' =
    case Query block result'
q' of
      Query block result'
Consensus.GetSystemStart
        -> result
result'
r'
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryCurrentEra ConsensusModeIsMultiEra mode
CardanoModeIsMultiEra) Query block result'
q' result'
r' =
    case Query block result'
q' of
      Consensus.BlockQuery (Consensus.QueryHardFork Consensus.GetCurrentEra)
        -> AnyEraInMode CardanoMode -> AnyCardanoEra
forall mode. AnyEraInMode mode -> AnyCardanoEra
anyEraInModeToAnyEra (ConsensusMode CardanoMode
-> EraIndex
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)]
-> AnyEraInMode CardanoMode
forall mode (xs :: [*]).
(ConsensusBlockForMode mode ~ HardForkBlock xs) =>
ConsensusMode mode -> EraIndex xs -> AnyEraInMode mode
fromConsensusEraIndex ConsensusMode CardanoMode
CardanoMode result'
EraIndex
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
r')
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra EraInMode era mode
ByronEraInByronMode
                                     QueryInEra era result
QueryByronUpdateState) Query block result'
q' result'
r' =
    case (Query block result'
q', result'
r') of
      (Consensus.BlockQuery (Consensus.DegenQuery Consensus.GetUpdateInterfaceState),
       Consensus.DegenQueryResult r'')
        -> ByronUpdateState -> Either EraMismatch ByronUpdateState
forall a b. b -> Either a b
Right (State -> ByronUpdateState
ByronUpdateState State
r'')
      (Query block result', result')
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra EraInMode era mode
ByronEraInCardanoMode
                                     QueryInEra era result
QueryByronUpdateState) Query block result'
q' result'
r' =
    case Query block result'
q' of
      Consensus.BlockQuery
        (Consensus.QueryIfCurrentByron Consensus.GetUpdateInterfaceState)
        -> (MismatchEraInfo
   '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
     ShelleyBlock (AllegraEra StandardCrypto),
     ShelleyBlock (MaryEra StandardCrypto),
     ShelleyBlock (AlonzoEra StandardCrypto)]
 -> EraMismatch)
-> (State -> ByronUpdateState)
-> CardanoQueryResult StandardCrypto State
-> Either EraMismatch ByronUpdateState
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap MismatchEraInfo
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> EraMismatch
forall (xs :: [*]). SListI xs => MismatchEraInfo xs -> EraMismatch
fromConsensusEraMismatch State -> ByronUpdateState
ByronUpdateState result'
CardanoQueryResult StandardCrypto State
r'
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra EraInMode era mode
ByronEraInByronMode
                                     (QueryInShelleyBasedEra ShelleyBasedEra era
era QueryInShelleyBasedEra era result
_)) Query block result'
_ result'
_ =
    case ShelleyBasedEra era
era of {}

fromConsensusQueryResult (QueryInEra EraInMode era mode
ShelleyEraInShelleyMode
                                     (QueryInShelleyBasedEra ShelleyBasedEra era
_era QueryInShelleyBasedEra era result
q)) Query block result'
q' result'
r' =
    case (Query block result'
q', result'
r') of
      (Consensus.BlockQuery (Consensus.DegenQuery q''),
       Consensus.DegenQueryResult r'')
        -> result -> Either EraMismatch result
forall a b. b -> Either a b
Right (ShelleyBasedEra ShelleyEra
-> QueryInShelleyBasedEra ShelleyEra result
-> BlockQuery (ShelleyBlock (ShelleyEra StandardCrypto)) result
-> result
-> result
forall era ledgerera result result'.
(ShelleyLedgerEra era ~ ledgerera, ShelleyBasedEra ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era
-> QueryInShelleyBasedEra era result
-> BlockQuery (ShelleyBlock ledgerera) result'
-> result'
-> result
fromConsensusQueryResultShelleyBased
                    ShelleyBasedEra ShelleyEra
ShelleyBasedEraShelley QueryInShelleyBasedEra era result
QueryInShelleyBasedEra ShelleyEra result
q BlockQuery (ShelleyBlock (ShelleyEra StandardCrypto)) result
q'' result
r'')
      (Query block result', result')
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra EraInMode era mode
ByronEraInCardanoMode
                                     (QueryInShelleyBasedEra ShelleyBasedEra era
era QueryInShelleyBasedEra era result
_)) Query block result'
_ result'
_ =
    case ShelleyBasedEra era
era of {}

fromConsensusQueryResult (QueryInEra EraInMode era mode
ShelleyEraInCardanoMode
                                     (QueryInShelleyBasedEra ShelleyBasedEra era
_era QueryInShelleyBasedEra era result
q)) Query block result'
q' result'
r' =
    case Query block result'
q' of
      Consensus.BlockQuery (Consensus.QueryIfCurrentShelley q'')
        -> (MismatchEraInfo
   '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
     ShelleyBlock (AllegraEra StandardCrypto),
     ShelleyBlock (MaryEra StandardCrypto),
     ShelleyBlock (AlonzoEra StandardCrypto)]
 -> EraMismatch)
-> (result -> result)
-> Either
     (MismatchEraInfo
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     result
-> Either EraMismatch result
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap MismatchEraInfo
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> EraMismatch
forall (xs :: [*]). SListI xs => MismatchEraInfo xs -> EraMismatch
fromConsensusEraMismatch
                 (ShelleyBasedEra ShelleyEra
-> QueryInShelleyBasedEra ShelleyEra result
-> BlockQuery (ShelleyBlock (ShelleyEra StandardCrypto)) result
-> result
-> result
forall era ledgerera result result'.
(ShelleyLedgerEra era ~ ledgerera, ShelleyBasedEra ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era
-> QueryInShelleyBasedEra era result
-> BlockQuery (ShelleyBlock ledgerera) result'
-> result'
-> result
fromConsensusQueryResultShelleyBased
                    ShelleyBasedEra ShelleyEra
ShelleyBasedEraShelley QueryInShelleyBasedEra era result
QueryInShelleyBasedEra ShelleyEra result
q BlockQuery (ShelleyBlock (ShelleyEra StandardCrypto)) result
q'')
                 result'
Either
  (MismatchEraInfo
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  result
r'
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra EraInMode era mode
AllegraEraInCardanoMode
                                     (QueryInShelleyBasedEra ShelleyBasedEra era
_era QueryInShelleyBasedEra era result
q)) Query block result'
q' result'
r' =
    case Query block result'
q' of
      Consensus.BlockQuery (Consensus.QueryIfCurrentAllegra q'')
        -> (MismatchEraInfo
   '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
     ShelleyBlock (AllegraEra StandardCrypto),
     ShelleyBlock (MaryEra StandardCrypto),
     ShelleyBlock (AlonzoEra StandardCrypto)]
 -> EraMismatch)
-> (result -> result)
-> Either
     (MismatchEraInfo
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     result
-> Either EraMismatch result
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap MismatchEraInfo
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> EraMismatch
forall (xs :: [*]). SListI xs => MismatchEraInfo xs -> EraMismatch
fromConsensusEraMismatch
                 (ShelleyBasedEra AllegraEra
-> QueryInShelleyBasedEra AllegraEra result
-> BlockQuery (ShelleyBlock (AllegraEra StandardCrypto)) result
-> result
-> result
forall era ledgerera result result'.
(ShelleyLedgerEra era ~ ledgerera, ShelleyBasedEra ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era
-> QueryInShelleyBasedEra era result
-> BlockQuery (ShelleyBlock ledgerera) result'
-> result'
-> result
fromConsensusQueryResultShelleyBased
                    ShelleyBasedEra AllegraEra
ShelleyBasedEraAllegra QueryInShelleyBasedEra era result
QueryInShelleyBasedEra AllegraEra result
q BlockQuery (ShelleyBlock (AllegraEra StandardCrypto)) result
q'')
                 result'
Either
  (MismatchEraInfo
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  result
r'
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra EraInMode era mode
MaryEraInCardanoMode
                                     (QueryInShelleyBasedEra ShelleyBasedEra era
_era QueryInShelleyBasedEra era result
q)) Query block result'
q' result'
r' =
    case Query block result'
q' of
      Consensus.BlockQuery (Consensus.QueryIfCurrentMary q'')
        -> (MismatchEraInfo
   '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
     ShelleyBlock (AllegraEra StandardCrypto),
     ShelleyBlock (MaryEra StandardCrypto),
     ShelleyBlock (AlonzoEra StandardCrypto)]
 -> EraMismatch)
-> (result -> result)
-> Either
     (MismatchEraInfo
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     result
-> Either EraMismatch result
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap MismatchEraInfo
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> EraMismatch
forall (xs :: [*]). SListI xs => MismatchEraInfo xs -> EraMismatch
fromConsensusEraMismatch
                 (ShelleyBasedEra MaryEra
-> QueryInShelleyBasedEra MaryEra result
-> BlockQuery (ShelleyBlock (MaryEra StandardCrypto)) result
-> result
-> result
forall era ledgerera result result'.
(ShelleyLedgerEra era ~ ledgerera, ShelleyBasedEra ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era
-> QueryInShelleyBasedEra era result
-> BlockQuery (ShelleyBlock ledgerera) result'
-> result'
-> result
fromConsensusQueryResultShelleyBased
                    ShelleyBasedEra MaryEra
ShelleyBasedEraMary QueryInShelleyBasedEra era result
QueryInShelleyBasedEra MaryEra result
q BlockQuery (ShelleyBlock (MaryEra StandardCrypto)) result
q'')
                 result'
Either
  (MismatchEraInfo
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  result
r'
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResult (QueryInEra EraInMode era mode
AlonzoEraInCardanoMode
                                     (QueryInShelleyBasedEra ShelleyBasedEra era
_era QueryInShelleyBasedEra era result
q)) Query block result'
q' result'
r' =
    case Query block result'
q' of
      Consensus.BlockQuery (Consensus.QueryIfCurrentAlonzo q'')
        -> (MismatchEraInfo
   '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
     ShelleyBlock (AllegraEra StandardCrypto),
     ShelleyBlock (MaryEra StandardCrypto),
     ShelleyBlock (AlonzoEra StandardCrypto)]
 -> EraMismatch)
-> (result -> result)
-> Either
     (MismatchEraInfo
        '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
          ShelleyBlock (AllegraEra StandardCrypto),
          ShelleyBlock (MaryEra StandardCrypto),
          ShelleyBlock (AlonzoEra StandardCrypto)])
     result
-> Either EraMismatch result
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap MismatchEraInfo
  '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
    ShelleyBlock (AllegraEra StandardCrypto),
    ShelleyBlock (MaryEra StandardCrypto),
    ShelleyBlock (AlonzoEra StandardCrypto)]
-> EraMismatch
forall (xs :: [*]). SListI xs => MismatchEraInfo xs -> EraMismatch
fromConsensusEraMismatch
                 (ShelleyBasedEra AlonzoEra
-> QueryInShelleyBasedEra AlonzoEra result
-> BlockQuery (ShelleyBlock (AlonzoEra StandardCrypto)) result
-> result
-> result
forall era ledgerera result result'.
(ShelleyLedgerEra era ~ ledgerera, ShelleyBasedEra ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era
-> QueryInShelleyBasedEra era result
-> BlockQuery (ShelleyBlock ledgerera) result'
-> result'
-> result
fromConsensusQueryResultShelleyBased
                    ShelleyBasedEra AlonzoEra
ShelleyBasedEraAlonzo QueryInShelleyBasedEra era result
QueryInShelleyBasedEra AlonzoEra result
q BlockQuery (ShelleyBlock (AlonzoEra StandardCrypto)) result
q'')
                 result'
Either
  (MismatchEraInfo
     '[ByronBlock, ShelleyBlock (ShelleyEra StandardCrypto),
       ShelleyBlock (AllegraEra StandardCrypto),
       ShelleyBlock (MaryEra StandardCrypto),
       ShelleyBlock (AlonzoEra StandardCrypto)])
  result
r'
      Query block result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased
  :: forall era ledgerera result result'.
     ShelleyLedgerEra era ~ ledgerera
  => Consensus.ShelleyBasedEra ledgerera
  => Ledger.Crypto ledgerera ~ Consensus.StandardCrypto
  => ShelleyBasedEra era
  -> QueryInShelleyBasedEra era result
  -> Consensus.BlockQuery (Consensus.ShelleyBlock ledgerera) result'
  -> result'
  -> result
fromConsensusQueryResultShelleyBased :: ShelleyBasedEra era
-> QueryInShelleyBasedEra era result
-> BlockQuery (ShelleyBlock ledgerera) result'
-> result'
-> result
fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryInShelleyBasedEra era result
QueryChainPoint BlockQuery (ShelleyBlock ledgerera) result'
q' result'
point =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetLedgerTip -> Point (ShelleyBlock ledgerera) -> ChainPoint
forall ledgerera.
ShelleyBasedEra ledgerera =>
Point (ShelleyBlock ledgerera) -> ChainPoint
fromConsensusPoint result'
Point (ShelleyBlock ledgerera)
point
      BlockQuery (ShelleyBlock ledgerera) result'
_                      -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryInShelleyBasedEra era result
QueryEpoch BlockQuery (ShelleyBlock ledgerera) result'
q' result'
epoch =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetEpochNo -> result
result'
epoch
      BlockQuery (ShelleyBlock ledgerera) result'
_                    -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryInShelleyBasedEra era result
QueryGenesisParameters BlockQuery (ShelleyBlock ledgerera) result'
q' result'
r' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetGenesisConfig -> ShelleyGenesis ledgerera -> GenesisParameters
forall era. ShelleyGenesis era -> GenesisParameters
fromShelleyGenesis
                                      (CompactGenesis ledgerera -> ShelleyGenesis ledgerera
forall era. CompactGenesis era -> ShelleyGenesis era
Consensus.getCompactGenesis result'
CompactGenesis ledgerera
r')
      BlockQuery (ShelleyBlock ledgerera) result'
_                          -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
era QueryInShelleyBasedEra era result
QueryProtocolParameters BlockQuery (ShelleyBlock ledgerera) result'
q' result'
r' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetCurrentPParams -> ShelleyBasedEra era
-> PParams (ShelleyLedgerEra era) -> ProtocolParameters
forall era.
ShelleyBasedEra era
-> PParams (ShelleyLedgerEra era) -> ProtocolParameters
fromLedgerPParams ShelleyBasedEra era
era result'
PParams (ShelleyLedgerEra era)
r'
      BlockQuery (ShelleyBlock ledgerera) result'
_                           -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
era QueryInShelleyBasedEra era result
QueryProtocolParametersUpdate BlockQuery (ShelleyBlock ledgerera) result'
q' result'
r' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetProposedPParamsUpdates -> ShelleyBasedEra era
-> ProposedPPUpdates ledgerera
-> Map (Hash GenesisKey) ProtocolParametersUpdate
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era
-> ProposedPPUpdates ledgerera
-> Map (Hash GenesisKey) ProtocolParametersUpdate
fromLedgerProposedPPUpdates ShelleyBasedEra era
era result'
ProposedPPUpdates ledgerera
r'
      BlockQuery (ShelleyBlock ledgerera) result'
_                                   -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryInShelleyBasedEra era result
QueryStakeDistribution BlockQuery (ShelleyBlock ledgerera) result'
q' result'
r' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetStakeDistribution -> PoolDistr StandardCrypto -> Map (Hash StakePoolKey) Rational
fromShelleyPoolDistr result'
PoolDistr StandardCrypto
r'
      BlockQuery (ShelleyBlock ledgerera) result'
_                              -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
era (QueryUTxO QueryUTxOFilter
QueryUTxOWhole) BlockQuery (ShelleyBlock ledgerera) result'
q' result'
utxo' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetUTxOWhole -> ShelleyBasedEra era -> UTxO ledgerera -> UTxO era
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UTxO ledgerera -> UTxO era
fromLedgerUTxO ShelleyBasedEra era
era result'
UTxO ledgerera
utxo'
      BlockQuery (ShelleyBlock ledgerera) result'
_                      -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
era (QueryUTxO QueryUTxOByAddress{}) BlockQuery (ShelleyBlock ledgerera) result'
q' result'
utxo' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      Consensus.GetUTxOByAddress{} -> ShelleyBasedEra era -> UTxO ledgerera -> UTxO era
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UTxO ledgerera -> UTxO era
fromLedgerUTxO ShelleyBasedEra era
era result'
UTxO ledgerera
utxo'
      BlockQuery (ShelleyBlock ledgerera) result'
_                            -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
era (QueryUTxO QueryUTxOByTxIn{}) BlockQuery (ShelleyBlock ledgerera) result'
q' result'
utxo' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      Consensus.GetUTxOByTxIn{} -> ShelleyBasedEra era -> UTxO ledgerera -> UTxO era
forall era ledgerera.
(ShelleyLedgerEra era ~ ledgerera,
 Crypto ledgerera ~ StandardCrypto) =>
ShelleyBasedEra era -> UTxO ledgerera -> UTxO era
fromLedgerUTxO ShelleyBasedEra era
era result'
UTxO ledgerera
utxo'
      BlockQuery (ShelleyBlock ledgerera) result'
_                         -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ (QueryStakeAddresses Set StakeCredential
_ NetworkId
nId) BlockQuery (ShelleyBlock ledgerera) result'
q' result'
r' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      Consensus.GetFilteredDelegationsAndRewardAccounts{}
        -> let (Map
  (Credential 'Staking StandardCrypto)
  (KeyHash 'StakePool StandardCrypto)
delegs, RewardAccounts StandardCrypto
rwaccs) = result'
(Map
   (Credential 'Staking StandardCrypto)
   (KeyHash 'StakePool StandardCrypto),
 RewardAccounts StandardCrypto)
r'
           in ( (StakeCredential -> StakeAddress)
-> Map StakeCredential Lovelace -> Map StakeAddress Lovelace
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys (NetworkId -> StakeCredential -> StakeAddress
makeStakeAddress NetworkId
nId) (Map StakeCredential Lovelace -> Map StakeAddress Lovelace)
-> Map StakeCredential Lovelace -> Map StakeAddress Lovelace
forall a b. (a -> b) -> a -> b
$ RewardAccounts StandardCrypto -> Map StakeCredential Lovelace
fromShelleyRewardAccounts RewardAccounts StandardCrypto
rwaccs
              , (StakeCredential -> StakeAddress)
-> Map StakeCredential (Hash StakePoolKey)
-> Map StakeAddress (Hash StakePoolKey)
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys (NetworkId -> StakeCredential -> StakeAddress
makeStakeAddress NetworkId
nId) (Map StakeCredential (Hash StakePoolKey)
 -> Map StakeAddress (Hash StakePoolKey))
-> Map StakeCredential (Hash StakePoolKey)
-> Map StakeAddress (Hash StakePoolKey)
forall a b. (a -> b) -> a -> b
$ Map
  (Credential 'Staking StandardCrypto)
  (KeyHash 'StakePool StandardCrypto)
-> Map StakeCredential (Hash StakePoolKey)
fromShelleyDelegations Map
  (Credential 'Staking StandardCrypto)
  (KeyHash 'StakePool StandardCrypto)
delegs
              )
      BlockQuery (ShelleyBlock ledgerera) result'
_ -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryInShelleyBasedEra era result
QueryStakePools BlockQuery (ShelleyBlock ledgerera) result'
q' result'
poolids' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      BlockQuery (ShelleyBlock ledgerera) result'
Consensus.GetStakePools -> (KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey)
-> Set (KeyHash 'StakePool StandardCrypto)
-> Set (Hash StakePoolKey)
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey
StakePoolKeyHash result'
Set (KeyHash 'StakePool StandardCrypto)
poolids'
      BlockQuery (ShelleyBlock ledgerera) result'
_                       -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryStakePoolParameters{} BlockQuery (ShelleyBlock ledgerera) result'
q' result'
poolparams' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      Consensus.GetStakePoolParams{} -> (PoolParams StandardCrypto -> StakePoolParameters)
-> Map (Hash StakePoolKey) (PoolParams StandardCrypto)
-> Map (Hash StakePoolKey) StakePoolParameters
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map PoolParams StandardCrypto -> StakePoolParameters
fromShelleyPoolParams
                                      (Map (Hash StakePoolKey) (PoolParams StandardCrypto)
 -> Map (Hash StakePoolKey) StakePoolParameters)
-> (Map
      (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)
    -> Map (Hash StakePoolKey) (PoolParams StandardCrypto))
-> Map
     (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)
-> Map (Hash StakePoolKey) StakePoolParameters
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey)
-> Map
     (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)
-> Map (Hash StakePoolKey) (PoolParams StandardCrypto)
forall k1 k2 a. (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeysMonotonic KeyHash 'StakePool StandardCrypto -> Hash StakePoolKey
StakePoolKeyHash
                                      (Map
   (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)
 -> Map (Hash StakePoolKey) StakePoolParameters)
-> Map
     (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)
-> Map (Hash StakePoolKey) StakePoolParameters
forall a b. (a -> b) -> a -> b
$ result'
Map (KeyHash 'StakePool StandardCrypto) (PoolParams StandardCrypto)
poolparams'
      BlockQuery (ShelleyBlock ledgerera) result'
_                              -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryDebugLedgerState{} BlockQuery (ShelleyBlock ledgerera) result'
q' result'
r' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      Consensus.GetCBOR Consensus.DebugNewEpochState -> Serialised (NewEpochState (ShelleyLedgerEra era))
-> SerialisedDebugLedgerState era
forall era.
Serialised (NewEpochState (ShelleyLedgerEra era))
-> SerialisedDebugLedgerState era
SerialisedDebugLedgerState result'
Serialised (NewEpochState (ShelleyLedgerEra era))
r'
      BlockQuery (ShelleyBlock ledgerera) result'
_                                              -> result
forall a. a
fromConsensusQueryResultMismatch

fromConsensusQueryResultShelleyBased ShelleyBasedEra era
_ QueryInShelleyBasedEra era result
QueryProtocolState BlockQuery (ShelleyBlock ledgerera) result'
q' result'
r' =
    case BlockQuery (ShelleyBlock ledgerera) result'
q' of
      Consensus.GetCBOR Consensus.DebugChainDepState -> Serialised (ChainDepState (Crypto (ShelleyLedgerEra era)))
-> ProtocolState era
forall era.
Serialised (ChainDepState (Crypto (ShelleyLedgerEra era)))
-> ProtocolState era
ProtocolState result'
Serialised (ChainDepState (Crypto (ShelleyLedgerEra era)))
r'
      BlockQuery (ShelleyBlock ledgerera) result'
_                                              -> result
forall a. a
fromConsensusQueryResultMismatch

-- | This should /only/ happen if we messed up the mapping in 'toConsensusQuery'
-- and 'fromConsensusQueryResult' so they are inconsistent with each other.
--
-- If we do encounter this error it means that 'toConsensusQuery' maps a
-- API query constructor to a certain consensus query constructor but that
-- 'fromConsensusQueryResult' apparently expects a different pairing.
--
-- For example, imagine if 'toConsensusQuery would (incorrectly) map
-- 'QueryChainPoint' to 'Consensus.GetEpochNo' but 'fromConsensusQueryResult'
-- (correctly) expected to find 'Consensus.GetLedgerTip'. This mismatch would
-- trigger this error.
--
-- Such mismatches should be preventable with an appropriate property test.
--
fromConsensusQueryResultMismatch :: a
fromConsensusQueryResultMismatch :: a
fromConsensusQueryResultMismatch =
    String -> a
forall a. HasCallStack => String -> a
error String
"fromConsensusQueryResult: internal query mismatch"


fromConsensusEraMismatch :: SListI xs
                         => Consensus.MismatchEraInfo xs -> EraMismatch
fromConsensusEraMismatch :: MismatchEraInfo xs -> EraMismatch
fromConsensusEraMismatch = MismatchEraInfo xs -> EraMismatch
forall (xs :: [*]). SListI xs => MismatchEraInfo xs -> EraMismatch
Consensus.mkEraMismatch