diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index 03120796f7..bac0b4bf4f 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -285,6 +285,9 @@ data QueryInShelleyBasedEra era result where QueryDRepStakeDistr :: Set (Ledger.DRep StandardCrypto) -> QueryInShelleyBasedEra era (Map (Ledger.DRep StandardCrypto) L.Coin) + QuerySPOStakeDistr + :: Set (Ledger.KeyHash 'Ledger.StakePool StandardCrypto) + -> QueryInShelleyBasedEra era (Map (Ledger.KeyHash 'Ledger.StakePool Ledger.StandardCrypto) L.Coin) QueryCommitteeMembersState :: Set (Shelley.Credential Shelley.ColdCommitteeRole StandardCrypto) -> Set (Shelley.Credential Shelley.HotCommitteeRole StandardCrypto) @@ -322,6 +325,7 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where nodeToClientVersionOf QueryGovState = NodeToClientV_16 nodeToClientVersionOf QueryDRepState{} = NodeToClientV_16 nodeToClientVersionOf QueryDRepStakeDistr{} = NodeToClientV_16 + nodeToClientVersionOf QuerySPOStakeDistr{} = NodeToClientV_16 nodeToClientVersionOf QueryCommitteeMembersState{} = NodeToClientV_16 nodeToClientVersionOf QueryStakeVoteDelegatees{} = NodeToClientV_16 @@ -666,6 +670,13 @@ toConsensusQueryShelleyBased sbe = \case ) (const $ Some (consensusQueryInEraInMode era (Consensus.GetDRepStakeDistr dreps))) sbe + QuerySPOStakeDistr spos -> + caseShelleyToBabbageOrConwayEraOnwards + ( const $ + error "toConsensusQueryShelleyBased: QuerySPOStakeDistr is only available in the Conway era" + ) + (const $ Some (consensusQueryInEraInMode era (Consensus.GetSPOStakeDistr spos))) + sbe QueryCommitteeMembersState coldCreds hotCreds statuses -> caseShelleyToBabbageOrConwayEraOnwards ( const $ @@ -958,6 +969,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' = Consensus.GetDRepStakeDistr{} -> r' _ -> fromConsensusQueryResultMismatch + QuerySPOStakeDistr{} -> + case q' of + Consensus.GetSPOStakeDistr{} -> + r' + _ -> fromConsensusQueryResultMismatch QueryCommitteeMembersState{} -> case q' of Consensus.GetCommitteeMembersState{} -> diff --git a/cardano-api/internal/Cardano/Api/Query/Expr.hs b/cardano-api/internal/Cardano/Api/Query/Expr.hs index 9615951f25..43415793ce 100644 --- a/cardano-api/internal/Cardano/Api/Query/Expr.hs +++ b/cardano-api/internal/Cardano/Api/Query/Expr.hs @@ -30,6 +30,7 @@ module Cardano.Api.Query.Expr , L.CommitteeMembersState (..) , queryCommitteeMembersState , queryDRepStakeDistribution + , querySPOStakeDistribution , queryDRepState , queryGovState , queryStakeVoteDelegatees @@ -416,6 +417,25 @@ queryDRepStakeDistribution era dreps = do let sbe = conwayEraOnwardsToShelleyBasedEra era queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryDRepStakeDistr dreps +querySPOStakeDistribution + :: () + => ConwayEraOnwards era + -> 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)) + ) +querySPOStakeDistribution era spos = do + let sbe = conwayEraOnwardsToShelleyBasedEra era + queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QuerySPOStakeDistr spos + -- | Returns info about committee members filtered by: cold credentials, hot credentials and statuses. -- If empty sets are passed as filters, then no filtering is done. queryCommitteeMembersState diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index d385afc7cf..0baabb2da8 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -970,6 +970,7 @@ module Cardano.Api , queryGovState , queryDRepState , queryDRepStakeDistribution + , querySPOStakeDistribution , queryCommitteeMembersState , queryStakeVoteDelegatees