@@ -18,8 +18,8 @@ module Testnet.Process.Cli.SPO
18
18
import Cardano.Api hiding (cardanoEra )
19
19
import qualified Cardano.Api.Ledger as L
20
20
21
- import qualified Cardano.Ledger.Api.State.Query as L
22
21
import qualified Cardano.Ledger.Shelley.LedgerState as L
22
+ import qualified Cardano.Ledger.State as L
23
23
import qualified Cardano.Ledger.UMap as L
24
24
25
25
import Control.Monad
@@ -130,30 +130,59 @@ checkStakeKeyRegistered tempAbsP nodeConfigFile sPath terminationEpoch execConfi
130
130
]
131
131
where
132
132
handler :: StakeAddress -> AnyNewEpochState -> SlotNo -> BlockNo -> StateT DelegationsAndRewards IO ConditionResult
133
- handler (StakeAddress network sCred) (AnyNewEpochState sbe newEpochState _) _ _ =
134
- let umap = shelleyBasedEraConstraints sbe $ newEpochState ^. L. nesEsL . L. epochStateUMapL
135
- dag = L. filterStakePoolDelegsAndRewards umap $ Set. singleton sCred
136
- allStakeCredentials = umap ^. L. umElemsL -- This does not include pointer addresses
137
- delegsAndRewards = shelleyBasedEraConstraints sbe $ toDelegationsAndRewards network sbe dag
138
- in case Map. lookup sCred allStakeCredentials of
139
- Nothing -> return ConditionNotMet
140
- Just _ -> StateT. put delegsAndRewards >> return ConditionMet
133
+ handler (StakeAddress network sCred) (AnyNewEpochState sbe newEpochState _) _ _ = shelleyBasedEraConstraints sbe $ do
134
+ let accountsMap = newEpochState
135
+ ^. L. nesEsL
136
+ . L. esLStateL
137
+ . L. lsCertStateL
138
+ . L. certDStateL
139
+ . L. accountsL
140
+ . L. accountsMapL
141
+
142
+
143
+ -- let umap = shelleyBasedEraConstraints sbe $ newEpochState ^. L.nesEsL . L.epochStateUMapL
144
+ -- dag = L.filterStakePoolDelegsAndRewards umap $ Set.singleton sCred
145
+ -- allStakeCredentials = umap ^. L.umElemsL -- This does not include pointer addresses
146
+ -- delegsAndRewards = shelleyBasedEraConstraints sbe $ toDelegationsAndRewards network sbe dag
147
+
148
+ case Map. lookup sCred accountsMap of
149
+ Nothing -> pure ConditionNotMet
150
+ Just _ -> do
151
+ StateT. put $ toDelegationsAndRewards sbe network accountsMap
152
+ pure ConditionMet
141
153
142
154
toDelegationsAndRewards
143
- :: L. Network
144
- -> ShelleyBasedEra era
145
- -> ( Map (L. Credential L. Staking ) (L. KeyHash L. StakePool ), Map ( L. Credential 'L. Staking ) L. Coin )
155
+ :: ShelleyBasedEra era
156
+ -> L. Network
157
+ -> Map (L. Credential L. Staking ) (L. AccountState ( ShelleyLedgerEra era ) )
146
158
-> DelegationsAndRewards
147
- toDelegationsAndRewards n _ (delegationMap, rewardsMap) =
148
- let apiDelegationMap = Map. map toApiPoolId $ Map. mapKeys (toApiStakeAddress n) delegationMap
149
- apiRewardsMap = Map. mapKeys (toApiStakeAddress n) rewardsMap
150
- in DelegationsAndRewards (apiRewardsMap, apiDelegationMap)
159
+ toDelegationsAndRewards sbe n accountsMap = do
160
+ let accountsMap' = Map. mapKeys (toApiStakeAddress n) accountsMap
161
+ let apiDelegationMap = Map. mapMaybe (toApiPoolId sbe) accountsMap'
162
+ apiRewardsMap = Map. map (toBalance sbe) accountsMap'
163
+ DelegationsAndRewards (apiRewardsMap, apiDelegationMap)
164
+
165
+ -- toApiPoolId :: L.KeyHash L.StakePool -> PoolId
166
+ toApiPoolId :: ShelleyBasedEra era
167
+ -> L. AccountState (ShelleyLedgerEra era )
168
+ -> Maybe PoolId
169
+ toApiPoolId sbe accountState =
170
+ fmap StakePoolKeyHash $
171
+ shelleyBasedEraConstraints sbe $
172
+ accountState ^. L. stakePoolDelegationAccountStateL
173
+
174
+
175
+ toBalance :: ShelleyBasedEra era
176
+ -> L. AccountState (ShelleyLedgerEra era )
177
+ -> L. Coin
178
+ toBalance sbe accountState =
179
+ shelleyBasedEraConstraints sbe $
180
+ accountState ^. L. balanceAccountStateL . to L. fromCompact
181
+
151
182
152
183
toApiStakeAddress :: L. Network -> L. Credential 'L.Staking -> StakeAddress
153
184
toApiStakeAddress = StakeAddress
154
185
155
- toApiPoolId :: L. KeyHash L. StakePool -> PoolId
156
- toApiPoolId = StakePoolKeyHash
157
186
158
187
createStakeDelegationCertificate
159
188
:: (MonadTest m , MonadCatch m , MonadIO m , HasCallStack )
0 commit comments