diff --git a/libs/cardano-ledger-api/CHANGELOG.md b/libs/cardano-ledger-api/CHANGELOG.md index b782ac55892..c8fe0e0bcc4 100644 --- a/libs/cardano-ledger-api/CHANGELOG.md +++ b/libs/cardano-ledger-api/CHANGELOG.md @@ -1,8 +1,9 @@ # Version history for `cardano-ledger-api` -## 1.9.2.2 +## 1.9.3.0 -* +* Add `queryRatifyState` state query +* Add `queryProposals` state query ## 1.9.2.1 diff --git a/libs/cardano-ledger-api/cardano-ledger-api.cabal b/libs/cardano-ledger-api/cardano-ledger-api.cabal index f477d680f3e..dcb3cd5a8b7 100644 --- a/libs/cardano-ledger-api/cardano-ledger-api.cabal +++ b/libs/cardano-ledger-api/cardano-ledger-api.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: cardano-ledger-api -version: 1.9.2.2 +version: 1.9.3.0 license: Apache-2.0 maintainer: operations@iohk.io author: IOHK @@ -62,6 +62,7 @@ library cardano-ledger-core >=1.13.2 && <1.15, cardano-ledger-mary >=1.5 && <1.7, cardano-ledger-shelley ^>=1.12, + cardano-strict-containers, containers, FailT, microlens, diff --git a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs index 3453d532f27..f33e3195442 100644 --- a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs +++ b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs @@ -1,5 +1,6 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} module Cardano.Ledger.Api.State.Query ( @@ -45,6 +46,12 @@ module Cardano.Ledger.Api.State.Query ( -- * @GetFuturePParams@ queryFuturePParams, + -- * @GetProposals@ + queryProposals, + + -- * @GetRatifyState@ + queryRatifyState, + -- * For testing getNextEpochCommitteeMembers, ) where @@ -64,6 +71,10 @@ import Cardano.Ledger.Conway.Governance ( Committee (committeeMembers), Constitution (constitutionAnchor), ConwayEraGov (..), + DRepPulser (..), + DRepPulsingState (..), + GovActionId, + GovActionState (..), PulsingSnapshot, RatifyState, committeeThresholdL, @@ -71,6 +82,7 @@ import Cardano.Ledger.Conway.Governance ( finishDRepPulser, psDRepDistr, psPoolDistr, + psProposalsL, rsEnactStateL, ) import Cardano.Ledger.Conway.Rules (updateDormantDRepExpiry) @@ -90,6 +102,9 @@ import Data.Foldable (foldMap') import Data.Map (Map) import qualified Data.Map.Strict as Map import Data.Maybe (isJust) +import Data.Sequence (Seq (..)) +import qualified Data.Sequence as Seq +import Data.Sequence.Strict (StrictSeq (..)) import Data.Set (Set) import qualified Data.Set as Set import Lens.Micro @@ -289,7 +304,7 @@ getNextEpochCommitteeMembers :: NewEpochState era -> Map (Credential 'ColdCommitteeRole (EraCrypto era)) EpochNo getNextEpochCommitteeMembers nes = - let ratifyState = snd $ finishedPulserState nes + let ratifyState = queryRatifyState nes committee = ratifyState ^. rsEnactStateL . ensCommitteeL in foldMap' committeeMembers committee @@ -309,6 +324,28 @@ queryFuturePParams nes = PotentialPParamsUpdate mpp -> mpp DefinitePParamsUpdate pp -> Just pp +-- | Query proposals that are considered for ratification. +queryProposals :: + ConwayEraGov era => + NewEpochState era -> + -- | Specify a set of Governance Action IDs to filter the proposals. When this set is + -- empty, all the proposals considered for ratification will be returned. + Set (GovActionId (EraCrypto era)) -> + Seq (GovActionState era) +queryProposals nes gids + | null gids = proposals + -- TODO: Add `filter` to `cardano-strict-containers` + | otherwise = + Seq.filter (\GovActionState {..} -> gasId `Set.member` gids) proposals + where + proposals = fromStrict $ case (nes ^. newEpochStateGovStateL . drepPulsingStateGovStateL) of + DRComplete snap _rs -> snap ^. psProposalsL + DRPulsing DRepPulser {..} -> dpProposals + +-- | Query ratification state. +queryRatifyState :: ConwayEraGov era => NewEpochState era -> RatifyState era +queryRatifyState = snd . finishedPulserState + finishedPulserState :: ConwayEraGov era => NewEpochState era ->