{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.Ledger.Api.State.Query (
  -- * @GetFilteredDelegationsAndRewardAccounts@
  filterStakePoolDelegsAndRewards,
  queryStakePoolDelegsAndRewards,

  -- * @GetGovState@
  queryGovState,

  -- * @GetConstitution@
  queryConstitution,

  -- * @GetConstitutionHash@
  queryConstitutionHash,

  -- * @GetDRepState@
  queryDRepState,

  -- * @GetDRepStakeDistr@
  queryDRepStakeDistr,

  -- * @GetRegisteredDRepStakeDistr@
  queryRegisteredDRepStakeDistr,

  -- * @GetSPOStakeDistr@
  querySPOStakeDistr,

  -- * @GetCommitteeState@
  queryCommitteeState,

  -- * @GetCommitteeMembersState@
  queryCommitteeMembersState,

  -- * @GetChainAccountState@
  queryChainAccountState,
  CommitteeMemberState (..),
  CommitteeMembersState (..),
  HotCredAuthStatus (..),
  MemberStatus (..),
  NextEpochChange (..),

  -- * @GetCurrentPParams@
  queryCurrentPParams,

  -- * @GetFuturePParams@
  queryFuturePParams,

  -- * @GetProposals@
  queryProposals,

  -- * @GetRatifyState@
  queryRatifyState,

  -- * @GetStakePoolDefaultVote
  queryStakePoolDefaultVote,
  DefaultVote (..),

  -- * For testing
  getNextEpochCommitteeMembers,
) where

import Cardano.Ledger.Api.State.Query.CommitteeMembersState (
  CommitteeMemberState (..),
  CommitteeMembersState (..),
  HotCredAuthStatus (..),
  MemberStatus (..),
  NextEpochChange (..),
 )
import Cardano.Ledger.BaseTypes (EpochNo, strictMaybeToMaybe)
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Compactible (fromCompact)
import Cardano.Ledger.Conway.Governance (
  Committee (committeeMembers),
  Constitution (constitutionAnchor),
  ConwayEraGov (..),
  DRepPulser (..),
  DRepPulsingState (..),
  DefaultVote (..),
  GovActionId,
  GovActionState (..),
  PulsingSnapshot,
  RatifyState,
  committeeThresholdL,
  defaultStakePoolVote,
  ensCommitteeL,
  finishDRepPulser,
  proposalsDeposits,
  psDRepDistr,
  psPoolDistr,
  psProposalsL,
  rsEnactStateL,
 )
import Cardano.Ledger.Conway.Rules (updateDormantDRepExpiry)
import Cardano.Ledger.Conway.State (
  ConwayEraCertState (..),
  vsCommitteeStateL,
  vsDRepsL,
 )
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.State
import Cardano.Ledger.UMap (
  StakeCredentials (scRewards, scSPools),
  UMap,
  dRepMap,
  domRestrictedStakeCredentials,
 )
import Control.Monad (guard)
import Data.Foldable (foldMap')
import Data.Map (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe, isJust)
import Data.Sequence (Seq (..))
import qualified Data.Sequence as Seq
import Data.Sequence.Strict (StrictSeq (..))
import Data.Set (Set)
import qualified Data.Set as Set
import Lens.Micro
import Lens.Micro.Extras (view)

-- | Filter out stake pool delegations and rewards for a set of stake credentials
filterStakePoolDelegsAndRewards ::
  UMap ->
  Set (Credential 'Staking) ->
  (Map (Credential 'Staking) (KeyHash 'StakePool), Map (Credential 'Staking) Coin)
filterStakePoolDelegsAndRewards :: UMap
-> Set (Credential 'Staking)
-> (Map (Credential 'Staking) (KeyHash 'StakePool),
    Map (Credential 'Staking) Coin)
filterStakePoolDelegsAndRewards UMap
umap Set (Credential 'Staking)
creds =
  (StakeCredentials -> Map (Credential 'Staking) (KeyHash 'StakePool)
scSPools StakeCredentials
stakeCredentials, StakeCredentials -> Map (Credential 'Staking) Coin
scRewards StakeCredentials
stakeCredentials)
  where
    stakeCredentials :: StakeCredentials
stakeCredentials = Set (Credential 'Staking) -> UMap -> StakeCredentials
domRestrictedStakeCredentials Set (Credential 'Staking)
creds UMap
umap

-- | Uses `filterStakePoolDelegsAndRewards` to get the same information from the `NewEpochState`
--
-- Implementation for @GetFilteredDelegationsAndRewardAccounts@ query.
queryStakePoolDelegsAndRewards ::
  EraCertState era =>
  NewEpochState era ->
  Set (Credential 'Staking) ->
  ( Map (Credential 'Staking) (KeyHash 'StakePool)
  , Map (Credential 'Staking) Coin
  )
queryStakePoolDelegsAndRewards :: forall era.
EraCertState era =>
NewEpochState era
-> Set (Credential 'Staking)
-> (Map (Credential 'Staking) (KeyHash 'StakePool),
    Map (Credential 'Staking) Coin)
queryStakePoolDelegsAndRewards NewEpochState era
nes = UMap
-> Set (Credential 'Staking)
-> (Map (Credential 'Staking) (KeyHash 'StakePool),
    Map (Credential 'Staking) Coin)
filterStakePoolDelegsAndRewards (DState era -> UMap
forall era. DState era -> UMap
dsUnified (NewEpochState era -> DState era
forall era. EraCertState era => NewEpochState era -> DState era
getDState NewEpochState era
nes))

getDState :: EraCertState era => NewEpochState era -> DState era
getDState :: forall era. EraCertState era => NewEpochState era -> DState era
getDState NewEpochState era
nes = NewEpochState era
nes NewEpochState era
-> Getting (DState era) (NewEpochState era) (DState era)
-> DState era
forall s a. s -> Getting a s a -> a
^. (EpochState era -> Const (DState era) (EpochState era))
-> NewEpochState era -> Const (DState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEsL ((EpochState era -> Const (DState era) (EpochState era))
 -> NewEpochState era -> Const (DState era) (NewEpochState era))
-> ((DState era -> Const (DState era) (DState era))
    -> EpochState era -> Const (DState era) (EpochState era))
-> Getting (DState era) (NewEpochState era) (DState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era -> Const (DState era) (LedgerState era))
-> EpochState era -> Const (DState era) (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL ((LedgerState era -> Const (DState era) (LedgerState era))
 -> EpochState era -> Const (DState era) (EpochState era))
-> ((DState era -> Const (DState era) (DState era))
    -> LedgerState era -> Const (DState era) (LedgerState era))
-> (DState era -> Const (DState era) (DState era))
-> EpochState era
-> Const (DState era) (EpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CertState era -> Const (DState era) (CertState era))
-> LedgerState era -> Const (DState era) (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(CertState era -> f (CertState era))
-> LedgerState era -> f (LedgerState era)
lsCertStateL ((CertState era -> Const (DState era) (CertState era))
 -> LedgerState era -> Const (DState era) (LedgerState era))
-> ((DState era -> Const (DState era) (DState era))
    -> CertState era -> Const (DState era) (CertState era))
-> (DState era -> Const (DState era) (DState era))
-> LedgerState era
-> Const (DState era) (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DState era -> Const (DState era) (DState era))
-> CertState era -> Const (DState era) (CertState era)
forall era. EraCertState era => Lens' (CertState era) (DState era)
Lens' (CertState era) (DState era)
certDStateL

queryConstitution :: ConwayEraGov era => NewEpochState era -> Constitution era
queryConstitution :: forall era.
ConwayEraGov era =>
NewEpochState era -> Constitution era
queryConstitution = (GovState era
-> Getting (Constitution era) (GovState era) (Constitution era)
-> Constitution era
forall s a. s -> Getting a s a -> a
^. Getting (Constitution era) (GovState era) (Constitution era)
forall era.
ConwayEraGov era =>
Lens' (GovState era) (Constitution era)
Lens' (GovState era) (Constitution era)
constitutionGovStateL) (GovState era -> Constitution era)
-> (NewEpochState era -> GovState era)
-> NewEpochState era
-> Constitution era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NewEpochState era -> GovState era
forall era. NewEpochState era -> GovState era
queryGovState

queryConstitutionHash ::
  ConwayEraGov era =>
  NewEpochState era ->
  SafeHash AnchorData
queryConstitutionHash :: forall era.
ConwayEraGov era =>
NewEpochState era -> SafeHash AnchorData
queryConstitutionHash NewEpochState era
nes =
  Anchor -> SafeHash AnchorData
anchorDataHash (Anchor -> SafeHash AnchorData)
-> (Constitution era -> Anchor)
-> Constitution era
-> SafeHash AnchorData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Constitution era -> Anchor
forall era. Constitution era -> Anchor
constitutionAnchor (Constitution era -> SafeHash AnchorData)
-> Constitution era -> SafeHash AnchorData
forall a b. (a -> b) -> a -> b
$ NewEpochState era -> Constitution era
forall era.
ConwayEraGov era =>
NewEpochState era -> Constitution era
queryConstitution NewEpochState era
nes

-- | This query returns all of the state related to governance
queryGovState :: NewEpochState era -> GovState era
queryGovState :: forall era. NewEpochState era -> GovState era
queryGovState NewEpochState era
nes = NewEpochState era
nes NewEpochState era
-> Getting (GovState era) (NewEpochState era) (GovState era)
-> GovState era
forall s a. s -> Getting a s a -> a
^. (EpochState era -> Const (GovState era) (EpochState era))
-> NewEpochState era -> Const (GovState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEpochStateL ((EpochState era -> Const (GovState era) (EpochState era))
 -> NewEpochState era -> Const (GovState era) (NewEpochState era))
-> ((GovState era -> Const (GovState era) (GovState era))
    -> EpochState era -> Const (GovState era) (EpochState era))
-> Getting (GovState era) (NewEpochState era) (GovState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GovState era -> Const (GovState era) (GovState era))
-> EpochState era -> Const (GovState era) (EpochState era)
forall era (f :: * -> *).
Functor f =>
(GovState era -> f (GovState era))
-> EpochState era -> f (EpochState era)
epochStateGovStateL

-- | Query DRep state.
queryDRepState ::
  ConwayEraCertState era =>
  NewEpochState era ->
  -- | Specify a set of DRep credentials whose state should be returned. When this set is
  -- empty, states for all of the DReps will be returned.
  Set (Credential 'DRepRole) ->
  Map (Credential 'DRepRole) DRepState
queryDRepState :: forall era.
ConwayEraCertState era =>
NewEpochState era
-> Set (Credential 'DRepRole)
-> Map (Credential 'DRepRole) DRepState
queryDRepState NewEpochState era
nes Set (Credential 'DRepRole)
creds
  | Set (Credential 'DRepRole) -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set (Credential 'DRepRole)
creds = VState era -> VState era
updateDormantDRepExpiry' VState era
vState VState era
-> Getting
     (Map (Credential 'DRepRole) DRepState)
     (VState era)
     (Map (Credential 'DRepRole) DRepState)
-> Map (Credential 'DRepRole) DRepState
forall s a. s -> Getting a s a -> a
^. Getting
  (Map (Credential 'DRepRole) DRepState)
  (VState era)
  (Map (Credential 'DRepRole) DRepState)
forall era (f :: * -> *).
Functor f =>
(Map (Credential 'DRepRole) DRepState
 -> f (Map (Credential 'DRepRole) DRepState))
-> VState era -> f (VState era)
vsDRepsL
  | Bool
otherwise = VState era -> VState era
updateDormantDRepExpiry' VState era
vStateFiltered VState era
-> Getting
     (Map (Credential 'DRepRole) DRepState)
     (VState era)
     (Map (Credential 'DRepRole) DRepState)
-> Map (Credential 'DRepRole) DRepState
forall s a. s -> Getting a s a -> a
^. Getting
  (Map (Credential 'DRepRole) DRepState)
  (VState era)
  (Map (Credential 'DRepRole) DRepState)
forall era (f :: * -> *).
Functor f =>
(Map (Credential 'DRepRole) DRepState
 -> f (Map (Credential 'DRepRole) DRepState))
-> VState era -> f (VState era)
vsDRepsL
  where
    vStateFiltered :: VState era
vStateFiltered = VState era
vState VState era -> (VState era -> VState era) -> VState era
forall a b. a -> (a -> b) -> b
& (Map (Credential 'DRepRole) DRepState
 -> Identity (Map (Credential 'DRepRole) DRepState))
-> VState era -> Identity (VState era)
forall era (f :: * -> *).
Functor f =>
(Map (Credential 'DRepRole) DRepState
 -> f (Map (Credential 'DRepRole) DRepState))
-> VState era -> f (VState era)
vsDRepsL ((Map (Credential 'DRepRole) DRepState
  -> Identity (Map (Credential 'DRepRole) DRepState))
 -> VState era -> Identity (VState era))
-> (Map (Credential 'DRepRole) DRepState
    -> Map (Credential 'DRepRole) DRepState)
-> VState era
-> VState era
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Map (Credential 'DRepRole) DRepState
-> Set (Credential 'DRepRole)
-> Map (Credential 'DRepRole) DRepState
forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'DRepRole)
creds)
    vState :: VState era
vState = NewEpochState era
nes NewEpochState era
-> Getting (VState era) (NewEpochState era) (VState era)
-> VState era
forall s a. s -> Getting a s a -> a
^. (EpochState era -> Const (VState era) (EpochState era))
-> NewEpochState era -> Const (VState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEsL ((EpochState era -> Const (VState era) (EpochState era))
 -> NewEpochState era -> Const (VState era) (NewEpochState era))
-> ((VState era -> Const (VState era) (VState era))
    -> EpochState era -> Const (VState era) (EpochState era))
-> Getting (VState era) (NewEpochState era) (VState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era -> Const (VState era) (LedgerState era))
-> EpochState era -> Const (VState era) (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL ((LedgerState era -> Const (VState era) (LedgerState era))
 -> EpochState era -> Const (VState era) (EpochState era))
-> ((VState era -> Const (VState era) (VState era))
    -> LedgerState era -> Const (VState era) (LedgerState era))
-> (VState era -> Const (VState era) (VState era))
-> EpochState era
-> Const (VState era) (EpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CertState era -> Const (VState era) (CertState era))
-> LedgerState era -> Const (VState era) (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(CertState era -> f (CertState era))
-> LedgerState era -> f (LedgerState era)
lsCertStateL ((CertState era -> Const (VState era) (CertState era))
 -> LedgerState era -> Const (VState era) (LedgerState era))
-> ((VState era -> Const (VState era) (VState era))
    -> CertState era -> Const (VState era) (CertState era))
-> (VState era -> Const (VState era) (VState era))
-> LedgerState era
-> Const (VState era) (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VState era -> Const (VState era) (VState era))
-> CertState era -> Const (VState era) (CertState era)
forall era.
ConwayEraCertState era =>
Lens' (CertState era) (VState era)
Lens' (CertState era) (VState era)
certVStateL
    updateDormantDRepExpiry' :: VState era -> VState era
updateDormantDRepExpiry' = EpochNo -> VState era -> VState era
forall era. EpochNo -> VState era -> VState era
updateDormantDRepExpiry (NewEpochState era
nes NewEpochState era
-> Getting EpochNo (NewEpochState era) EpochNo -> EpochNo
forall s a. s -> Getting a s a -> a
^. Getting EpochNo (NewEpochState era) EpochNo
forall era (f :: * -> *).
Functor f =>
(EpochNo -> f EpochNo)
-> NewEpochState era -> f (NewEpochState era)
nesELL)

-- | Query DRep stake distribution. Note that this can be an expensive query because there
-- is a chance that current distribution has not been fully computed yet.
queryDRepStakeDistr ::
  ConwayEraGov era =>
  NewEpochState era ->
  -- | Specify DRep Ids whose stake distribution should be returned. When this set is
  -- empty, distributions for all of the DReps will be returned.
  Set DRep ->
  Map DRep Coin
queryDRepStakeDistr :: forall era.
ConwayEraGov era =>
NewEpochState era -> Set DRep -> Map DRep Coin
queryDRepStakeDistr NewEpochState era
nes Set DRep
creds
  | Set DRep -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set DRep
creds = (CompactForm Coin -> Coin)
-> Map DRep (CompactForm Coin) -> Map DRep Coin
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map CompactForm Coin -> Coin
forall a. Compactible a => CompactForm a -> a
fromCompact Map DRep (CompactForm Coin)
distr
  | Bool
otherwise = (CompactForm Coin -> Coin)
-> Map DRep (CompactForm Coin) -> Map DRep Coin
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map CompactForm Coin -> Coin
forall a. Compactible a => CompactForm a -> a
fromCompact (Map DRep (CompactForm Coin) -> Map DRep Coin)
-> Map DRep (CompactForm Coin) -> Map DRep Coin
forall a b. (a -> b) -> a -> b
$ Map DRep (CompactForm Coin)
distr Map DRep (CompactForm Coin)
-> Set DRep -> Map DRep (CompactForm Coin)
forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set DRep
creds
  where
    distr :: Map DRep (CompactForm Coin)
distr = PulsingSnapshot era -> Map DRep (CompactForm Coin)
forall era. PulsingSnapshot era -> Map DRep (CompactForm Coin)
psDRepDistr (PulsingSnapshot era -> Map DRep (CompactForm Coin))
-> ((PulsingSnapshot era, RatifyState era) -> PulsingSnapshot era)
-> (PulsingSnapshot era, RatifyState era)
-> Map DRep (CompactForm Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PulsingSnapshot era, RatifyState era) -> PulsingSnapshot era
forall a b. (a, b) -> a
fst ((PulsingSnapshot era, RatifyState era)
 -> Map DRep (CompactForm Coin))
-> (PulsingSnapshot era, RatifyState era)
-> Map DRep (CompactForm Coin)
forall a b. (a -> b) -> a -> b
$ NewEpochState era -> (PulsingSnapshot era, RatifyState era)
forall era.
ConwayEraGov era =>
NewEpochState era -> (PulsingSnapshot era, RatifyState era)
finishedPulserState NewEpochState era
nes

-- | Query the stake distribution of the registered DReps. This does not
-- include the @AlwaysAbstain@ and @NoConfidence@ DReps.
queryRegisteredDRepStakeDistr ::
  (ConwayEraGov era, ConwayEraCertState era) =>
  NewEpochState era ->
  -- | Specify DRep Ids whose stake distribution should be returned. When this set is
  -- empty, distributions for all of the registered DReps will be returned.
  Set (Credential 'DRepRole) ->
  Map (Credential 'DRepRole) Coin
queryRegisteredDRepStakeDistr :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
NewEpochState era
-> Set (Credential 'DRepRole) -> Map (Credential 'DRepRole) Coin
queryRegisteredDRepStakeDistr NewEpochState era
nes Set (Credential 'DRepRole)
creds =
  (Map (Credential 'DRepRole) Coin
 -> Credential 'DRepRole
 -> DRepState
 -> Map (Credential 'DRepRole) Coin)
-> Map (Credential 'DRepRole) Coin
-> Map (Credential 'DRepRole) DRepState
-> Map (Credential 'DRepRole) Coin
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' Map (Credential 'DRepRole) Coin
-> Credential 'DRepRole
-> DRepState
-> Map (Credential 'DRepRole) Coin
computeDistr Map (Credential 'DRepRole) Coin
forall a. Monoid a => a
mempty Map (Credential 'DRepRole) DRepState
selectedDReps
  where
    selectedDReps :: Map (Credential 'DRepRole) DRepState
selectedDReps
      | Set (Credential 'DRepRole) -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set (Credential 'DRepRole)
creds = Map (Credential 'DRepRole) DRepState
registeredDReps
      | Bool
otherwise = Map (Credential 'DRepRole) DRepState
registeredDReps Map (Credential 'DRepRole) DRepState
-> Set (Credential 'DRepRole)
-> Map (Credential 'DRepRole) DRepState
forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (Credential 'DRepRole)
creds
    registeredDReps :: Map (Credential 'DRepRole) DRepState
registeredDReps = NewEpochState era
nes NewEpochState era
-> Getting
     (Map (Credential 'DRepRole) DRepState)
     (NewEpochState era)
     (Map (Credential 'DRepRole) DRepState)
-> Map (Credential 'DRepRole) DRepState
forall s a. s -> Getting a s a -> a
^. (EpochState era
 -> Const (Map (Credential 'DRepRole) DRepState) (EpochState era))
-> NewEpochState era
-> Const (Map (Credential 'DRepRole) DRepState) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEsL ((EpochState era
  -> Const (Map (Credential 'DRepRole) DRepState) (EpochState era))
 -> NewEpochState era
 -> Const
      (Map (Credential 'DRepRole) DRepState) (NewEpochState era))
-> ((Map (Credential 'DRepRole) DRepState
     -> Const
          (Map (Credential 'DRepRole) DRepState)
          (Map (Credential 'DRepRole) DRepState))
    -> EpochState era
    -> Const (Map (Credential 'DRepRole) DRepState) (EpochState era))
-> Getting
     (Map (Credential 'DRepRole) DRepState)
     (NewEpochState era)
     (Map (Credential 'DRepRole) DRepState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era
 -> Const (Map (Credential 'DRepRole) DRepState) (LedgerState era))
-> EpochState era
-> Const (Map (Credential 'DRepRole) DRepState) (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL ((LedgerState era
  -> Const (Map (Credential 'DRepRole) DRepState) (LedgerState era))
 -> EpochState era
 -> Const (Map (Credential 'DRepRole) DRepState) (EpochState era))
-> ((Map (Credential 'DRepRole) DRepState
     -> Const
          (Map (Credential 'DRepRole) DRepState)
          (Map (Credential 'DRepRole) DRepState))
    -> LedgerState era
    -> Const (Map (Credential 'DRepRole) DRepState) (LedgerState era))
-> (Map (Credential 'DRepRole) DRepState
    -> Const
         (Map (Credential 'DRepRole) DRepState)
         (Map (Credential 'DRepRole) DRepState))
-> EpochState era
-> Const (Map (Credential 'DRepRole) DRepState) (EpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CertState era
 -> Const (Map (Credential 'DRepRole) DRepState) (CertState era))
-> LedgerState era
-> Const (Map (Credential 'DRepRole) DRepState) (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(CertState era -> f (CertState era))
-> LedgerState era -> f (LedgerState era)
lsCertStateL ((CertState era
  -> Const (Map (Credential 'DRepRole) DRepState) (CertState era))
 -> LedgerState era
 -> Const (Map (Credential 'DRepRole) DRepState) (LedgerState era))
-> ((Map (Credential 'DRepRole) DRepState
     -> Const
          (Map (Credential 'DRepRole) DRepState)
          (Map (Credential 'DRepRole) DRepState))
    -> CertState era
    -> Const (Map (Credential 'DRepRole) DRepState) (CertState era))
-> (Map (Credential 'DRepRole) DRepState
    -> Const
         (Map (Credential 'DRepRole) DRepState)
         (Map (Credential 'DRepRole) DRepState))
-> LedgerState era
-> Const (Map (Credential 'DRepRole) DRepState) (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VState era
 -> Const (Map (Credential 'DRepRole) DRepState) (VState era))
-> CertState era
-> Const (Map (Credential 'DRepRole) DRepState) (CertState era)
forall era.
ConwayEraCertState era =>
Lens' (CertState era) (VState era)
Lens' (CertState era) (VState era)
certVStateL ((VState era
  -> Const (Map (Credential 'DRepRole) DRepState) (VState era))
 -> CertState era
 -> Const (Map (Credential 'DRepRole) DRepState) (CertState era))
-> ((Map (Credential 'DRepRole) DRepState
     -> Const
          (Map (Credential 'DRepRole) DRepState)
          (Map (Credential 'DRepRole) DRepState))
    -> VState era
    -> Const (Map (Credential 'DRepRole) DRepState) (VState era))
-> (Map (Credential 'DRepRole) DRepState
    -> Const
         (Map (Credential 'DRepRole) DRepState)
         (Map (Credential 'DRepRole) DRepState))
-> CertState era
-> Const (Map (Credential 'DRepRole) DRepState) (CertState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential 'DRepRole) DRepState
 -> Const
      (Map (Credential 'DRepRole) DRepState)
      (Map (Credential 'DRepRole) DRepState))
-> VState era
-> Const (Map (Credential 'DRepRole) DRepState) (VState era)
forall era (f :: * -> *).
Functor f =>
(Map (Credential 'DRepRole) DRepState
 -> f (Map (Credential 'DRepRole) DRepState))
-> VState era -> f (VState era)
vsDRepsL
    computeDistr :: Map (Credential 'DRepRole) Coin
-> Credential 'DRepRole
-> DRepState
-> Map (Credential 'DRepRole) Coin
computeDistr Map (Credential 'DRepRole) Coin
distrAcc Credential 'DRepRole
dRepCred (DRepState {Set (Credential 'Staking)
StrictMaybe Anchor
Coin
EpochNo
drepExpiry :: EpochNo
drepAnchor :: StrictMaybe Anchor
drepDeposit :: Coin
drepDelegs :: Set (Credential 'Staking)
drepExpiry :: DRepState -> EpochNo
drepAnchor :: DRepState -> StrictMaybe Anchor
drepDeposit :: DRepState -> Coin
drepDelegs :: DRepState -> Set (Credential 'Staking)
..}) =
      Credential 'DRepRole
-> Coin
-> Map (Credential 'DRepRole) Coin
-> Map (Credential 'DRepRole) Coin
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Credential 'DRepRole
dRepCred (Set (Credential 'Staking) -> Coin
totalDelegations Set (Credential 'Staking)
drepDelegs) Map (Credential 'DRepRole) Coin
distrAcc
    totalDelegations :: Set (Credential 'Staking) -> Coin
totalDelegations =
      CompactForm Coin -> Coin
forall a. Compactible a => CompactForm a -> a
fromCompact (CompactForm Coin -> Coin)
-> (Set (Credential 'Staking) -> CompactForm Coin)
-> Set (Credential 'Staking)
-> Coin
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Credential 'Staking -> CompactForm Coin)
-> Set (Credential 'Staking) -> CompactForm Coin
forall m a. Monoid m => (a -> m) -> Set a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Credential 'Staking -> CompactForm Coin
stakeAndDeposits
    instantStake :: Map (Credential 'Staking) (CompactForm Coin)
instantStake = NewEpochState era
nes NewEpochState era
-> Getting
     (Map (Credential 'Staking) (CompactForm Coin))
     (NewEpochState era)
     (Map (Credential 'Staking) (CompactForm Coin))
-> Map (Credential 'Staking) (CompactForm Coin)
forall s a. s -> Getting a s a -> a
^. (InstantStake era
 -> Const
      (Map (Credential 'Staking) (CompactForm Coin)) (InstantStake era))
-> NewEpochState era
-> Const
     (Map (Credential 'Staking) (CompactForm Coin)) (NewEpochState era)
forall era. Lens' (NewEpochState era) (InstantStake era)
forall (t :: * -> *) era.
CanSetInstantStake t =>
Lens' (t era) (InstantStake era)
instantStakeL ((InstantStake era
  -> Const
       (Map (Credential 'Staking) (CompactForm Coin)) (InstantStake era))
 -> NewEpochState era
 -> Const
      (Map (Credential 'Staking) (CompactForm Coin)) (NewEpochState era))
-> ((Map (Credential 'Staking) (CompactForm Coin)
     -> Const
          (Map (Credential 'Staking) (CompactForm Coin))
          (Map (Credential 'Staking) (CompactForm Coin)))
    -> InstantStake era
    -> Const
         (Map (Credential 'Staking) (CompactForm Coin)) (InstantStake era))
-> Getting
     (Map (Credential 'Staking) (CompactForm Coin))
     (NewEpochState era)
     (Map (Credential 'Staking) (CompactForm Coin))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (Credential 'Staking) (CompactForm Coin)
 -> Const
      (Map (Credential 'Staking) (CompactForm Coin))
      (Map (Credential 'Staking) (CompactForm Coin)))
-> InstantStake era
-> Const
     (Map (Credential 'Staking) (CompactForm Coin)) (InstantStake era)
forall era.
EraStake era =>
Lens'
  (InstantStake era) (Map (Credential 'Staking) (CompactForm Coin))
Lens'
  (InstantStake era) (Map (Credential 'Staking) (CompactForm Coin))
instantStakeCredentialsL
    proposalDeposits :: Map (Credential 'Staking) (CompactForm Coin)
proposalDeposits = Proposals era -> Map (Credential 'Staking) (CompactForm Coin)
forall era.
Proposals era -> Map (Credential 'Staking) (CompactForm Coin)
proposalsDeposits (Proposals era -> Map (Credential 'Staking) (CompactForm Coin))
-> Proposals era -> Map (Credential 'Staking) (CompactForm Coin)
forall a b. (a -> b) -> a -> b
$ NewEpochState era
nes NewEpochState era
-> Getting (Proposals era) (NewEpochState era) (Proposals era)
-> Proposals era
forall s a. s -> Getting a s a -> a
^. (GovState era -> Const (Proposals era) (GovState era))
-> NewEpochState era -> Const (Proposals era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(GovState era -> f (GovState era))
-> NewEpochState era -> f (NewEpochState era)
newEpochStateGovStateL ((GovState era -> Const (Proposals era) (GovState era))
 -> NewEpochState era -> Const (Proposals era) (NewEpochState era))
-> ((Proposals era -> Const (Proposals era) (Proposals era))
    -> GovState era -> Const (Proposals era) (GovState era))
-> Getting (Proposals era) (NewEpochState era) (Proposals era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Proposals era -> Const (Proposals era) (Proposals era))
-> GovState era -> Const (Proposals era) (GovState era)
forall era.
ConwayEraGov era =>
Lens' (GovState era) (Proposals era)
Lens' (GovState era) (Proposals era)
proposalsGovStateL
    stakeAndDeposits :: Credential 'Staking -> CompactForm Coin
stakeAndDeposits Credential 'Staking
stakeCred =
      CompactForm Coin -> Maybe (CompactForm Coin) -> CompactForm Coin
forall a. a -> Maybe a -> a
fromMaybe (Word64 -> CompactForm Coin
CompactCoin Word64
0) (Maybe (CompactForm Coin) -> CompactForm Coin)
-> Maybe (CompactForm Coin) -> CompactForm Coin
forall a b. (a -> b) -> a -> b
$
        Credential 'Staking
-> Map (Credential 'Staking) (CompactForm Coin)
-> Maybe (CompactForm Coin)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
stakeCred Map (Credential 'Staking) (CompactForm Coin)
instantStake Maybe (CompactForm Coin)
-> Maybe (CompactForm Coin) -> Maybe (CompactForm Coin)
forall a. Semigroup a => a -> a -> a
<> Credential 'Staking
-> Map (Credential 'Staking) (CompactForm Coin)
-> Maybe (CompactForm Coin)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'Staking
stakeCred Map (Credential 'Staking) (CompactForm Coin)
proposalDeposits

-- | Query pool stake distribution.
querySPOStakeDistr ::
  ConwayEraGov era =>
  NewEpochState era ->
  Set (KeyHash 'StakePool) ->
  -- | Specify pool key hashes whose stake distribution should be returned. When this set is
  -- empty, distributions for all of the pools will be returned.
  Map (KeyHash 'StakePool) Coin
querySPOStakeDistr :: forall era.
ConwayEraGov era =>
NewEpochState era
-> Set (KeyHash 'StakePool) -> Map (KeyHash 'StakePool) Coin
querySPOStakeDistr NewEpochState era
nes Set (KeyHash 'StakePool)
keys
  | Set (KeyHash 'StakePool) -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set (KeyHash 'StakePool)
keys = (CompactForm Coin -> Coin)
-> Map (KeyHash 'StakePool) (CompactForm Coin)
-> Map (KeyHash 'StakePool) Coin
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map CompactForm Coin -> Coin
forall a. Compactible a => CompactForm a -> a
fromCompact Map (KeyHash 'StakePool) (CompactForm Coin)
distr
  | Bool
otherwise = (CompactForm Coin -> Coin)
-> Map (KeyHash 'StakePool) (CompactForm Coin)
-> Map (KeyHash 'StakePool) Coin
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map CompactForm Coin -> Coin
forall a. Compactible a => CompactForm a -> a
fromCompact (Map (KeyHash 'StakePool) (CompactForm Coin)
 -> Map (KeyHash 'StakePool) Coin)
-> Map (KeyHash 'StakePool) (CompactForm Coin)
-> Map (KeyHash 'StakePool) Coin
forall a b. (a -> b) -> a -> b
$ Map (KeyHash 'StakePool) (CompactForm Coin)
distr Map (KeyHash 'StakePool) (CompactForm Coin)
-> Set (KeyHash 'StakePool)
-> Map (KeyHash 'StakePool) (CompactForm Coin)
forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set (KeyHash 'StakePool)
keys
  where
    distr :: Map (KeyHash 'StakePool) (CompactForm Coin)
distr = PulsingSnapshot era -> Map (KeyHash 'StakePool) (CompactForm Coin)
forall era.
PulsingSnapshot era -> Map (KeyHash 'StakePool) (CompactForm Coin)
psPoolDistr (PulsingSnapshot era
 -> Map (KeyHash 'StakePool) (CompactForm Coin))
-> ((PulsingSnapshot era, RatifyState era) -> PulsingSnapshot era)
-> (PulsingSnapshot era, RatifyState era)
-> Map (KeyHash 'StakePool) (CompactForm Coin)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PulsingSnapshot era, RatifyState era) -> PulsingSnapshot era
forall a b. (a, b) -> a
fst ((PulsingSnapshot era, RatifyState era)
 -> Map (KeyHash 'StakePool) (CompactForm Coin))
-> (PulsingSnapshot era, RatifyState era)
-> Map (KeyHash 'StakePool) (CompactForm Coin)
forall a b. (a -> b) -> a -> b
$ NewEpochState era -> (PulsingSnapshot era, RatifyState era)
forall era.
ConwayEraGov era =>
NewEpochState era -> (PulsingSnapshot era, RatifyState era)
finishedPulserState NewEpochState era
nes

-- | Query committee members
queryCommitteeState :: ConwayEraCertState era => NewEpochState era -> CommitteeState era
queryCommitteeState :: forall era.
ConwayEraCertState era =>
NewEpochState era -> CommitteeState era
queryCommitteeState NewEpochState era
nes = NewEpochState era
nes NewEpochState era
-> Getting
     (CommitteeState era) (NewEpochState era) (CommitteeState era)
-> CommitteeState era
forall s a. s -> Getting a s a -> a
^. (EpochState era -> Const (CommitteeState era) (EpochState era))
-> NewEpochState era
-> Const (CommitteeState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEsL ((EpochState era -> Const (CommitteeState era) (EpochState era))
 -> NewEpochState era
 -> Const (CommitteeState era) (NewEpochState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> EpochState era -> Const (CommitteeState era) (EpochState era))
-> Getting
     (CommitteeState era) (NewEpochState era) (CommitteeState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era -> Const (CommitteeState era) (LedgerState era))
-> EpochState era -> Const (CommitteeState era) (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL ((LedgerState era -> Const (CommitteeState era) (LedgerState era))
 -> EpochState era -> Const (CommitteeState era) (EpochState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> LedgerState era -> Const (CommitteeState era) (LedgerState era))
-> (CommitteeState era
    -> Const (CommitteeState era) (CommitteeState era))
-> EpochState era
-> Const (CommitteeState era) (EpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CertState era -> Const (CommitteeState era) (CertState era))
-> LedgerState era -> Const (CommitteeState era) (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(CertState era -> f (CertState era))
-> LedgerState era -> f (LedgerState era)
lsCertStateL ((CertState era -> Const (CommitteeState era) (CertState era))
 -> LedgerState era -> Const (CommitteeState era) (LedgerState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> CertState era -> Const (CommitteeState era) (CertState era))
-> (CommitteeState era
    -> Const (CommitteeState era) (CommitteeState era))
-> LedgerState era
-> Const (CommitteeState era) (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VState era -> Const (CommitteeState era) (VState era))
-> CertState era -> Const (CommitteeState era) (CertState era)
forall era.
ConwayEraCertState era =>
Lens' (CertState era) (VState era)
Lens' (CertState era) (VState era)
certVStateL ((VState era -> Const (CommitteeState era) (VState era))
 -> CertState era -> Const (CommitteeState era) (CertState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> VState era -> Const (CommitteeState era) (VState era))
-> (CommitteeState era
    -> Const (CommitteeState era) (CommitteeState era))
-> CertState era
-> Const (CommitteeState era) (CertState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CommitteeState era
 -> Const (CommitteeState era) (CommitteeState era))
-> VState era -> Const (CommitteeState era) (VState era)
forall era (f :: * -> *).
Functor f =>
(CommitteeState era -> f (CommitteeState era))
-> VState era -> f (VState era)
vsCommitteeStateL
{-# DEPRECATED queryCommitteeState "In favor of `queryCommitteeMembersState`" #-}

-- | Query committee members. Whenever the system is in No Confidence mode this query will
-- return `Nothing`.
queryCommitteeMembersState ::
  forall era.
  (ConwayEraGov era, ConwayEraCertState era) =>
  -- | filter by cold credentials (don't filter when empty)
  Set (Credential 'ColdCommitteeRole) ->
  -- | filter by hot credentials (don't filter when empty)
  Set (Credential 'HotCommitteeRole) ->
  -- | filter by status (don't filter when empty)
  -- (useful, for discovering, for example, only active members)
  Set MemberStatus ->
  NewEpochState era ->
  CommitteeMembersState
queryCommitteeMembersState :: forall era.
(ConwayEraGov era, ConwayEraCertState era) =>
Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'HotCommitteeRole)
-> Set MemberStatus
-> NewEpochState era
-> CommitteeMembersState
queryCommitteeMembersState Set (Credential 'ColdCommitteeRole)
coldCredsFilter Set (Credential 'HotCommitteeRole)
hotCredsFilter Set MemberStatus
statusFilter NewEpochState era
nes =
  let
    committee :: StrictMaybe (Committee era)
committee = NewEpochState era -> GovState era
forall era. NewEpochState era -> GovState era
queryGovState NewEpochState era
nes GovState era
-> Getting
     (StrictMaybe (Committee era))
     (GovState era)
     (StrictMaybe (Committee era))
-> StrictMaybe (Committee era)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictMaybe (Committee era))
  (GovState era)
  (StrictMaybe (Committee era))
forall era.
ConwayEraGov era =>
Lens' (GovState era) (StrictMaybe (Committee era))
Lens' (GovState era) (StrictMaybe (Committee era))
committeeGovStateL
    comMembers :: Map (Credential 'ColdCommitteeRole) EpochNo
comMembers = (Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo)
-> StrictMaybe (Committee era)
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall m a. Monoid m => (a -> m) -> StrictMaybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap' Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
forall era.
Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
committeeMembers StrictMaybe (Committee era)
committee
    nextComMembers :: Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers = NewEpochState era -> Map (Credential 'ColdCommitteeRole) EpochNo
forall era.
ConwayEraGov era =>
NewEpochState era -> Map (Credential 'ColdCommitteeRole) EpochNo
getNextEpochCommitteeMembers NewEpochState era
nes
    comStateMembers :: Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers =
      CommitteeState era
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
forall era.
CommitteeState era
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
csCommitteeCreds (CommitteeState era
 -> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization)
-> CommitteeState era
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
forall a b. (a -> b) -> a -> b
$
        NewEpochState era
nes NewEpochState era
-> Getting
     (CommitteeState era) (NewEpochState era) (CommitteeState era)
-> CommitteeState era
forall s a. s -> Getting a s a -> a
^. (EpochState era -> Const (CommitteeState era) (EpochState era))
-> NewEpochState era
-> Const (CommitteeState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEpochStateL ((EpochState era -> Const (CommitteeState era) (EpochState era))
 -> NewEpochState era
 -> Const (CommitteeState era) (NewEpochState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> EpochState era -> Const (CommitteeState era) (EpochState era))
-> Getting
     (CommitteeState era) (NewEpochState era) (CommitteeState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LedgerState era -> Const (CommitteeState era) (LedgerState era))
-> EpochState era -> Const (CommitteeState era) (EpochState era)
forall era (f :: * -> *).
Functor f =>
(LedgerState era -> f (LedgerState era))
-> EpochState era -> f (EpochState era)
esLStateL ((LedgerState era -> Const (CommitteeState era) (LedgerState era))
 -> EpochState era -> Const (CommitteeState era) (EpochState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> LedgerState era -> Const (CommitteeState era) (LedgerState era))
-> (CommitteeState era
    -> Const (CommitteeState era) (CommitteeState era))
-> EpochState era
-> Const (CommitteeState era) (EpochState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CertState era -> Const (CommitteeState era) (CertState era))
-> LedgerState era -> Const (CommitteeState era) (LedgerState era)
forall era (f :: * -> *).
Functor f =>
(CertState era -> f (CertState era))
-> LedgerState era -> f (LedgerState era)
lsCertStateL ((CertState era -> Const (CommitteeState era) (CertState era))
 -> LedgerState era -> Const (CommitteeState era) (LedgerState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> CertState era -> Const (CommitteeState era) (CertState era))
-> (CommitteeState era
    -> Const (CommitteeState era) (CommitteeState era))
-> LedgerState era
-> Const (CommitteeState era) (LedgerState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (VState era -> Const (CommitteeState era) (VState era))
-> CertState era -> Const (CommitteeState era) (CertState era)
forall era.
ConwayEraCertState era =>
Lens' (CertState era) (VState era)
Lens' (CertState era) (VState era)
certVStateL ((VState era -> Const (CommitteeState era) (VState era))
 -> CertState era -> Const (CommitteeState era) (CertState era))
-> ((CommitteeState era
     -> Const (CommitteeState era) (CommitteeState era))
    -> VState era -> Const (CommitteeState era) (VState era))
-> (CommitteeState era
    -> Const (CommitteeState era) (CommitteeState era))
-> CertState era
-> Const (CommitteeState era) (CertState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CommitteeState era
 -> Const (CommitteeState era) (CommitteeState era))
-> VState era -> Const (CommitteeState era) (VState era)
forall era (f :: * -> *).
Functor f =>
(CommitteeState era -> f (CommitteeState era))
-> VState era -> f (VState era)
vsCommitteeStateL

    withFilteredColdCreds :: Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
withFilteredColdCreds Set (Credential 'ColdCommitteeRole)
s
      | Set (Credential 'ColdCommitteeRole) -> Bool
forall a. Set a -> Bool
Set.null Set (Credential 'ColdCommitteeRole)
coldCredsFilter = Set (Credential 'ColdCommitteeRole)
s
      | Bool
otherwise = Set (Credential 'ColdCommitteeRole)
s Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set (Credential 'ColdCommitteeRole)
coldCredsFilter

    relevantColdKeys :: Set (Credential 'ColdCommitteeRole)
relevantColdKeys
      | Set MemberStatus -> Bool
forall a. Set a -> Bool
Set.null Set MemberStatus
statusFilter Bool -> Bool -> Bool
|| MemberStatus -> Set MemberStatus -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member MemberStatus
Unrecognized Set MemberStatus
statusFilter =
          Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
withFilteredColdCreds (Set (Credential 'ColdCommitteeRole)
 -> Set (Credential 'ColdCommitteeRole))
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a b. (a -> b) -> a -> b
$
            [Set (Credential 'ColdCommitteeRole)]
-> Set (Credential 'ColdCommitteeRole)
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
              [ Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
comMembers
              , Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers
              , Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers
              ]
      | Bool
otherwise = Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
withFilteredColdCreds (Set (Credential 'ColdCommitteeRole)
 -> Set (Credential 'ColdCommitteeRole))
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a b. (a -> b) -> a -> b
$ Map (Credential 'ColdCommitteeRole) EpochNo
-> Set (Credential 'ColdCommitteeRole)
forall k a. Map k a -> Set k
Map.keysSet Map (Credential 'ColdCommitteeRole) EpochNo
comMembers

    relevantHotKeys :: Set (Credential 'ColdCommitteeRole)
relevantHotKeys =
      [Credential 'ColdCommitteeRole]
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => [a] -> Set a
Set.fromList
        [ Credential 'ColdCommitteeRole
ck
        | (Credential 'ColdCommitteeRole
ck, CommitteeHotCredential Credential 'HotCommitteeRole
hk) <- Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> [(Credential 'ColdCommitteeRole, CommitteeAuthorization)]
forall k a. Map k a -> [(k, a)]
Map.toList Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers
        , Credential 'HotCommitteeRole
hk Credential 'HotCommitteeRole
-> Set (Credential 'HotCommitteeRole) -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set (Credential 'HotCommitteeRole)
hotCredsFilter
        ]

    relevant :: Set (Credential 'ColdCommitteeRole)
relevant
      | Set (Credential 'HotCommitteeRole) -> Bool
forall a. Set a -> Bool
Set.null Set (Credential 'HotCommitteeRole)
hotCredsFilter = Set (Credential 'ColdCommitteeRole)
relevantColdKeys
      | Bool
otherwise = Set (Credential 'ColdCommitteeRole)
relevantColdKeys Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
-> Set (Credential 'ColdCommitteeRole)
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set (Credential 'ColdCommitteeRole)
relevantHotKeys

    cms :: Map (Credential 'ColdCommitteeRole) CommitteeMemberState
cms = (Maybe CommitteeMemberState -> Maybe CommitteeMemberState)
-> Map (Credential 'ColdCommitteeRole) (Maybe CommitteeMemberState)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe Maybe CommitteeMemberState -> Maybe CommitteeMemberState
forall a. a -> a
id (Map (Credential 'ColdCommitteeRole) (Maybe CommitteeMemberState)
 -> Map (Credential 'ColdCommitteeRole) CommitteeMemberState)
-> Map (Credential 'ColdCommitteeRole) (Maybe CommitteeMemberState)
-> Map (Credential 'ColdCommitteeRole) CommitteeMemberState
forall a b. (a -> b) -> a -> b
$ (Credential 'ColdCommitteeRole -> Maybe CommitteeMemberState)
-> Set (Credential 'ColdCommitteeRole)
-> Map (Credential 'ColdCommitteeRole) (Maybe CommitteeMemberState)
forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet Credential 'ColdCommitteeRole -> Maybe CommitteeMemberState
mkMaybeMemberState Set (Credential 'ColdCommitteeRole)
relevant
    currentEpoch :: EpochNo
currentEpoch = NewEpochState era
nes NewEpochState era
-> Getting EpochNo (NewEpochState era) EpochNo -> EpochNo
forall s a. s -> Getting a s a -> a
^. Getting EpochNo (NewEpochState era) EpochNo
forall era (f :: * -> *).
Functor f =>
(EpochNo -> f EpochNo)
-> NewEpochState era -> f (NewEpochState era)
nesELL

    mkMaybeMemberState ::
      Credential 'ColdCommitteeRole ->
      Maybe CommitteeMemberState
    mkMaybeMemberState :: Credential 'ColdCommitteeRole -> Maybe CommitteeMemberState
mkMaybeMemberState Credential 'ColdCommitteeRole
coldCred = do
      let mbExpiry :: Maybe EpochNo
mbExpiry = Credential 'ColdCommitteeRole
-> Map (Credential 'ColdCommitteeRole) EpochNo -> Maybe EpochNo
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'ColdCommitteeRole
coldCred Map (Credential 'ColdCommitteeRole) EpochNo
comMembers
      let status :: MemberStatus
status = case Maybe EpochNo
mbExpiry of
            Maybe EpochNo
Nothing -> MemberStatus
Unrecognized
            Just EpochNo
expiry
              | EpochNo
currentEpoch EpochNo -> EpochNo -> Bool
forall a. Ord a => a -> a -> Bool
> EpochNo
expiry -> MemberStatus
Expired
              | Bool
otherwise -> MemberStatus
Active
      Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Set MemberStatus -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set MemberStatus
statusFilter Bool -> Bool -> Bool
|| MemberStatus
status MemberStatus -> Set MemberStatus -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set MemberStatus
statusFilter)
      let hkStatus :: HotCredAuthStatus
hkStatus =
            case Credential 'ColdCommitteeRole
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
-> Maybe CommitteeAuthorization
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'ColdCommitteeRole
coldCred Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
comStateMembers of
              Maybe CommitteeAuthorization
Nothing -> HotCredAuthStatus
MemberNotAuthorized
              Just (CommitteeMemberResigned StrictMaybe Anchor
anchor) -> Maybe Anchor -> HotCredAuthStatus
MemberResigned (StrictMaybe Anchor -> Maybe Anchor
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe StrictMaybe Anchor
anchor)
              Just (CommitteeHotCredential Credential 'HotCommitteeRole
hk) -> Credential 'HotCommitteeRole -> HotCredAuthStatus
MemberAuthorized Credential 'HotCommitteeRole
hk
      CommitteeMemberState -> Maybe CommitteeMemberState
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommitteeMemberState -> Maybe CommitteeMemberState)
-> CommitteeMemberState -> Maybe CommitteeMemberState
forall a b. (a -> b) -> a -> b
$ HotCredAuthStatus
-> MemberStatus
-> Maybe EpochNo
-> NextEpochChange
-> CommitteeMemberState
CommitteeMemberState HotCredAuthStatus
hkStatus MemberStatus
status Maybe EpochNo
mbExpiry (Credential 'ColdCommitteeRole -> NextEpochChange
nextEpochChange Credential 'ColdCommitteeRole
coldCred)

    nextEpochChange :: Credential 'ColdCommitteeRole -> NextEpochChange
    nextEpochChange :: Credential 'ColdCommitteeRole -> NextEpochChange
nextEpochChange Credential 'ColdCommitteeRole
ck
      | Bool -> Bool
not Bool
inCurrent Bool -> Bool -> Bool
&& Bool
inNext = NextEpochChange
ToBeEnacted
      | Bool -> Bool
not Bool
inNext = NextEpochChange
ToBeRemoved
      | Just EpochNo
curTerm <- Maybe EpochNo
lookupCurrent
      , Just EpochNo
nextTerm <- Maybe EpochNo
lookupNext
      , EpochNo
curTerm EpochNo -> EpochNo -> Bool
forall a. Eq a => a -> a -> Bool
/= EpochNo
nextTerm
      , -- if the term is adjusted such that it expires in the next epoch,
        -- we set it to ToBeExpired instead of TermAdjusted
        Bool -> Bool
not Bool
expiringNext =
          EpochNo -> NextEpochChange
TermAdjusted EpochNo
nextTerm
      | Bool
expiringCurrent Bool -> Bool -> Bool
|| Bool
expiringNext = NextEpochChange
ToBeExpired
      | Bool
otherwise = NextEpochChange
NoChangeExpected
      where
        lookupCurrent :: Maybe EpochNo
lookupCurrent = Credential 'ColdCommitteeRole
-> Map (Credential 'ColdCommitteeRole) EpochNo -> Maybe EpochNo
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'ColdCommitteeRole
ck Map (Credential 'ColdCommitteeRole) EpochNo
comMembers
        lookupNext :: Maybe EpochNo
lookupNext = Credential 'ColdCommitteeRole
-> Map (Credential 'ColdCommitteeRole) EpochNo -> Maybe EpochNo
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'ColdCommitteeRole
ck Map (Credential 'ColdCommitteeRole) EpochNo
nextComMembers
        inCurrent :: Bool
inCurrent = Maybe EpochNo -> Bool
forall a. Maybe a -> Bool
isJust Maybe EpochNo
lookupCurrent
        inNext :: Bool
inNext = Maybe EpochNo -> Bool
forall a. Maybe a -> Bool
isJust Maybe EpochNo
lookupNext
        expiringCurrent :: Bool
expiringCurrent = Maybe EpochNo
lookupCurrent Maybe EpochNo -> Maybe EpochNo -> Bool
forall a. Eq a => a -> a -> Bool
== EpochNo -> Maybe EpochNo
forall a. a -> Maybe a
Just EpochNo
currentEpoch
        expiringNext :: Bool
expiringNext = Maybe EpochNo
lookupNext Maybe EpochNo -> Maybe EpochNo -> Bool
forall a. Eq a => a -> a -> Bool
== EpochNo -> Maybe EpochNo
forall a. a -> Maybe a
Just EpochNo
currentEpoch
   in
    CommitteeMembersState
      { csCommittee :: Map (Credential 'ColdCommitteeRole) CommitteeMemberState
csCommittee = Map (Credential 'ColdCommitteeRole) CommitteeMemberState
cms
      , csThreshold :: Maybe UnitInterval
csThreshold = StrictMaybe UnitInterval -> Maybe UnitInterval
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe (StrictMaybe UnitInterval -> Maybe UnitInterval)
-> StrictMaybe UnitInterval -> Maybe UnitInterval
forall a b. (a -> b) -> a -> b
$ (Committee era
-> Getting UnitInterval (Committee era) UnitInterval
-> UnitInterval
forall s a. s -> Getting a s a -> a
^. Getting UnitInterval (Committee era) UnitInterval
forall era (f :: * -> *).
Functor f =>
(UnitInterval -> f UnitInterval)
-> Committee era -> f (Committee era)
committeeThresholdL) (Committee era -> UnitInterval)
-> StrictMaybe (Committee era) -> StrictMaybe UnitInterval
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StrictMaybe (Committee era)
committee
      , csEpochNo :: EpochNo
csEpochNo = EpochNo
currentEpoch
      }

queryChainAccountState ::
  NewEpochState era ->
  ChainAccountState
queryChainAccountState :: forall era. NewEpochState era -> ChainAccountState
queryChainAccountState = Getting ChainAccountState (NewEpochState era) ChainAccountState
-> NewEpochState era -> ChainAccountState
forall a s. Getting a s a -> s -> a
view Getting ChainAccountState (NewEpochState era) ChainAccountState
forall era. Lens' (NewEpochState era) ChainAccountState
forall (t :: * -> *) era.
CanSetChainAccountState t =>
Lens' (t era) ChainAccountState
chainAccountStateL

getNextEpochCommitteeMembers ::
  ConwayEraGov era =>
  NewEpochState era ->
  Map (Credential 'ColdCommitteeRole) EpochNo
getNextEpochCommitteeMembers :: forall era.
ConwayEraGov era =>
NewEpochState era -> Map (Credential 'ColdCommitteeRole) EpochNo
getNextEpochCommitteeMembers NewEpochState era
nes =
  let ratifyState :: RatifyState era
ratifyState = NewEpochState era -> RatifyState era
forall era.
ConwayEraGov era =>
NewEpochState era -> RatifyState era
queryRatifyState NewEpochState era
nes
      committee :: StrictMaybe (Committee era)
committee = RatifyState era
ratifyState RatifyState era
-> Getting
     (StrictMaybe (Committee era))
     (RatifyState era)
     (StrictMaybe (Committee era))
-> StrictMaybe (Committee era)
forall s a. s -> Getting a s a -> a
^. (EnactState era
 -> Const (StrictMaybe (Committee era)) (EnactState era))
-> RatifyState era
-> Const (StrictMaybe (Committee era)) (RatifyState era)
forall era (f :: * -> *).
Functor f =>
(EnactState era -> f (EnactState era))
-> RatifyState era -> f (RatifyState era)
rsEnactStateL ((EnactState era
  -> Const (StrictMaybe (Committee era)) (EnactState era))
 -> RatifyState era
 -> Const (StrictMaybe (Committee era)) (RatifyState era))
-> ((StrictMaybe (Committee era)
     -> Const
          (StrictMaybe (Committee era)) (StrictMaybe (Committee era)))
    -> EnactState era
    -> Const (StrictMaybe (Committee era)) (EnactState era))
-> Getting
     (StrictMaybe (Committee era))
     (RatifyState era)
     (StrictMaybe (Committee era))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StrictMaybe (Committee era)
 -> Const
      (StrictMaybe (Committee era)) (StrictMaybe (Committee era)))
-> EnactState era
-> Const (StrictMaybe (Committee era)) (EnactState era)
forall era (f :: * -> *).
Functor f =>
(StrictMaybe (Committee era) -> f (StrictMaybe (Committee era)))
-> EnactState era -> f (EnactState era)
ensCommitteeL
   in (Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo)
-> StrictMaybe (Committee era)
-> Map (Credential 'ColdCommitteeRole) EpochNo
forall m a. Monoid m => (a -> m) -> StrictMaybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap' Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
forall era.
Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
committeeMembers StrictMaybe (Committee era)
committee

-- | This is a simple lookup into the state for the values of current protocol
-- parameters. These values can change on the epoch boundary. Use `queryFuturePParams` to
-- see if we are aware of any upcoming changes.
queryCurrentPParams :: EraGov era => NewEpochState era -> PParams era
queryCurrentPParams :: forall era. EraGov era => NewEpochState era -> PParams era
queryCurrentPParams NewEpochState era
nes = NewEpochState era -> GovState era
forall era. NewEpochState era -> GovState era
queryGovState NewEpochState era
nes GovState era
-> Getting (PParams era) (GovState era) (PParams era)
-> PParams era
forall s a. s -> Getting a s a -> a
^. Getting (PParams era) (GovState era) (PParams era)
forall era. EraGov era => Lens' (GovState era) (PParams era)
Lens' (GovState era) (PParams era)
curPParamsGovStateL

-- | This query will return values for protocol parameters that are likely to be adopted
-- at the next epoch boundary. It is only when we passed 2 stability windows before the
-- end of the epoch that users can rely on this query to produce stable results.
queryFuturePParams :: EraGov era => NewEpochState era -> Maybe (PParams era)
queryFuturePParams :: forall era. EraGov era => NewEpochState era -> Maybe (PParams era)
queryFuturePParams NewEpochState era
nes =
  case NewEpochState era -> GovState era
forall era. NewEpochState era -> GovState era
queryGovState NewEpochState era
nes GovState era
-> Getting (FuturePParams era) (GovState era) (FuturePParams era)
-> FuturePParams era
forall s a. s -> Getting a s a -> a
^. Getting (FuturePParams era) (GovState era) (FuturePParams era)
forall era. EraGov era => Lens' (GovState era) (FuturePParams era)
Lens' (GovState era) (FuturePParams era)
futurePParamsGovStateL of
    FuturePParams era
NoPParamsUpdate -> Maybe (PParams era)
forall a. Maybe a
Nothing
    PotentialPParamsUpdate Maybe (PParams era)
mpp -> Maybe (PParams era)
mpp
    DefinitePParamsUpdate PParams era
pp -> PParams era -> Maybe (PParams era)
forall a. a -> Maybe a
Just PParams era
pp

-- | Query proposals that are considered for ratification.
queryProposals ::
  ConwayEraGov era =>
  NewEpochState 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 GovActionId ->
  Seq (GovActionState era)
queryProposals :: forall era.
ConwayEraGov era =>
NewEpochState era -> Set GovActionId -> Seq (GovActionState era)
queryProposals NewEpochState era
nes Set GovActionId
gids
  | Set GovActionId -> Bool
forall a. Set a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Set GovActionId
gids = Seq (GovActionState era)
proposals
  -- TODO: Add `filter` to `cardano-strict-containers`
  | Bool
otherwise =
      (GovActionState era -> Bool)
-> Seq (GovActionState era) -> Seq (GovActionState era)
forall a. (a -> Bool) -> Seq a -> Seq a
Seq.filter (\GovActionState {Map (KeyHash 'StakePool) Vote
Map (Credential 'DRepRole) Vote
Map (Credential 'HotCommitteeRole) Vote
ProposalProcedure era
GovActionId
EpochNo
gasId :: GovActionId
gasCommitteeVotes :: Map (Credential 'HotCommitteeRole) Vote
gasDRepVotes :: Map (Credential 'DRepRole) Vote
gasStakePoolVotes :: Map (KeyHash 'StakePool) Vote
gasProposalProcedure :: ProposalProcedure era
gasProposedIn :: EpochNo
gasExpiresAfter :: EpochNo
gasId :: forall era. GovActionState era -> GovActionId
gasCommitteeVotes :: forall era.
GovActionState era -> Map (Credential 'HotCommitteeRole) Vote
gasDRepVotes :: forall era. GovActionState era -> Map (Credential 'DRepRole) Vote
gasStakePoolVotes :: forall era. GovActionState era -> Map (KeyHash 'StakePool) Vote
gasProposalProcedure :: forall era. GovActionState era -> ProposalProcedure era
gasProposedIn :: forall era. GovActionState era -> EpochNo
gasExpiresAfter :: forall era. GovActionState era -> EpochNo
..} -> GovActionId
gasId GovActionId -> Set GovActionId -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set GovActionId
gids) Seq (GovActionState era)
proposals
  where
    proposals :: Seq (GovActionState era)
proposals = StrictSeq (GovActionState era) -> Seq (GovActionState era)
forall a. StrictSeq a -> Seq a
fromStrict (StrictSeq (GovActionState era) -> Seq (GovActionState era))
-> StrictSeq (GovActionState era) -> Seq (GovActionState era)
forall a b. (a -> b) -> a -> b
$ case NewEpochState era
nes NewEpochState era
-> Getting
     (DRepPulsingState era) (NewEpochState era) (DRepPulsingState era)
-> DRepPulsingState era
forall s a. s -> Getting a s a -> a
^. (GovState era -> Const (DRepPulsingState era) (GovState era))
-> NewEpochState era
-> Const (DRepPulsingState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(GovState era -> f (GovState era))
-> NewEpochState era -> f (NewEpochState era)
newEpochStateGovStateL ((GovState era -> Const (DRepPulsingState era) (GovState era))
 -> NewEpochState era
 -> Const (DRepPulsingState era) (NewEpochState era))
-> ((DRepPulsingState era
     -> Const (DRepPulsingState era) (DRepPulsingState era))
    -> GovState era -> Const (DRepPulsingState era) (GovState era))
-> Getting
     (DRepPulsingState era) (NewEpochState era) (DRepPulsingState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DRepPulsingState era
 -> Const (DRepPulsingState era) (DRepPulsingState era))
-> GovState era -> Const (DRepPulsingState era) (GovState era)
forall era.
ConwayEraGov era =>
Lens' (GovState era) (DRepPulsingState era)
Lens' (GovState era) (DRepPulsingState era)
drepPulsingStateGovStateL of
      DRComplete PulsingSnapshot era
snap RatifyState era
_rs -> PulsingSnapshot era
snap PulsingSnapshot era
-> Getting
     (StrictSeq (GovActionState era))
     (PulsingSnapshot era)
     (StrictSeq (GovActionState era))
-> StrictSeq (GovActionState era)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictSeq (GovActionState era))
  (PulsingSnapshot era)
  (StrictSeq (GovActionState era))
forall era (f :: * -> *).
Functor f =>
(StrictSeq (GovActionState era)
 -> f (StrictSeq (GovActionState era)))
-> PulsingSnapshot era -> f (PulsingSnapshot era)
psProposalsL
      DRPulsing DRepPulser {Int
Map (KeyHash 'StakePool) PoolParams
Map DRep (CompactForm Coin)
Map (Credential 'Staking) (CompactForm Coin)
Map (Credential 'DRepRole) DRepState
PoolDistr
CommitteeState era
InstantStake era
StrictSeq (GovActionState era)
EnactState era
EpochNo
Globals
UMap
dpPulseSize :: Int
dpUMap :: UMap
dpIndex :: Int
dpInstantStake :: InstantStake era
dpStakePoolDistr :: PoolDistr
dpDRepDistr :: Map DRep (CompactForm Coin)
dpDRepState :: Map (Credential 'DRepRole) DRepState
dpCurrentEpoch :: EpochNo
dpCommitteeState :: CommitteeState era
dpEnactState :: EnactState era
dpProposals :: StrictSeq (GovActionState era)
dpProposalDeposits :: Map (Credential 'Staking) (CompactForm Coin)
dpGlobals :: Globals
dpPoolParams :: Map (KeyHash 'StakePool) PoolParams
dpPulseSize :: forall era ans (m :: * -> *). DRepPulser era m ans -> Int
dpUMap :: forall era ans (m :: * -> *). DRepPulser era m ans -> UMap
dpIndex :: forall era ans (m :: * -> *). DRepPulser era m ans -> Int
dpInstantStake :: forall era ans (m :: * -> *).
DRepPulser era m ans -> InstantStake era
dpStakePoolDistr :: forall era ans (m :: * -> *). DRepPulser era m ans -> PoolDistr
dpDRepDistr :: forall era ans (m :: * -> *).
DRepPulser era m ans -> Map DRep (CompactForm Coin)
dpDRepState :: forall era ans (m :: * -> *).
DRepPulser era m ans -> Map (Credential 'DRepRole) DRepState
dpCurrentEpoch :: forall era ans (m :: * -> *). DRepPulser era m ans -> EpochNo
dpCommitteeState :: forall era ans (m :: * -> *).
DRepPulser era m ans -> CommitteeState era
dpEnactState :: forall era ans (m :: * -> *).
DRepPulser era m ans -> EnactState era
dpProposals :: forall era ans (m :: * -> *).
DRepPulser era m ans -> StrictSeq (GovActionState era)
dpProposalDeposits :: forall era ans (m :: * -> *).
DRepPulser era m ans
-> Map (Credential 'Staking) (CompactForm Coin)
dpGlobals :: forall era ans (m :: * -> *). DRepPulser era m ans -> Globals
dpPoolParams :: forall era ans (m :: * -> *).
DRepPulser era m ans -> Map (KeyHash 'StakePool) PoolParams
..} -> StrictSeq (GovActionState era)
dpProposals

-- | Query ratification state.
queryRatifyState :: ConwayEraGov era => NewEpochState era -> RatifyState era
queryRatifyState :: forall era.
ConwayEraGov era =>
NewEpochState era -> RatifyState era
queryRatifyState = (PulsingSnapshot era, RatifyState era) -> RatifyState era
forall a b. (a, b) -> b
snd ((PulsingSnapshot era, RatifyState era) -> RatifyState era)
-> (NewEpochState era -> (PulsingSnapshot era, RatifyState era))
-> NewEpochState era
-> RatifyState era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NewEpochState era -> (PulsingSnapshot era, RatifyState era)
forall era.
ConwayEraGov era =>
NewEpochState era -> (PulsingSnapshot era, RatifyState era)
finishedPulserState

finishedPulserState ::
  ConwayEraGov era =>
  NewEpochState era ->
  (PulsingSnapshot era, RatifyState era)
finishedPulserState :: forall era.
ConwayEraGov era =>
NewEpochState era -> (PulsingSnapshot era, RatifyState era)
finishedPulserState NewEpochState era
nes = DRepPulsingState era -> (PulsingSnapshot era, RatifyState era)
forall era.
EraStake era =>
DRepPulsingState era -> (PulsingSnapshot era, RatifyState era)
finishDRepPulser (NewEpochState era
nes NewEpochState era
-> Getting
     (DRepPulsingState era) (NewEpochState era) (DRepPulsingState era)
-> DRepPulsingState era
forall s a. s -> Getting a s a -> a
^. (GovState era -> Const (DRepPulsingState era) (GovState era))
-> NewEpochState era
-> Const (DRepPulsingState era) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(GovState era -> f (GovState era))
-> NewEpochState era -> f (NewEpochState era)
newEpochStateGovStateL ((GovState era -> Const (DRepPulsingState era) (GovState era))
 -> NewEpochState era
 -> Const (DRepPulsingState era) (NewEpochState era))
-> ((DRepPulsingState era
     -> Const (DRepPulsingState era) (DRepPulsingState era))
    -> GovState era -> Const (DRepPulsingState era) (GovState era))
-> Getting
     (DRepPulsingState era) (NewEpochState era) (DRepPulsingState era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DRepPulsingState era
 -> Const (DRepPulsingState era) (DRepPulsingState era))
-> GovState era -> Const (DRepPulsingState era) (GovState era)
forall era.
ConwayEraGov era =>
Lens' (GovState era) (DRepPulsingState era)
Lens' (GovState era) (DRepPulsingState era)
drepPulsingStateGovStateL)

-- | Query a stake pool's reward account delegatee which determines the pool's default vote
-- in absence of an explicit vote. Note that this is different from the delegatee determined
-- by the credential of the stake pool itself.
queryStakePoolDefaultVote ::
  EraCertState era =>
  NewEpochState era ->
  -- | Specify the key hash of the pool whose default vote should be returned.
  KeyHash 'StakePool ->
  DefaultVote
queryStakePoolDefaultVote :: forall era.
EraCertState era =>
NewEpochState era -> KeyHash 'StakePool -> DefaultVote
queryStakePoolDefaultVote NewEpochState era
nes KeyHash 'StakePool
poolId =
  KeyHash 'StakePool
-> Map (KeyHash 'StakePool) PoolParams
-> Map (Credential 'Staking) DRep
-> DefaultVote
defaultStakePoolVote KeyHash 'StakePool
poolId (NewEpochState era
nes NewEpochState era
-> Getting
     (Map (KeyHash 'StakePool) PoolParams)
     (NewEpochState era)
     (Map (KeyHash 'StakePool) PoolParams)
-> Map (KeyHash 'StakePool) PoolParams
forall s a. s -> Getting a s a -> a
^. (EpochState era
 -> Const (Map (KeyHash 'StakePool) PoolParams) (EpochState era))
-> NewEpochState era
-> Const (Map (KeyHash 'StakePool) PoolParams) (NewEpochState era)
forall era (f :: * -> *).
Functor f =>
(EpochState era -> f (EpochState era))
-> NewEpochState era -> f (NewEpochState era)
nesEsL ((EpochState era
  -> Const (Map (KeyHash 'StakePool) PoolParams) (EpochState era))
 -> NewEpochState era
 -> Const (Map (KeyHash 'StakePool) PoolParams) (NewEpochState era))
-> ((Map (KeyHash 'StakePool) PoolParams
     -> Const
          (Map (KeyHash 'StakePool) PoolParams)
          (Map (KeyHash 'StakePool) PoolParams))
    -> EpochState era
    -> Const (Map (KeyHash 'StakePool) PoolParams) (EpochState era))
-> Getting
     (Map (KeyHash 'StakePool) PoolParams)
     (NewEpochState era)
     (Map (KeyHash 'StakePool) PoolParams)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (KeyHash 'StakePool) PoolParams
 -> Const
      (Map (KeyHash 'StakePool) PoolParams)
      (Map (KeyHash 'StakePool) PoolParams))
-> EpochState era
-> Const (Map (KeyHash 'StakePool) PoolParams) (EpochState era)
forall era.
EraCertState era =>
Lens' (EpochState era) (Map (KeyHash 'StakePool) PoolParams)
Lens' (EpochState era) (Map (KeyHash 'StakePool) PoolParams)
epochStatePoolParamsL) (UMap -> Map (Credential 'Staking) DRep
dRepMap (UMap -> Map (Credential 'Staking) DRep)
-> UMap -> Map (Credential 'Staking) DRep
forall a b. (a -> b) -> a -> b
$ NewEpochState era
nes NewEpochState era -> Getting UMap (NewEpochState era) UMap -> UMap
forall s a. s -> Getting a s a -> a
^. Getting UMap (NewEpochState era) UMap
forall era. EraCertState era => Lens' (NewEpochState era) UMap
Lens' (NewEpochState era) UMap
unifiedL)