From d09090d5745ca259a3f90e93d4180aafac373628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Fri, 31 Jan 2025 22:44:49 -0600 Subject: [PATCH] add query future pparams --- cardano-api/internal/Cardano/Api/Query.hs | 27 +- .../internal/Cardano/Api/Query/Expr.hs | 405 +++++++++--------- cardano-api/src/Cardano/Api.hs | 1 + 3 files changed, 232 insertions(+), 201 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index f7c4bee510..e481aed7fc 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -236,8 +236,8 @@ data QueryInShelleyBasedEra era result where :: QueryInShelleyBasedEra era (Ledger.PParams (ShelleyLedgerEra era)) QueryProtocolParametersUpdate :: QueryInShelleyBasedEra - era - (Map (Hash GenesisKey) ProtocolParametersUpdate) + era + (Map (Hash GenesisKey) ProtocolParametersUpdate) QueryStakeDistribution :: QueryInShelleyBasedEra era (Map (Hash StakePoolKey) Rational) QueryUTxO @@ -282,11 +282,13 @@ data QueryInShelleyBasedEra era result where :: QueryInShelleyBasedEra era (L.GovState (ShelleyLedgerEra era)) QueryRatifyState :: QueryInShelleyBasedEra era (L.RatifyState (ShelleyLedgerEra era)) + QueryFuturePParams + :: QueryInShelleyBasedEra era (Maybe (Core.PParams (ShelleyLedgerEra era))) QueryDRepState :: Set (Shelley.Credential Shelley.DRepRole StandardCrypto) -> QueryInShelleyBasedEra - era - (Map (Shelley.Credential Shelley.DRepRole StandardCrypto) (L.DRepState StandardCrypto)) + era + (Map (Shelley.Credential Shelley.DRepRole StandardCrypto) (L.DRepState StandardCrypto)) QueryDRepStakeDistr :: Set (Ledger.DRep StandardCrypto) -> QueryInShelleyBasedEra era (Map (Ledger.DRep StandardCrypto) L.Coin) @@ -340,6 +342,7 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where nodeToClientVersionOf QueryStakeVoteDelegatees{} = NodeToClientV_16 nodeToClientVersionOf QueryProposals{} = NodeToClientV_17 nodeToClientVersionOf QueryRatifyState{} = NodeToClientV_17 + nodeToClientVersionOf QueryFuturePParams{} = NodeToClientV_18 nodeToClientVersionOf QueryLedgerPeerSnapshot = NodeToClientV_19 deriving instance Show (QueryInShelleyBasedEra era result) @@ -538,8 +541,8 @@ fromShelleyPoolDistr = fromShelleyDelegations :: Map - (Shelley.Credential Shelley.Staking StandardCrypto) - (Shelley.KeyHash Shelley.StakePool StandardCrypto) + (Shelley.Credential Shelley.Staking StandardCrypto) + (Shelley.KeyHash Shelley.StakePool StandardCrypto) -> Map StakeCredential PoolId fromShelleyDelegations = -- TODO: write an appropriate property to show it is safe to use @@ -681,6 +684,13 @@ toConsensusQueryShelleyBased sbe = \case (const $ error "toConsensusQueryShelleyBased: QueryRatifyState is only available in the Conway era") (const $ Some (consensusQueryInEraInMode era Consensus.GetRatifyState)) sbe + QueryFuturePParams -> + caseShelleyToBabbageOrConwayEraOnwards + ( const $ + error "toConsensusQueryShelleyBased: QueryFuturePParams is only available in the Conway era onwards" + ) + (const $ Some (consensusQueryInEraInMode era Consensus.GetFuturePParams)) + sbe QueryDRepState creds -> caseShelleyToBabbageOrConwayEraOnwards (const $ error "toConsensusQueryShelleyBased: QueryDRepState is only available in the Conway era") @@ -999,6 +1009,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' = Consensus.GetRatifyState{} -> r' _ -> fromConsensusQueryResultMismatch + QueryFuturePParams{} -> + case q' of + Consensus.GetFuturePParams{} -> + r' + _ -> fromConsensusQueryResultMismatch QueryDRepState{} -> case q' of Consensus.GetDRepState{} -> diff --git a/cardano-api/internal/Cardano/Api/Query/Expr.hs b/cardano-api/internal/Cardano/Api/Query/Expr.hs index cfb3d3c6ac..9a5db7f256 100644 --- a/cardano-api/internal/Cardano/Api/Query/Expr.hs +++ b/cardano-api/internal/Cardano/Api/Query/Expr.hs @@ -36,6 +36,7 @@ module Cardano.Api.Query.Expr , queryDRepState , queryGovState , queryRatifyState + , queryFuturePParams , queryStakeVoteDelegatees , queryProposals ) @@ -80,12 +81,12 @@ import qualified Data.Set as S queryChainBlockNo :: () => LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (WithOrigin BlockNo)) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (WithOrigin BlockNo)) queryChainBlockNo = queryExpr QueryChainBlockNo @@ -105,12 +106,12 @@ queryCurrentEpochState :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedCurrentEpochState era))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedCurrentEpochState era))) queryCurrentEpochState sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryCurrentEpochState @@ -118,12 +119,12 @@ queryEpoch :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch EpochNo)) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch EpochNo)) queryEpoch sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryEpoch @@ -131,12 +132,12 @@ queryDebugLedgerState :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedDebugLedgerState era))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedDebugLedgerState era))) queryDebugLedgerState sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryDebugLedgerState @@ -144,12 +145,12 @@ queryLedgerPeerSnapshot :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (Serialised LedgerPeerSnapshot))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (Serialised LedgerPeerSnapshot))) queryLedgerPeerSnapshot sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryLedgerPeerSnapshot @@ -163,12 +164,12 @@ queryGenesisParameters :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (GenesisParameters ShelleyEra))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (GenesisParameters ShelleyEra))) queryGenesisParameters sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryGenesisParameters @@ -177,12 +178,12 @@ queryPoolDistribution => BabbageEraOnwards era -> Maybe (Set PoolId) -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedPoolDistribution era))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedPoolDistribution era))) queryPoolDistribution era mPoolIds = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryPoolDistribution mPoolIds @@ -192,12 +193,12 @@ queryPoolState => BabbageEraOnwards era -> Maybe (Set PoolId) -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedPoolState era))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedPoolState era))) queryPoolState era mPoolIds = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryPoolState mPoolIds @@ -206,12 +207,12 @@ queryProtocolParameters :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (Ledger.PParams (ShelleyLedgerEra era)))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (Ledger.PParams (ShelleyLedgerEra era)))) queryProtocolParameters sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryProtocolParameters @@ -219,15 +220,15 @@ queryConstitutionHash :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - ( Either - UnsupportedNtcVersionError - (Either EraMismatch (SafeHash (EraCrypto (ShelleyLedgerEra era)) L.AnchorData)) - ) + block + point + QueryInMode + r + IO + ( Either + UnsupportedNtcVersionError + (Either EraMismatch (SafeHash (EraCrypto (ShelleyLedgerEra era)) L.AnchorData)) + ) queryConstitutionHash sbe = (fmap . fmap . fmap) (L.anchorDataHash . L.constitutionAnchor) $ queryExpr $ @@ -238,15 +239,15 @@ queryProtocolParametersUpdate :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - ( Either - UnsupportedNtcVersionError - (Either EraMismatch (Map (Hash GenesisKey) ProtocolParametersUpdate)) - ) + block + point + QueryInMode + r + IO + ( Either + UnsupportedNtcVersionError + (Either EraMismatch (Map (Hash GenesisKey) ProtocolParametersUpdate)) + ) queryProtocolParametersUpdate sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryProtocolParametersUpdate @@ -254,12 +255,12 @@ queryProtocolState :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (ProtocolState era))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (ProtocolState era))) queryProtocolState sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryProtocolState @@ -269,15 +270,15 @@ queryStakeAddresses -> Set StakeCredential -> NetworkId -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - ( Either - UnsupportedNtcVersionError - (Either EraMismatch (Map StakeAddress L.Coin, Map StakeAddress PoolId)) - ) + block + point + QueryInMode + r + IO + ( Either + UnsupportedNtcVersionError + (Either EraMismatch (Map StakeAddress L.Coin, Map StakeAddress PoolId)) + ) queryStakeAddresses sbe stakeCredentials networkId = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryStakeAddresses stakeCredentials networkId @@ -285,12 +286,12 @@ queryStakeDelegDeposits :: BabbageEraOnwards era -> Set StakeCredential -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either Consensus.EraMismatch (Map StakeCredential L.Coin))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either Consensus.EraMismatch (Map StakeCredential L.Coin))) queryStakeDelegDeposits era stakeCreds | S.null stakeCreds = pure . pure $ pure mempty | otherwise = do @@ -301,12 +302,12 @@ queryStakeDistribution :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (Map (Hash StakePoolKey) Rational))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (Map (Hash StakePoolKey) Rational))) queryStakeDistribution sbe = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryStakeDistribution @@ -315,12 +316,12 @@ queryStakePoolParameters => ShelleyBasedEra era -> Set PoolId -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (Map PoolId StakePoolParameters))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (Map PoolId StakePoolParameters))) queryStakePoolParameters sbe poolIds | S.null poolIds = pure . pure $ pure mempty | otherwise = @@ -330,12 +331,12 @@ queryStakePools :: () => ShelleyBasedEra era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (Set PoolId))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (Set PoolId))) queryStakePools sbe = queryExpr $ QueryInEra . QueryInShelleyBasedEra sbe $ QueryStakePools @@ -344,12 +345,12 @@ queryStakeSnapshot => BabbageEraOnwards era -> Maybe (Set PoolId) -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedStakeSnapshots era))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedStakeSnapshots era))) queryStakeSnapshot era mPoolIds = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryStakeSnapshot mPoolIds @@ -365,12 +366,12 @@ queryUtxo => ShelleyBasedEra era -> QueryUTxOFilter -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (UTxO era))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (UTxO era))) queryUtxo sbe utxoFilter = queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryUTxO utxoFilter @@ -378,12 +379,12 @@ queryConstitution :: () => ConwayEraOnwards era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (L.Constitution (ShelleyLedgerEra era)))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (L.Constitution (ShelleyLedgerEra era)))) queryConstitution era = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryConstitution @@ -392,12 +393,12 @@ queryGovState :: () => ConwayEraOnwards era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (L.GovState (ShelleyLedgerEra era)))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (L.GovState (ShelleyLedgerEra era)))) queryGovState era = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryGovState @@ -406,30 +407,44 @@ queryRatifyState :: () => ConwayEraOnwards era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (L.RatifyState (ShelleyLedgerEra era)))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (L.RatifyState (ShelleyLedgerEra era)))) queryRatifyState era = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryRatifyState +queryFuturePParams + :: () + => ConwayEraOnwards era + -> LocalStateQueryExpr + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (Maybe (L.PParams (ShelleyLedgerEra era))))) +queryFuturePParams era = do + let sbe = convert era + queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe QueryFuturePParams + queryDRepState :: ConwayEraOnwards era -> Set (L.Credential L.DRepRole L.StandardCrypto) -- ^ An empty credentials set means that states for all DReps will be returned -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - ( Either - UnsupportedNtcVersionError - (Either EraMismatch (Map (L.Credential L.DRepRole L.StandardCrypto) (L.DRepState L.StandardCrypto))) - ) + block + point + QueryInMode + r + IO + ( Either + UnsupportedNtcVersionError + (Either EraMismatch (Map (L.Credential L.DRepRole L.StandardCrypto) (L.DRepState L.StandardCrypto))) + ) queryDRepState era drepCreds = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryDRepState drepCreds @@ -439,12 +454,12 @@ queryDRepStakeDistribution -> Set (L.DRep L.StandardCrypto) -- ^ An empty DRep set means that distributions for all DReps will be returned -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (Map (L.DRep L.StandardCrypto) L.Coin))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (Map (L.DRep L.StandardCrypto) L.Coin))) queryDRepStakeDistribution era dreps = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryDRepStakeDistr dreps @@ -454,15 +469,15 @@ querySPOStakeDistribution -> Set (L.KeyHash 'L.StakePool L.StandardCrypto) -- ^ An empty SPO key hash set means that distributions for all SPOs will be returned -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - ( Either - UnsupportedNtcVersionError - (Either EraMismatch (Map (L.KeyHash 'L.StakePool L.StandardCrypto) L.Coin)) - ) + block + point + QueryInMode + r + IO + ( Either + UnsupportedNtcVersionError + (Either EraMismatch (Map (L.KeyHash 'L.StakePool L.StandardCrypto) L.Coin)) + ) querySPOStakeDistribution era spos = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QuerySPOStakeDistr spos @@ -475,12 +490,12 @@ queryCommitteeMembersState -> Set (L.Credential L.HotCommitteeRole L.StandardCrypto) -> Set L.MemberStatus -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch (L.CommitteeMembersState L.StandardCrypto))) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch (L.CommitteeMembersState L.StandardCrypto))) queryCommitteeMembersState era coldCreds hotCreds statuses = do let sbe = convert era queryExpr $ @@ -491,15 +506,15 @@ queryStakeVoteDelegatees :: ConwayEraOnwards era -> Set StakeCredential -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - ( Either - UnsupportedNtcVersionError - (Either EraMismatch (Map StakeCredential (L.DRep L.StandardCrypto))) - ) + block + point + QueryInMode + r + IO + ( Either + UnsupportedNtcVersionError + (Either EraMismatch (Map StakeCredential (L.DRep L.StandardCrypto))) + ) queryStakeVoteDelegatees era stakeCredentials = do let sbe = convert era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryStakeVoteDelegatees stakeCredentials @@ -507,12 +522,12 @@ queryStakeVoteDelegatees era stakeCredentials = do queryAccountState :: ConwayEraOnwards era -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - (Either UnsupportedNtcVersionError (Either EraMismatch L.AccountState)) + block + point + QueryInMode + r + IO + (Either UnsupportedNtcVersionError (Either EraMismatch L.AccountState)) queryAccountState cOnwards = queryExpr $ QueryInEra . QueryInShelleyBasedEra (convert cOnwards) $ @@ -525,15 +540,15 @@ queryProposals -- empty, all the proposals considered for ratification will be returned. -> Set (L.GovActionId L.StandardCrypto) -> LocalStateQueryExpr - block - point - QueryInMode - r - IO - ( Either - UnsupportedNtcVersionError - (Either EraMismatch (Seq (L.GovActionState (ShelleyLedgerEra era)))) - ) + block + point + QueryInMode + r + IO + ( Either + UnsupportedNtcVersionError + (Either EraMismatch (Seq (L.GovActionState (ShelleyLedgerEra era)))) + ) queryProposals cOnwards govActionIds = do let sbe = convert cOnwards queryExpr $ diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index 02498e5324..dfae71c4ca 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -1032,6 +1032,7 @@ module Cardano.Api , queryConstitution , queryGovState , queryRatifyState + , queryFuturePParams , queryDRepState , queryDRepStakeDistribution , querySPOStakeDistribution