diff --git a/cardano-api/internal/Cardano/Api/IPC.hs b/cardano-api/internal/Cardano/Api/IPC.hs index 2a14a39da0..00a4e5973a 100644 --- a/cardano-api/internal/Cardano/Api/IPC.hs +++ b/cardano-api/internal/Cardano/Api/IPC.hs @@ -106,6 +106,7 @@ import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus import qualified Ouroboros.Consensus.Shelley.Eras as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol () +import qualified Ouroboros.Consensus.Util as Consensus import qualified Ouroboros.Network.Block as Net import qualified Ouroboros.Network.Mux as Net import Ouroboros.Network.NodeToClient (NodeToClientProtocols (..), @@ -523,7 +524,7 @@ convLocalStateQueryClient convLocalStateQueryClient mode = Net.Query.mapLocalStateQueryClient (toConsensusPointInMode mode) - toConsensusQuery + ((\(Consensus.Some q) -> Net.Query.Some q) <$> toConsensusQuery) fromConsensusQueryResult diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index c6a5e2208f..d9b40d5cf8 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -161,7 +161,6 @@ import qualified Ouroboros.Consensus.Protocol.TPraos as TPraos import qualified Ouroboros.Consensus.Shelley.Eras as Shelley hiding (StandardCrypto) import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Shelley import qualified Ouroboros.Consensus.Shelley.Ledger.Ledger as Shelley hiding (LedgerState) -import qualified Ouroboros.Consensus.Shelley.Node.Praos as Consensus import Ouroboros.Consensus.TypeFamilyWrappers (WrapLedgerEvent (WrapLedgerEvent)) import qualified Ouroboros.Network.Block import qualified Ouroboros.Network.Protocol.ChainSync.Client as CS @@ -808,18 +807,18 @@ data NodeConfig = NodeConfig , ncRequiresNetworkMagic :: !Cardano.Crypto.RequiresNetworkMagic , ncByronProtocolVersion :: !Cardano.Chain.Update.ProtocolVersion - -- Per-era parameters for the hardfok transitions: + -- Per-era parameters for the hardfork transitions: , ncByronToShelley :: !(Consensus.ProtocolTransitionParams Byron.ByronBlock - (Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardShelley) + (Shelley.ShelleyBlock (TPraos Consensus.StandardCrypto) Shelley.StandardShelley) ) , ncShelleyToAllegra :: !(Consensus.ProtocolTransitionParams - (Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardShelley) - (Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardAllegra) + (Shelley.ShelleyBlock (TPraos Consensus.StandardCrypto) Shelley.StandardShelley) + (Shelley.ShelleyBlock (TPraos Consensus.StandardCrypto) Shelley.StandardAllegra) ) , ncAllegraToMary :: !(Consensus.ProtocolTransitionParams - (Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardAllegra) - (Shelley.ShelleyBlock (TPraos Shelley.StandardCrypto) Shelley.StandardMary) + (Shelley.ShelleyBlock (TPraos Consensus.StandardCrypto) Shelley.StandardAllegra) + (Shelley.ShelleyBlock (TPraos Consensus.StandardCrypto) Shelley.StandardMary) ) , ncMaryToAlonzo :: !Consensus.TriggerHardFork , ncAlonzoToBabbage :: !Consensus.TriggerHardFork diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index 08370d9516..0be5873d8c 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -121,9 +121,10 @@ import qualified Ouroboros.Consensus.HardFork.History.Qry as Qry import qualified Ouroboros.Consensus.Ledger.Query as Consensus import qualified Ouroboros.Consensus.Protocol.Abstract as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus +import qualified Ouroboros.Consensus.Util as Consensus +import Ouroboros.Consensus.Util.Singletons import Ouroboros.Network.Block (Serialised (..)) import Ouroboros.Network.NodeToClient.Version (NodeToClientVersion (..)) -import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..)) import Control.Monad (forM) import Control.Monad.Trans.Except @@ -357,11 +358,12 @@ data QueryUTxOFilter = QueryUTxOWhole -- | /O(n) time, O(m) space/ for utxo size n, and address set size m - | QueryUTxOByAddress (Set AddressAny) + | QueryUTxOByAddress (Set AddressAny) -- | /O(m log n) time, O(m) space/ for utxo size n, and address set size m - | QueryUTxOByTxIn (Set TxIn) - deriving (Eq, Show) + | QueryUTxOByTxIn (Set TxIn) + +deriving instance Show QueryUTxOFilter instance NodeToClientVersionOf QueryUTxOFilter where nodeToClientVersionOf QueryUTxOWhole = NodeToClientV_9 @@ -549,30 +551,30 @@ fromShelleyRewardAccounts = toConsensusQuery :: forall mode block result. ConsensusBlockForMode mode ~ block => QueryInMode mode result - -> Some (Consensus.Query block) + -> Consensus.Some (Consensus.Query block) toConsensusQuery (QueryCurrentEra CardanoModeIsMultiEra) = - Some $ Consensus.BlockQuery $ + Consensus.Some $ Consensus.BlockQuery $ Consensus.QueryHardFork Consensus.GetCurrentEra toConsensusQuery (QueryInEra ByronEraInByronMode QueryByronUpdateState) = - Some $ Consensus.BlockQuery $ + Consensus.Some $ Consensus.BlockQuery $ Consensus.DegenQuery Consensus.GetUpdateInterfaceState toConsensusQuery (QueryEraHistory CardanoModeIsMultiEra) = - Some $ Consensus.BlockQuery $ + Consensus.Some $ Consensus.BlockQuery $ Consensus.QueryHardFork Consensus.GetInterpreter -toConsensusQuery QuerySystemStart = Some Consensus.GetSystemStart +toConsensusQuery QuerySystemStart = Consensus.Some Consensus.GetSystemStart -toConsensusQuery QueryChainBlockNo = Some Consensus.GetChainBlockNo +toConsensusQuery QueryChainBlockNo = Consensus.Some Consensus.GetChainBlockNo -toConsensusQuery (QueryChainPoint _) = Some Consensus.GetChainPoint +toConsensusQuery (QueryChainPoint _) = Consensus.Some Consensus.GetChainPoint toConsensusQuery (QueryInEra ByronEraInCardanoMode QueryByronUpdateState) = - Some $ Consensus.BlockQuery $ + Consensus.Some $ Consensus.BlockQuery $ Consensus.QueryIfCurrentByron Consensus.GetUpdateInterfaceState @@ -586,7 +588,7 @@ toConsensusQuery (QueryInEra erainmode (QueryInShelleyBasedEra sbe q)) = MaryEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q AlonzoEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q BabbageEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q - ConwayEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q + ConwayEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q toConsensusQueryShelleyBased @@ -598,116 +600,118 @@ toConsensusQueryShelleyBased => block ~ Consensus.HardForkBlock xs => EraInMode era mode -> QueryInShelleyBasedEra era result - -> Some (Consensus.Query block) + -> Consensus.Some (Consensus.Query block) toConsensusQueryShelleyBased erainmode QueryEpoch = - Some (consensusQueryInEraInMode erainmode Consensus.GetEpochNo) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetEpochNo) toConsensusQueryShelleyBased erainmode QueryConstitution = - Some (consensusQueryInEraInMode erainmode Consensus.GetConstitution) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetConstitution) toConsensusQueryShelleyBased erainmode QueryGenesisParameters = - Some (consensusQueryInEraInMode erainmode Consensus.GetGenesisConfig) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetGenesisConfig) toConsensusQueryShelleyBased erainmode QueryProtocolParameters = - Some (consensusQueryInEraInMode erainmode Consensus.GetCurrentPParams) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetCurrentPParams) toConsensusQueryShelleyBased erainmode QueryProtocolParametersUpdate = - Some (consensusQueryInEraInMode erainmode Consensus.GetProposedPParamsUpdates) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetProposedPParamsUpdates) toConsensusQueryShelleyBased erainmode QueryStakeDistribution = - Some (consensusQueryInEraInMode erainmode Consensus.GetStakeDistribution) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetStakeDistribution) toConsensusQueryShelleyBased erainmode (QueryUTxO QueryUTxOWhole) = - Some (consensusQueryInEraInMode erainmode Consensus.GetUTxOWhole) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetUTxOWhole) toConsensusQueryShelleyBased erainmode (QueryUTxO (QueryUTxOByAddress addrs)) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetUTxOByAddress addrs')) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetUTxOByAddress addrs')) where addrs' :: Set (Shelley.Addr Consensus.StandardCrypto) addrs' = toShelleyAddrSet (eraInModeToEra erainmode) addrs toConsensusQueryShelleyBased erainmode (QueryUTxO (QueryUTxOByTxIn txins)) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetUTxOByTxIn txins')) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetUTxOByTxIn txins')) where txins' :: Set (Shelley.TxIn Consensus.StandardCrypto) txins' = Set.map toShelleyTxIn txins toConsensusQueryShelleyBased erainmode (QueryStakeAddresses creds _nId) = - Some (consensusQueryInEraInMode erainmode + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetFilteredDelegationsAndRewardAccounts creds')) where creds' :: Set (Shelley.Credential Shelley.Staking StandardCrypto) creds' = Set.map toShelleyStakeCredential creds toConsensusQueryShelleyBased erainmode QueryStakePools = - Some (consensusQueryInEraInMode erainmode Consensus.GetStakePools) + Consensus.Some (consensusQueryInEraInMode erainmode Consensus.GetStakePools) toConsensusQueryShelleyBased erainmode (QueryStakePoolParameters poolids) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetStakePoolParams poolids')) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetStakePoolParams poolids')) where poolids' :: Set (Shelley.KeyHash Shelley.StakePool Consensus.StandardCrypto) poolids' = Set.map unStakePoolKeyHash poolids toConsensusQueryShelleyBased erainmode QueryDebugLedgerState = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.DebugNewEpochState)) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.DebugNewEpochState)) toConsensusQueryShelleyBased erainmode QueryProtocolState = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.DebugChainDepState)) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.DebugChainDepState)) toConsensusQueryShelleyBased erainmode QueryCurrentEpochState = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.DebugEpochState)) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.DebugEpochState)) toConsensusQueryShelleyBased erainmode (QueryPoolState poolIds) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetPoolState (Set.map unStakePoolKeyHash <$> poolIds)))) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetPoolState (Set.map unStakePoolKeyHash <$> poolIds)))) toConsensusQueryShelleyBased erainmode (QueryStakeSnapshot mPoolIds) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetStakeSnapshots (fmap (Set.map unStakePoolKeyHash) mPoolIds)))) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetStakeSnapshots (fmap (Set.map unStakePoolKeyHash) mPoolIds)))) toConsensusQueryShelleyBased erainmode (QueryPoolDistribution poolIds) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetPoolDistr (getPoolIds <$> poolIds)))) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetPoolDistr (getPoolIds <$> poolIds)))) where getPoolIds :: Set PoolId -> Set (Shelley.KeyHash Shelley.StakePool Consensus.StandardCrypto) getPoolIds = Set.map (\(StakePoolKeyHash kh) -> kh) toConsensusQueryShelleyBased erainmode (QueryStakeDelegDeposits creds) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR $ Consensus.GetStakeDelegDeposits creds')) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR $ Consensus.GetStakeDelegDeposits creds')) where creds' = Set.map toShelleyStakeCredential creds toConsensusQueryShelleyBased erainmode QueryGovState = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.GetGovState)) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.GetGovState)) toConsensusQueryShelleyBased erainmode (QueryDRepState creds) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetDRepState creds))) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR (Consensus.GetDRepState creds))) toConsensusQueryShelleyBased erainmode (QueryDRepStakeDistr dreps) = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR $ Consensus.GetDRepStakeDistr dreps)) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR $ Consensus.GetDRepStakeDistr dreps)) toConsensusQueryShelleyBased erainmode QueryCommitteeState = - Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.GetCommitteeState)) + Consensus.Some (consensusQueryInEraInMode erainmode (Consensus.GetCBOR Consensus.GetCommitteeState)) consensusQueryInEraInMode - :: forall era mode erablock modeblock result result' xs. + :: forall era mode erablock modeblock result result' fp xs. ConsensusBlockForEra era ~ erablock => ConsensusBlockForMode mode ~ modeblock => modeblock ~ Consensus.HardForkBlock xs => Consensus.HardForkQueryResult xs result ~ result' + => SingI fp => EraInMode era mode - -> Consensus.BlockQuery erablock result + -> Consensus.BlockQuery erablock fp result -> Consensus.Query modeblock result' -consensusQueryInEraInMode erainmode = +consensusQueryInEraInMode erainmode b = Consensus.BlockQuery - . case erainmode of - ByronEraInByronMode -> Consensus.DegenQuery - ShelleyEraInShelleyMode -> Consensus.DegenQuery - ByronEraInCardanoMode -> Consensus.QueryIfCurrentByron - ShelleyEraInCardanoMode -> Consensus.QueryIfCurrentShelley - AllegraEraInCardanoMode -> Consensus.QueryIfCurrentAllegra - MaryEraInCardanoMode -> Consensus.QueryIfCurrentMary - AlonzoEraInCardanoMode -> Consensus.QueryIfCurrentAlonzo - BabbageEraInCardanoMode -> Consensus.QueryIfCurrentBabbage - ConwayEraInCardanoMode -> Consensus.QueryIfCurrentConway + ((case erainmode of + ByronEraInByronMode -> Consensus.DegenQuery b + ShelleyEraInShelleyMode -> Consensus.DegenQuery b + ByronEraInCardanoMode -> Consensus.QueryIfCurrentByron b + ShelleyEraInCardanoMode -> Consensus.QueryIfCurrentShelley b + AllegraEraInCardanoMode -> Consensus.QueryIfCurrentAllegra b + MaryEraInCardanoMode -> Consensus.QueryIfCurrentMary b + AlonzoEraInCardanoMode -> Consensus.QueryIfCurrentAlonzo b + BabbageEraInCardanoMode -> Consensus.QueryIfCurrentBabbage b + ConwayEraInCardanoMode -> Consensus.QueryIfCurrentConway b + ) :: Consensus.BlockQuery (Consensus.HardForkBlock xs) fp (Consensus.HardForkQueryResult xs result)) -- ---------------------------------------------------------------------------- -- Conversions of query results from the consensus types. @@ -842,13 +846,13 @@ fromConsensusQueryResult (QueryInEra ConwayEraInCardanoMode _ -> fromConsensusQueryResultMismatch fromConsensusQueryResultShelleyBased - :: forall era ledgerera protocol result result'. + :: forall era ledgerera protocol result fp result'. ShelleyLedgerEra era ~ ledgerera => Core.EraCrypto ledgerera ~ Consensus.StandardCrypto => ConsensusProtocol era ~ protocol => ShelleyBasedEra era -> QueryInShelleyBasedEra era result - -> Consensus.BlockQuery (Consensus.ShelleyBlock protocol ledgerera) result' + -> Consensus.BlockQuery (Consensus.ShelleyBlock protocol ledgerera) fp result' -> result' -> result fromConsensusQueryResultShelleyBased _ QueryEpoch q' epoch =