Skip to content

Commit

Permalink
Implement "query proposals"
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLopezDeLara authored and smelc committed Dec 5, 2024
1 parent 4396ad1 commit b2c04da
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
20 changes: 20 additions & 0 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import Data.Either.Combinators (rightToMaybe)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (mapMaybe)
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.SOP.Constraint (SListI)
Expand Down Expand Up @@ -296,6 +297,9 @@ data QueryInShelleyBasedEra era result where
QueryStakeVoteDelegatees
:: Set StakeCredential
-> QueryInShelleyBasedEra era (Map StakeCredential (Ledger.DRep StandardCrypto))
QueryProposals
:: Set (L.GovActionId StandardCrypto)
-> QueryInShelleyBasedEra era (Seq (L.GovActionState (ShelleyLedgerEra era)))

-- | Mapping for queries in Shelley-based eras returning minimal node-to-client protocol versions. More
-- information about queries versioning can be found:
Expand Down Expand Up @@ -328,6 +332,7 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where
nodeToClientVersionOf QuerySPOStakeDistr{} = NodeToClientV_16
nodeToClientVersionOf QueryCommitteeMembersState{} = NodeToClientV_16
nodeToClientVersionOf QueryStakeVoteDelegatees{} = NodeToClientV_16
nodeToClientVersionOf QueryProposals{} = NodeToClientV_17

deriving instance Show (QueryInShelleyBasedEra era result)

Expand Down Expand Up @@ -703,6 +708,16 @@ toConsensusQueryShelleyBased sbe = \case
where
creds' :: Set (Shelley.Credential Shelley.Staking StandardCrypto)
creds' = Set.map toShelleyStakeCredential creds
QueryProposals govActs ->
caseShelleyToBabbageOrConwayEraOnwards
( const $
error "toConsensusQueryShelleyBased: QueryProposals is only available in the Conway era"
)
( const $
Some
(consensusQueryInEraInMode era (Consensus.GetProposals govActs))
)
sbe
where
era = toCardanoEra sbe

Expand Down Expand Up @@ -984,6 +999,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' =
Consensus.GetFilteredVoteDelegatees{} ->
Map.mapKeys fromShelleyStakeCredential r'
_ -> fromConsensusQueryResultMismatch
QueryProposals{} ->
case q' of
Consensus.GetProposals{} ->
r'
_ -> fromConsensusQueryResultMismatch

-- | This should /only/ happen if we messed up the mapping in 'toConsensusQuery'
-- and 'fromConsensusQueryResult' so they are inconsistent with each other.
Expand Down
24 changes: 24 additions & 0 deletions cardano-api/internal/Cardano/Api/Query/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Cardano.Api.Query.Expr
, queryDRepState
, queryGovState
, queryStakeVoteDelegatees
, queryProposals
)
where

Expand Down Expand Up @@ -68,6 +69,7 @@ import Cardano.Slotting.Slot
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus

import Data.Map (Map)
import Data.Sequence (Seq)
import Data.Set (Set)
import qualified Data.Set as S

Expand Down Expand Up @@ -484,3 +486,25 @@ queryAccountState cOnwards =
queryExpr $
QueryInEra . QueryInShelleyBasedEra (convert cOnwards) $
QueryAccountState

queryProposals
:: forall era block point r
. ConwayEraOnwards 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 (L.GovActionId L.StandardCrypto)
-> LocalStateQueryExpr
block
point
QueryInMode
r
IO
( Either
UnsupportedNtcVersionError
(Either EraMismatch (Seq (L.GovActionState (ShelleyLedgerEra era))))
)
queryProposals cOnwards govActionIds = do
let sbe = convert cOnwards
queryExpr $
QueryInEra . QueryInShelleyBasedEra sbe $
QueryProposals govActionIds
5 changes: 3 additions & 2 deletions cardano-api/internal/Cardano/Api/ReexposeLedger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module Cardano.Api.ReexposeLedger
, GovAction (..)
, GovActionId (..)
, GovActionIx (..)
, GovActionState
, Vote (..)
, Voter (..)
, VotingProcedure (..)
Expand Down Expand Up @@ -209,8 +210,8 @@ import Cardano.Ledger.Conway.Core (DRepVotingThresholds (..), PoolVoti
dvtUpdateToConstitutionL)
import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..))
import Cardano.Ledger.Conway.Governance (Anchor (..), Committee (..), GovActionId (..),
GovActionIx (..), GovState, ProposalProcedure (..), Vote (..), Voter (..),
VotingProcedure (..), VotingProcedures (..))
GovActionIx (..), GovActionState, GovState, ProposalProcedure (..), Vote (..),
Voter (..), VotingProcedure (..), VotingProcedures (..))
import Cardano.Ledger.Conway.PParams (UpgradeConwayPParams (..))
import Cardano.Ledger.Conway.Scripts (ConwayPlutusPurpose (..))
import Cardano.Ledger.Conway.TxCert (ConwayDelegCert (..), ConwayEraTxCert (..),
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ module Cardano.Api
, queryDRepState
, queryDRepStakeDistribution
, querySPOStakeDistribution
, queryProposals
, queryCommitteeMembersState
, queryStakeVoteDelegatees

Expand Down

0 comments on commit b2c04da

Please sign in to comment.