Skip to content

Commit 6a42210

Browse files
authored
Merge pull request #684 from IntersectMBO/cl/queryProposals
Integrate query proposals
2 parents 4396ad1 + b2c04da commit 6a42210

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

cardano-api/internal/Cardano/Api/Query.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import Data.Either.Combinators (rightToMaybe)
125125
import Data.Map.Strict (Map)
126126
import qualified Data.Map.Strict as Map
127127
import Data.Maybe (mapMaybe)
128+
import Data.Sequence (Seq)
128129
import Data.Set (Set)
129130
import qualified Data.Set as Set
130131
import Data.SOP.Constraint (SListI)
@@ -296,6 +297,9 @@ data QueryInShelleyBasedEra era result where
296297
QueryStakeVoteDelegatees
297298
:: Set StakeCredential
298299
-> QueryInShelleyBasedEra era (Map StakeCredential (Ledger.DRep StandardCrypto))
300+
QueryProposals
301+
:: Set (L.GovActionId StandardCrypto)
302+
-> QueryInShelleyBasedEra era (Seq (L.GovActionState (ShelleyLedgerEra era)))
299303

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

332337
deriving instance Show (QueryInShelleyBasedEra era result)
333338

@@ -703,6 +708,16 @@ toConsensusQueryShelleyBased sbe = \case
703708
where
704709
creds' :: Set (Shelley.Credential Shelley.Staking StandardCrypto)
705710
creds' = Set.map toShelleyStakeCredential creds
711+
QueryProposals govActs ->
712+
caseShelleyToBabbageOrConwayEraOnwards
713+
( const $
714+
error "toConsensusQueryShelleyBased: QueryProposals is only available in the Conway era"
715+
)
716+
( const $
717+
Some
718+
(consensusQueryInEraInMode era (Consensus.GetProposals govActs))
719+
)
720+
sbe
706721
where
707722
era = toCardanoEra sbe
708723

@@ -984,6 +999,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' =
984999
Consensus.GetFilteredVoteDelegatees{} ->
9851000
Map.mapKeys fromShelleyStakeCredential r'
9861001
_ -> fromConsensusQueryResultMismatch
1002+
QueryProposals{} ->
1003+
case q' of
1004+
Consensus.GetProposals{} ->
1005+
r'
1006+
_ -> fromConsensusQueryResultMismatch
9871007

9881008
-- | This should /only/ happen if we messed up the mapping in 'toConsensusQuery'
9891009
-- and 'fromConsensusQueryResult' so they are inconsistent with each other.

cardano-api/internal/Cardano/Api/Query/Expr.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module Cardano.Api.Query.Expr
3535
, queryDRepState
3636
, queryGovState
3737
, queryStakeVoteDelegatees
38+
, queryProposals
3839
)
3940
where
4041

@@ -68,6 +69,7 @@ import Cardano.Slotting.Slot
6869
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus
6970

7071
import Data.Map (Map)
72+
import Data.Sequence (Seq)
7173
import Data.Set (Set)
7274
import qualified Data.Set as S
7375

@@ -484,3 +486,25 @@ queryAccountState cOnwards =
484486
queryExpr $
485487
QueryInEra . QueryInShelleyBasedEra (convert cOnwards) $
486488
QueryAccountState
489+
490+
queryProposals
491+
:: forall era block point r
492+
. ConwayEraOnwards era
493+
-- Specify a set of Governance Action IDs to filter the proposals. When this set is
494+
-- empty, all the proposals considered for ratification will be returned.
495+
-> Set (L.GovActionId L.StandardCrypto)
496+
-> LocalStateQueryExpr
497+
block
498+
point
499+
QueryInMode
500+
r
501+
IO
502+
( Either
503+
UnsupportedNtcVersionError
504+
(Either EraMismatch (Seq (L.GovActionState (ShelleyLedgerEra era))))
505+
)
506+
queryProposals cOnwards govActionIds = do
507+
let sbe = convert cOnwards
508+
queryExpr $
509+
QueryInEra . QueryInShelleyBasedEra sbe $
510+
QueryProposals govActionIds

cardano-api/internal/Cardano/Api/ReexposeLedger.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ module Cardano.Api.ReexposeLedger
7979
, GovAction (..)
8080
, GovActionId (..)
8181
, GovActionIx (..)
82+
, GovActionState
8283
, Vote (..)
8384
, Voter (..)
8485
, VotingProcedure (..)
@@ -209,8 +210,8 @@ import Cardano.Ledger.Conway.Core (DRepVotingThresholds (..), PoolVoti
209210
dvtUpdateToConstitutionL)
210211
import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..))
211212
import Cardano.Ledger.Conway.Governance (Anchor (..), Committee (..), GovActionId (..),
212-
GovActionIx (..), GovState, ProposalProcedure (..), Vote (..), Voter (..),
213-
VotingProcedure (..), VotingProcedures (..))
213+
GovActionIx (..), GovActionState, GovState, ProposalProcedure (..), Vote (..),
214+
Voter (..), VotingProcedure (..), VotingProcedures (..))
214215
import Cardano.Ledger.Conway.PParams (UpgradeConwayPParams (..))
215216
import Cardano.Ledger.Conway.Scripts (ConwayPlutusPurpose (..))
216217
import Cardano.Ledger.Conway.TxCert (ConwayDelegCert (..), ConwayEraTxCert (..),

cardano-api/src/Cardano/Api.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ module Cardano.Api
996996
, queryDRepState
997997
, queryDRepStakeDistribution
998998
, querySPOStakeDistribution
999+
, queryProposals
9991000
, queryCommitteeMembersState
10001001
, queryStakeVoteDelegatees
10011002

0 commit comments

Comments
 (0)