module Cardano.Api.LedgerEvents.Rule.TICK.RUPD
  ( handleLedgerRUPDEvents
  )
where

import           Cardano.Api.Address (fromShelleyStakeCredential)
import           Cardano.Api.LedgerEvents.LedgerEvent (LedgerEvent (IncrementalRewardsDistribution))

import           Cardano.Ledger.Crypto (StandardCrypto)
import           Cardano.Ledger.Shelley.Rules

import qualified Data.Map.Strict as Map

handleLedgerRUPDEvents :: RupdEvent StandardCrypto -> Maybe LedgerEvent
handleLedgerRUPDEvents :: RupdEvent StandardCrypto -> Maybe LedgerEvent
handleLedgerRUPDEvents (RupdEvent EpochNo
epochNum Map
  (Credential 'Staking StandardCrypto) (Set (Reward StandardCrypto))
rewards) =
  LedgerEvent -> Maybe LedgerEvent
forall a. a -> Maybe a
Just (LedgerEvent -> Maybe LedgerEvent)
-> LedgerEvent -> Maybe LedgerEvent
forall a b. (a -> b) -> a -> b
$ EpochNo
-> Map StakeCredential (Set (Reward StandardCrypto)) -> LedgerEvent
IncrementalRewardsDistribution EpochNo
epochNum ((Credential 'Staking StandardCrypto -> StakeCredential)
-> Map
     (Credential 'Staking StandardCrypto) (Set (Reward StandardCrypto))
-> Map StakeCredential (Set (Reward StandardCrypto))
forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeys Credential 'Staking StandardCrypto -> StakeCredential
fromShelleyStakeCredential Map
  (Credential 'Staking StandardCrypto) (Set (Reward StandardCrypto))
rewards)