@@ -10,15 +10,29 @@ module Cardano.DbSync.Era.Shelley.Generic.Rewards (
10
10
RewardRests (.. ),
11
11
rewardsCount ,
12
12
rewardsTotalAda ,
13
+ getRewardsUpdate ,
13
14
) where
14
15
15
16
import Cardano.Db (Ada , RewardSource (.. ), word64ToAda )
16
17
import Cardano.DbSync.Types
18
+ import Cardano.Ledger.BaseTypes (strictMaybeToMaybe )
17
19
import Cardano.Ledger.Coin (Coin (.. ))
20
+ import Cardano.Ledger.Crypto (StandardCrypto )
21
+ import Cardano.Ledger.Shelley.LedgerState hiding (LedgerState )
18
22
import Cardano.Prelude
19
23
import qualified Data.Map.Strict as Map
24
+ import Data.SOP.Strict.NP
20
25
import qualified Data.Set as Set
26
+ import Ouroboros.Consensus.Cardano.Block (EraCrypto , LedgerState (.. ))
21
27
import Ouroboros.Consensus.Cardano.CanHardFork ()
28
+ import Ouroboros.Consensus.Config (TopLevelConfig (.. ))
29
+ import Ouroboros.Consensus.HardFork.Combinator.AcrossEras
30
+ import Ouroboros.Consensus.HardFork.Combinator.Basics
31
+ import Ouroboros.Consensus.HardFork.Combinator.PartialConfig
32
+ import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState (.. ))
33
+ import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock )
34
+ import Ouroboros.Consensus.Shelley.Ledger.Ledger
35
+ import Ouroboros.Consensus.Shelley.ShelleyHFC
22
36
23
37
data Reward = Reward
24
38
{ rewardSource :: ! RewardSource
@@ -53,3 +67,33 @@ rewardsTotalAda rwds =
53
67
. sum
54
68
. concatMap (map (unCoin . rewardAmount) . Set. toList)
55
69
$ Map. elems (unRewards rwds)
70
+
71
+ getRewardsUpdate :: TopLevelConfig CardanoBlock -> ExtLedgerState CardanoBlock -> Maybe (RewardUpdate StandardCrypto )
72
+ getRewardsUpdate cfg els =
73
+ case ledgerState els of
74
+ LedgerStateByron _ -> Nothing
75
+ LedgerStateShelley sls -> genericRewardUpdate cfg sls
76
+ LedgerStateAllegra als -> genericRewardUpdate cfg als
77
+ LedgerStateMary mls -> genericRewardUpdate cfg mls
78
+ LedgerStateAlonzo als -> genericRewardUpdate cfg als
79
+ LedgerStateBabbage bls -> genericRewardUpdate cfg bls
80
+ LedgerStateConway cls -> genericRewardUpdate cfg cls
81
+
82
+ genericRewardUpdate ::
83
+ forall era p .
84
+ (EraCrypto era ~ StandardCrypto ) =>
85
+ TopLevelConfig CardanoBlock ->
86
+ LedgerState (ShelleyBlock p era ) ->
87
+ Maybe (RewardUpdate StandardCrypto )
88
+ genericRewardUpdate cfg lstate = do
89
+ pulsing <- strictMaybeToMaybe mPulsing
90
+ case pulsing of
91
+ Complete _ -> Nothing
92
+ Pulsing _ _ -> do
93
+ let Identity (rewardUpdate, _) = runReaderT (completeRupd pulsing) globals
94
+ Just rewardUpdate
95
+ where
96
+ mPulsing = nesRu $ shelleyLedgerState lstate
97
+
98
+ globals = case getPerEraLedgerConfig $ hardForkLedgerConfigPerEra $ topLevelConfigLedger cfg of
99
+ _ :* wplc :* _ -> shelleyLedgerGlobals $ shelleyLedgerConfig $ unwrapPartialLedgerConfig wplc
0 commit comments