Skip to content

Commit

Permalink
Add state query for proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucsanszky authored and lehins committed Aug 1, 2024
1 parent bca8e2b commit 99f8d49
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libs/cardano-ledger-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Version history for `cardano-ledger-api`

## 1.9.2.2
## 1.9.3.0

*
* Add `queryProposals` state query

## 1.9.2.1

Expand Down
3 changes: 2 additions & 1 deletion libs/cardano-ledger-api/cardano-ledger-api.cabal
Original file line number Diff line number Diff line change
@@ -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: [email protected]
author: IOHK
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api/State/Query.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Ledger.Api.State.Query (
Expand Down Expand Up @@ -45,6 +46,9 @@ module Cardano.Ledger.Api.State.Query (
-- * @GetFuturePParams@
queryFuturePParams,

-- * @GetProposals@
queryProposals,

-- * For testing
getNextEpochCommitteeMembers,
) where
Expand All @@ -64,13 +68,18 @@ import Cardano.Ledger.Conway.Governance (
Committee (committeeMembers),
Constitution (constitutionAnchor),
ConwayEraGov (..),
DRepPulser (..),
DRepPulsingState (..),
GovActionId,
GovActionState (..),
PulsingSnapshot,
RatifyState,
committeeThresholdL,
ensCommitteeL,
finishDRepPulser,
psDRepDistr,
psPoolDistr,
psProposalsL,
rsEnactStateL,
)
import Cardano.Ledger.Conway.Rules (updateDormantDRepExpiry)
Expand All @@ -90,6 +99,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
Expand Down Expand Up @@ -309,6 +321,24 @@ 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

finishedPulserState ::
ConwayEraGov era =>
NewEpochState era ->
Expand Down

0 comments on commit 99f8d49

Please sign in to comment.