Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose querySPOStakeDistribution query #598

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading