Skip to content

Commit

Permalink
Extract deposits from current state
Browse files Browse the repository at this point in the history
  • Loading branch information
kderme committed Apr 17, 2024
1 parent 80ef950 commit 3a41023
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Expand Up @@ -5,7 +5,9 @@

module Cardano.DbSync.Era.Shelley.Generic.ProtoParams (
ProtoParams (..),
Deposits (..),
epochProtoParams,
getDeposits,
) where

import Cardano.DbSync.Types
Expand Down Expand Up @@ -66,6 +68,11 @@ data ProtoParams = ProtoParams
, ppDRepActivity :: !(Maybe EpochInterval)
}

data Deposits = Deposits
{ stakeKeyDeposit :: Coin
, poolDeposit :: Coin
}

epochProtoParams :: ExtLedgerState CardanoBlock -> Maybe ProtoParams
epochProtoParams lstate =
case ledgerState lstate of
Expand All @@ -83,6 +90,24 @@ getProtoParams ::
PParams era
getProtoParams st = Shelley.nesEs (Consensus.shelleyLedgerState st) ^. Shelley.curPParamsEpochStateL

getDeposits :: ExtLedgerState CardanoBlock -> Maybe Deposits
getDeposits lstate =
case ledgerState lstate of
LedgerStateByron _ -> Nothing
LedgerStateShelley st -> Just $ getDopositsShelley $ getProtoParams st
LedgerStateAllegra st -> Just $ getDopositsShelley $ getProtoParams st
LedgerStateMary st -> Just $ getDopositsShelley $ getProtoParams st
LedgerStateAlonzo st -> Just $ getDopositsShelley $ getProtoParams st
LedgerStateBabbage st -> Just $ getDopositsShelley $ getProtoParams st
LedgerStateConway st -> Just $ getDopositsShelley $ getProtoParams st
where
getDopositsShelley :: EraPParams era => PParams era -> Deposits
getDopositsShelley pp =
Deposits
{ stakeKeyDeposit = pp ^. ppKeyDepositL
, poolDeposit = pp ^. ppPoolDepositL
}

-- -------------------------------------------------------------------------------------------------

fromConwayParams :: PParams StandardConway -> ProtoParams
Expand Down
1 change: 1 addition & 0 deletions cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs
Expand Up @@ -241,6 +241,7 @@ applyBlock env blk = do
, apPoolsRegistered = getRegisteredPools oldState
, apNewEpoch = maybeToStrict newEpoch
, apOldLedger = Strict.Just oldState
, apDeposits = maybeToStrict $ Generic.getDeposits newLedgerState
, apSlotDetails = details
, apStakeSlice = getStakeSlice env newState False
, apEvents = ledgerEvents
Expand Down
2 changes: 2 additions & 0 deletions cardano-db-sync/src/Cardano/DbSync/Ledger/Types.hs
Expand Up @@ -133,6 +133,7 @@ data ApplyResult = ApplyResult
, apPoolsRegistered :: !(Set.Set PoolKeyHash) -- registered before the block application
, apNewEpoch :: !(Strict.Maybe Generic.NewEpoch) -- Only Just for a single block at the epoch boundary
, apOldLedger :: !(Strict.Maybe CardanoLedgerState)
, apDeposits :: !(Strict.Maybe Generic.Deposits) -- The current required deposits
, apSlotDetails :: !SlotDetails
, apStakeSlice :: !Generic.StakeSliceRes
, apEvents :: ![LedgerEvent]
Expand All @@ -148,6 +149,7 @@ defaultApplyResult slotDetails =
, apPoolsRegistered = Set.empty
, apNewEpoch = Strict.Nothing
, apOldLedger = Strict.Nothing
, apDeposits = Strict.Nothing
, apSlotDetails = slotDetails
, apStakeSlice = Generic.NoSlices
, apEvents = []
Expand Down

0 comments on commit 3a41023

Please sign in to comment.