From b2c04da81b6394ef351253d5a313401a4078a557 Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Tue, 19 Nov 2024 08:24:19 -0600 Subject: [PATCH] Implement "query proposals" --- cardano-api/internal/Cardano/Api/Query.hs | 20 ++++++++++++++++ .../internal/Cardano/Api/Query/Expr.hs | 24 +++++++++++++++++++ .../internal/Cardano/Api/ReexposeLedger.hs | 5 ++-- cardano-api/src/Cardano/Api.hs | 1 + 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Query.hs b/cardano-api/internal/Cardano/Api/Query.hs index cf71e03976..bfdef390f4 100644 --- a/cardano-api/internal/Cardano/Api/Query.hs +++ b/cardano-api/internal/Cardano/Api/Query.hs @@ -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) @@ -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: @@ -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) @@ -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 @@ -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. diff --git a/cardano-api/internal/Cardano/Api/Query/Expr.hs b/cardano-api/internal/Cardano/Api/Query/Expr.hs index 74f3cd8d0f..f7cf15a16b 100644 --- a/cardano-api/internal/Cardano/Api/Query/Expr.hs +++ b/cardano-api/internal/Cardano/Api/Query/Expr.hs @@ -35,6 +35,7 @@ module Cardano.Api.Query.Expr , queryDRepState , queryGovState , queryStakeVoteDelegatees + , queryProposals ) where @@ -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 @@ -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 diff --git a/cardano-api/internal/Cardano/Api/ReexposeLedger.hs b/cardano-api/internal/Cardano/Api/ReexposeLedger.hs index d526ccb10a..8df2aba34a 100644 --- a/cardano-api/internal/Cardano/Api/ReexposeLedger.hs +++ b/cardano-api/internal/Cardano/Api/ReexposeLedger.hs @@ -79,6 +79,7 @@ module Cardano.Api.ReexposeLedger , GovAction (..) , GovActionId (..) , GovActionIx (..) + , GovActionState , Vote (..) , Voter (..) , VotingProcedure (..) @@ -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 (..), diff --git a/cardano-api/src/Cardano/Api.hs b/cardano-api/src/Cardano/Api.hs index dd7d862f54..687019ca8e 100644 --- a/cardano-api/src/Cardano/Api.hs +++ b/cardano-api/src/Cardano/Api.hs @@ -996,6 +996,7 @@ module Cardano.Api , queryDRepState , queryDRepStakeDistribution , querySPOStakeDistribution + , queryProposals , queryCommitteeMembersState , queryStakeVoteDelegatees