@@ -28,7 +28,7 @@ import Cardano.DbSync.Api
28
28
import Cardano.DbSync.Api.Types (InsertOptions (.. ), SyncEnv (.. ))
29
29
import Cardano.DbSync.Cache (queryOrInsertStakeAddress , queryPoolKeyOrInsert )
30
30
import Cardano.DbSync.Cache.Types (Cache , CacheNew (.. ))
31
- import Cardano.DbSync.Config.Types (isShelleyEnabled )
31
+ import Cardano.DbSync.Config.Types (isShelleyNotDisabled )
32
32
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
33
33
import Cardano.DbSync.Era.Universal.Insert.Certificate (insertPots )
34
34
import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCostModel , insertDrepDistr , updateEnacted , updateExpired , updateRatified )
@@ -38,7 +38,8 @@ import Cardano.DbSync.Ledger.Event
38
38
import Cardano.DbSync.Types
39
39
import Cardano.DbSync.Util (whenStrictJust )
40
40
import Cardano.DbSync.Util.Constraint (constraintNameEpochStake , constraintNameReward )
41
- import Cardano.Ledger.Address (RewardAccount (.. ))
41
+ import Cardano.DbSync.Util.Whitelist (shelleyStakeAddrWhitelistCheck )
42
+ import qualified Cardano.Ledger.Address as Ledger
42
43
import Cardano.Ledger.BaseTypes (Network , unEpochInterval )
43
44
import qualified Cardano.Ledger.BaseTypes as Ledger
44
45
import Cardano.Ledger.Binary.Version (getVersion )
@@ -214,20 +215,23 @@ insertEpochStake syncEnv nw epochNo stakeChunk = do
214
215
Cache ->
215
216
(StakeCred , (Shelley. Coin , PoolKeyHash )) ->
216
217
ExceptT SyncNodeError (ReaderT SqlBackend m ) (Maybe DB. EpochStake )
217
- mkStake cache (saddr, (coin, pool)) = do
218
- mSaId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
219
- poolId <- lift $ queryPoolKeyOrInsert " insertEpochStake" syncEnv cache CacheNew (isShelleyEnabled $ ioShelley iopts) pool
220
- case mSaId of
221
- Nothing -> pure Nothing
222
- Just saId ->
223
- pure $
224
- Just $
225
- DB. EpochStake
226
- { DB. epochStakeAddrId = saId
227
- , DB. epochStakePoolId = poolId
228
- , DB. epochStakeAmount = Generic. coinToDbLovelace coin
229
- , DB. epochStakeEpochNo = unEpochNo epochNo -- The epoch where this delegation becomes valid.
230
- }
218
+ mkStake cache (saddr, (coin, pool)) =
219
+ -- Check if the stake address is in the shelley whitelist
220
+ if shelleyStakeAddrWhitelistCheck syncEnv $ Ledger. RewardAcnt nw saddr
221
+ then
222
+ ( do
223
+ saId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
224
+ poolId <- lift $ queryPoolKeyOrInsert " insertEpochStake" syncEnv cache CacheNew (isShelleyNotDisabled $ ioShelley iopts) pool
225
+ pure $
226
+ Just $
227
+ DB. EpochStake
228
+ { DB. epochStakeAddrId = saId
229
+ , DB. epochStakePoolId = poolId
230
+ , DB. epochStakeAmount = Generic. coinToDbLovelace coin
231
+ , DB. epochStakeEpochNo = unEpochNo epochNo -- The epoch where this delegation becomes valid.
232
+ }
233
+ )
234
+ else pure Nothing
231
235
232
236
iopts = getInsertOptions syncEnv
233
237
@@ -251,11 +255,13 @@ insertRewards syncEnv nw earnedEpoch spendableEpoch cache rewardsChunk = do
251
255
(MonadBaseControl IO m , MonadIO m ) =>
252
256
(StakeCred , Set Generic. Reward ) ->
253
257
ExceptT SyncNodeError (ReaderT SqlBackend m ) [DB. Reward ]
254
- mkRewards (saddr, rset) = do
255
- mSaId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
256
- case mSaId of
257
- Nothing -> pure []
258
- Just saId -> mapM (prepareReward saId) (Set. toList rset)
258
+ mkRewards (saddr, rset) =
259
+ -- Check if the stake address is in the shelley whitelist
260
+ if shelleyStakeAddrWhitelistCheck syncEnv $ Ledger. RewardAcnt nw saddr
261
+ then do
262
+ saId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
263
+ mapM (prepareReward saId) (Set. toList rset)
264
+ else pure []
259
265
260
266
prepareReward ::
261
267
(MonadBaseControl IO m , MonadIO m ) =>
@@ -279,7 +285,7 @@ insertRewards syncEnv nw earnedEpoch spendableEpoch cache rewardsChunk = do
279
285
PoolKeyHash ->
280
286
ExceptT SyncNodeError (ReaderT SqlBackend m ) DB. PoolHashId
281
287
queryPool poolHash =
282
- lift (queryPoolKeyOrInsert " insertRewards" syncEnv cache CacheNew (isShelleyEnabled $ ioShelley iopts) poolHash)
288
+ lift (queryPoolKeyOrInsert " insertRewards" syncEnv cache CacheNew (isShelleyNotDisabled $ ioShelley iopts) poolHash)
283
289
284
290
iopts = getInsertOptions syncEnv
285
291
@@ -302,11 +308,13 @@ insertInstantRewards syncEnv nw earnedEpoch spendableEpoch cache rewardsChunk =
302
308
(MonadBaseControl IO m , MonadIO m ) =>
303
309
(StakeCred , Set Generic. RewardRest ) ->
304
310
ExceptT SyncNodeError (ReaderT SqlBackend m ) [DB. RewardRest ]
305
- mkRewards (saddr, rset) = do
306
- mSaId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
307
- case mSaId of
308
- Nothing -> pure []
309
- Just saId -> pure $ map (prepareReward saId) (Set. toList rset)
311
+ mkRewards (saddr, rset) =
312
+ -- Check if the stake address is in the shelley whitelist
313
+ if shelleyStakeAddrWhitelistCheck syncEnv $ Ledger. RewardAccount nw saddr
314
+ then do
315
+ saId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
316
+ pure $ map (prepareReward saId) (Set. toList rset)
317
+ else pure []
310
318
311
319
prepareReward ::
312
320
DB. StakeAddressId ->
0 commit comments