Skip to content

Commit 8c15145

Browse files
authored
Merge pull request #773 from IntersectMBO/js/10-3-queries
Integrate new Consensus queries for 10.3
2 parents de211ca + ab24702 commit 8c15145

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

cardano-api/src/Cardano/Api.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,8 @@ module Cardano.Api
10391039
, queryProposals
10401040
, queryCommitteeMembersState
10411041
, queryStakeVoteDelegatees
1042+
, queryStakePoolDefaultVote
1043+
, queryLedgerConfig
10421044

10431045
-- ** Committee State Query
10441046
, MemberStatus (..)

cardano-api/src/Cardano/Api/Internal/Query.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ data QueryInMode result where
149149
:: QueryInMode (WithOrigin BlockNo)
150150
QueryChainPoint
151151
:: QueryInMode ChainPoint
152+
QueryLedgerConfig
153+
:: QueryInMode (Consensus.CardanoLedgerConfig StandardCrypto)
152154

153155
instance NodeToClientVersionOf (QueryInMode result) where
154156
nodeToClientVersionOf = \case
@@ -158,6 +160,7 @@ instance NodeToClientVersionOf (QueryInMode result) where
158160
QuerySystemStart -> NodeToClientV_16
159161
QueryChainBlockNo -> NodeToClientV_16
160162
QueryChainPoint -> NodeToClientV_16
163+
QueryLedgerConfig -> NodeToClientV_20
161164

162165
data EraHistory where
163166
EraHistory
@@ -298,6 +301,9 @@ data QueryInShelleyBasedEra era result where
298301
-> QueryInShelleyBasedEra era (Seq (L.GovActionState (ShelleyLedgerEra era)))
299302
QueryLedgerPeerSnapshot
300303
:: QueryInShelleyBasedEra era (Serialised LedgerPeerSnapshot)
304+
QueryStakePoolDefaultVote
305+
:: Ledger.KeyHash 'Ledger.StakePool
306+
-> QueryInShelleyBasedEra era L.DefaultVote
301307

302308
-- | Mapping for queries in Shelley-based eras returning minimal node-to-client protocol versions. More
303309
-- information about queries versioning can be found:
@@ -333,6 +339,7 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where
333339
nodeToClientVersionOf QueryRatifyState{} = NodeToClientV_17
334340
nodeToClientVersionOf QueryFuturePParams{} = NodeToClientV_18
335341
nodeToClientVersionOf QueryLedgerPeerSnapshot = NodeToClientV_19
342+
nodeToClientVersionOf QueryStakePoolDefaultVote{} = NodeToClientV_20
336343

337344
deriving instance Show (QueryInShelleyBasedEra era result)
338345

@@ -557,6 +564,7 @@ toConsensusQuery (QueryInEra QueryByronUpdateState) =
557564
Consensus.GetUpdateInterfaceState
558565
toConsensusQuery (QueryInEra (QueryInShelleyBasedEra sbe q)) =
559566
shelleyBasedEraConstraints sbe $ toConsensusQueryShelleyBased sbe q
567+
toConsensusQuery QueryLedgerConfig = Some Consensus.GetLedgerConfig
560568

561569
toConsensusQueryShelleyBased
562570
:: forall era protocol block result
@@ -709,6 +717,16 @@ toConsensusQueryShelleyBased sbe = \case
709717
sbe
710718
QueryLedgerPeerSnapshot ->
711719
Some (consensusQueryInEraInMode era (Consensus.GetCBOR Consensus.GetBigLedgerPeerSnapshot))
720+
QueryStakePoolDefaultVote govActs ->
721+
caseShelleyToBabbageOrConwayEraOnwards
722+
( const $
723+
error "toConsensusQueryShelleyBased: QueryStakePoolDefaultVote is only available in the Conway era"
724+
)
725+
( const $
726+
Some
727+
(consensusQueryInEraInMode era (Consensus.QueryStakePoolDefaultVote govActs))
728+
)
729+
sbe
712730
where
713731
era = toCardanoEra sbe
714732

@@ -770,6 +788,11 @@ fromConsensusQueryResult QueryCurrentEra q' r' =
770788
Consensus.BlockQuery (Consensus.QueryHardFork Consensus.GetCurrentEra) ->
771789
fromConsensusEraIndex r'
772790
_ -> fromConsensusQueryResultMismatch
791+
fromConsensusQueryResult QueryLedgerConfig q' r' =
792+
case q' of
793+
Consensus.GetLedgerConfig ->
794+
r'
795+
_ -> fromConsensusQueryResultMismatch
773796
fromConsensusQueryResult (QueryInEra QueryByronUpdateState) q' r' =
774797
case q' of
775798
Consensus.BlockQuery
@@ -1006,6 +1029,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' =
10061029
Consensus.GetCBOR Consensus.GetBigLedgerPeerSnapshot ->
10071030
r'
10081031
_ -> fromConsensusQueryResultMismatch
1032+
QueryStakePoolDefaultVote{} ->
1033+
case q' of
1034+
Consensus.QueryStakePoolDefaultVote{} ->
1035+
r'
1036+
_ -> fromConsensusQueryResultMismatch
10091037

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

cardano-api/src/Cardano/Api/Internal/Query/Expr.hs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module Cardano.Api.Internal.Query.Expr
3838
, queryFuturePParams
3939
, queryStakeVoteDelegatees
4040
, queryProposals
41+
, queryStakePoolDefaultVote
42+
, queryLedgerConfig
4143
)
4244
where
4345

@@ -67,6 +69,7 @@ import Cardano.Ledger.Hashes hiding (Hash)
6769
import Cardano.Ledger.Keys qualified as L
6870
import Cardano.Ledger.Shelley.LedgerState qualified as L
6971
import Cardano.Slotting.Slot
72+
import Ouroboros.Consensus.Cardano.Block qualified as Consensus
7073
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus
7174
import Ouroboros.Network.Block (Serialised)
7275
import Ouroboros.Network.PeerSelection.LedgerPeers (LedgerPeerSnapshot)
@@ -94,6 +97,21 @@ queryChainPoint
9497
queryChainPoint =
9598
queryExpr QueryChainPoint
9699

100+
queryLedgerConfig
101+
:: ()
102+
=> LocalStateQueryExpr
103+
block
104+
point
105+
QueryInMode
106+
r
107+
IO
108+
( Either
109+
UnsupportedNtcVersionError
110+
(Consensus.CardanoLedgerConfig Ledger.StandardCrypto)
111+
)
112+
queryLedgerConfig =
113+
queryExpr QueryLedgerConfig
114+
97115
queryCurrentEra
98116
:: ()
99117
=> LocalStateQueryExpr block point QueryInMode r IO (Either UnsupportedNtcVersionError AnyCardanoEra)
@@ -536,3 +554,23 @@ queryProposals cOnwards govActionIds = do
536554
queryExpr $
537555
QueryInEra . QueryInShelleyBasedEra sbe $
538556
QueryProposals govActionIds
557+
558+
queryStakePoolDefaultVote
559+
:: forall era block point r
560+
. ConwayEraOnwards era
561+
-> L.KeyHash 'L.StakePool
562+
-> LocalStateQueryExpr
563+
block
564+
point
565+
QueryInMode
566+
r
567+
IO
568+
( Either
569+
UnsupportedNtcVersionError
570+
(Either EraMismatch L.DefaultVote)
571+
)
572+
queryStakePoolDefaultVote cOnwards stakePools = do
573+
let sbe = convert cOnwards
574+
queryExpr $
575+
QueryInEra . QueryInShelleyBasedEra sbe $
576+
QueryStakePoolDefaultVote stakePools

0 commit comments

Comments
 (0)