Skip to content

Commit

Permalink
Introduce type PoolRegistrationStatus.
Browse files Browse the repository at this point in the history
Introduce type `PoolRegistrationStatus` and related functions.

Type `PoolRegistrationStatus` indicates the registration status of a
pool, which can be one of the following options:

  1. Not registered.
  2. Registered.
  3. Registered but retired.

In addition, this change introduces the `readPoolRegistrationStatus`
function, which read the pool registration status of a given pool on
any given database backend.
  • Loading branch information
jonathanknowles committed Jul 6, 2020
1 parent 7cb21eb commit 28bc362
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/core/src/Cardano/Pool/DB.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}

-- |
Expand All @@ -13,6 +14,10 @@ module Cardano.Pool.DB
( -- * Interface
DBLayer (..)

, PoolRegistrationStatus (..)
, determinePoolRegistrationStatus
, readPoolRegistrationStatus

-- * Errors
, ErrPointAlreadyExists (..)
) where
Expand Down Expand Up @@ -181,6 +186,45 @@ data DBLayer m = forall stm. (MonadFail stm, MonadIO stm) => DBLayer

type SlotIndex = (SlotId, SlotInternalIndex)

data PoolRegistrationStatus
= PoolNotRegistered
-- ^ Indicates that a pool is not registered.
| PoolRegistered
PoolRegistrationCertificate
-- ^ Indicates that a pool is registered BUT NOT marked for retirement.
-- Records the latest registration certificate.
| PoolRegisteredAndRetired
PoolRegistrationCertificate
PoolRetirementCertificate
-- ^ Indicates that a pool is registered AND ALSO marked for retirement.
-- Records the latest registration and retirement certificates.

determinePoolRegistrationStatus
:: Maybe (SlotIndex, PoolRegistrationCertificate)
-> Maybe (SlotIndex, PoolRetirementCertificate)
-> PoolRegistrationStatus
determinePoolRegistrationStatus = f
where
f Nothing _ =
PoolNotRegistered
f (Just (_, regCert)) Nothing =
PoolRegistered regCert
f (Just (regTime, regCert)) (Just (retTime, retCert))
| regTime > retTime =
PoolRegistered regCert
| otherwise =
PoolRegisteredAndRetired regCert retCert

readPoolRegistrationStatus
:: DBLayer m
-> PoolId
-> m PoolRegistrationStatus
readPoolRegistrationStatus
DBLayer {atomically, readPoolRegistration, readPoolRetirement} poolId =
atomically $ determinePoolRegistrationStatus
<$> readPoolRegistration poolId
<*> readPoolRetirement poolId

-- | Forbidden operation was executed on an already existing slot
newtype ErrPointAlreadyExists
= ErrPointAlreadyExists BlockHeader -- Point already exists in db
Expand Down

0 comments on commit 28bc362

Please sign in to comment.