Skip to content

Commit

Permalink
Merge pull request #598 from IntersectMBO/query-spo-stake-distr-api
Browse files Browse the repository at this point in the history
Expose `querySPOStakeDistribution` query
  • Loading branch information
palas authored Jul 31, 2024
2 parents e4fdbbd + b82672e commit 74cb3b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cardano-api/internal/Cardano/Api/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ data QueryInShelleyBasedEra era result where
QueryDRepStakeDistr
:: Set (Ledger.DRep StandardCrypto)
-> QueryInShelleyBasedEra era (Map (Ledger.DRep StandardCrypto) L.Coin)
QuerySPOStakeDistr
:: Set (Ledger.KeyHash 'Ledger.StakePool StandardCrypto)
-> QueryInShelleyBasedEra era (Map (Ledger.KeyHash 'Ledger.StakePool Ledger.StandardCrypto) L.Coin)
QueryCommitteeMembersState
:: Set (Shelley.Credential Shelley.ColdCommitteeRole StandardCrypto)
-> Set (Shelley.Credential Shelley.HotCommitteeRole StandardCrypto)
Expand Down Expand Up @@ -322,6 +325,7 @@ instance NodeToClientVersionOf (QueryInShelleyBasedEra era result) where
nodeToClientVersionOf QueryGovState = NodeToClientV_16
nodeToClientVersionOf QueryDRepState{} = NodeToClientV_16
nodeToClientVersionOf QueryDRepStakeDistr{} = NodeToClientV_16
nodeToClientVersionOf QuerySPOStakeDistr{} = NodeToClientV_16
nodeToClientVersionOf QueryCommitteeMembersState{} = NodeToClientV_16
nodeToClientVersionOf QueryStakeVoteDelegatees{} = NodeToClientV_16

Expand Down Expand Up @@ -666,6 +670,13 @@ toConsensusQueryShelleyBased sbe = \case
)
(const $ Some (consensusQueryInEraInMode era (Consensus.GetDRepStakeDistr dreps)))
sbe
QuerySPOStakeDistr spos ->
caseShelleyToBabbageOrConwayEraOnwards
( const $
error "toConsensusQueryShelleyBased: QuerySPOStakeDistr is only available in the Conway era"
)
(const $ Some (consensusQueryInEraInMode era (Consensus.GetSPOStakeDistr spos)))
sbe
QueryCommitteeMembersState coldCreds hotCreds statuses ->
caseShelleyToBabbageOrConwayEraOnwards
( const $
Expand Down Expand Up @@ -958,6 +969,11 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' =
Consensus.GetDRepStakeDistr{} ->
r'
_ -> fromConsensusQueryResultMismatch
QuerySPOStakeDistr{} ->
case q' of
Consensus.GetSPOStakeDistr{} ->
r'
_ -> fromConsensusQueryResultMismatch
QueryCommitteeMembersState{} ->
case q' of
Consensus.GetCommitteeMembersState{} ->
Expand Down
20 changes: 20 additions & 0 deletions cardano-api/internal/Cardano/Api/Query/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Cardano.Api.Query.Expr
, L.CommitteeMembersState (..)
, queryCommitteeMembersState
, queryDRepStakeDistribution
, querySPOStakeDistribution
, queryDRepState
, queryGovState
, queryStakeVoteDelegatees
Expand Down Expand Up @@ -416,6 +417,25 @@ queryDRepStakeDistribution era dreps = do
let sbe = conwayEraOnwardsToShelleyBasedEra era
queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QueryDRepStakeDistr dreps

querySPOStakeDistribution
:: ()
=> ConwayEraOnwards era
-> Set (L.KeyHash 'L.StakePool L.StandardCrypto)
-- ^ An empty SPO key hash set means that distributions for all SPOs will be returned
-> LocalStateQueryExpr
block
point
QueryInMode
r
IO
( Either
UnsupportedNtcVersionError
(Either EraMismatch (Map (L.KeyHash 'L.StakePool L.StandardCrypto) L.Coin))
)
querySPOStakeDistribution era spos = do
let sbe = conwayEraOnwardsToShelleyBasedEra era
queryExpr $ QueryInEra $ QueryInShelleyBasedEra sbe $ QuerySPOStakeDistr spos

-- | Returns info about committee members filtered by: cold credentials, hot credentials and statuses.
-- If empty sets are passed as filters, then no filtering is done.
queryCommitteeMembersState
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 @@ -970,6 +970,7 @@ module Cardano.Api
, queryGovState
, queryDRepState
, queryDRepStakeDistribution
, querySPOStakeDistribution
, queryCommitteeMembersState
, queryStakeVoteDelegatees

Expand Down

0 comments on commit 74cb3b8

Please sign in to comment.