{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- | Types common to any generic committee selection scheme
module Ouroboros.Consensus.Committee.Types
  ( PoolId (..)
  , LedgerStake (..)
  , VoteWeight (..)
  , TargetCommitteeSize (..)
  , Cumulative (..)
  ) where

import Cardano.Binary (FromCBOR (..), ToCBOR (..))
import qualified Cardano.Crypto.Hash as Hash
import Cardano.Ledger.BaseTypes (HasZero)
import Cardano.Ledger.Core (KeyHash (..), KeyRole (..))
import Cardano.Prelude (Generic)
import Control.DeepSeq (NFData)
import Data.Semigroup (Sum (..))
import Data.Word (Word64)
import NoThunks.Class (NoThunks)

-- | Identifier of a given voter in the committee selection scheme
newtype PoolId = PoolId
  { PoolId -> KeyHash StakePool
unPoolId :: KeyHash StakePool
  }
  deriving stock (Int -> PoolId -> ShowS
[PoolId] -> ShowS
PoolId -> String
(Int -> PoolId -> ShowS)
-> (PoolId -> String) -> ([PoolId] -> ShowS) -> Show PoolId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PoolId -> ShowS
showsPrec :: Int -> PoolId -> ShowS
$cshow :: PoolId -> String
show :: PoolId -> String
$cshowList :: [PoolId] -> ShowS
showList :: [PoolId] -> ShowS
Show, PoolId -> PoolId -> Bool
(PoolId -> PoolId -> Bool)
-> (PoolId -> PoolId -> Bool) -> Eq PoolId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PoolId -> PoolId -> Bool
== :: PoolId -> PoolId -> Bool
$c/= :: PoolId -> PoolId -> Bool
/= :: PoolId -> PoolId -> Bool
Eq, Eq PoolId
Eq PoolId =>
(PoolId -> PoolId -> Ordering)
-> (PoolId -> PoolId -> Bool)
-> (PoolId -> PoolId -> Bool)
-> (PoolId -> PoolId -> Bool)
-> (PoolId -> PoolId -> Bool)
-> (PoolId -> PoolId -> PoolId)
-> (PoolId -> PoolId -> PoolId)
-> Ord PoolId
PoolId -> PoolId -> Bool
PoolId -> PoolId -> Ordering
PoolId -> PoolId -> PoolId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PoolId -> PoolId -> Ordering
compare :: PoolId -> PoolId -> Ordering
$c< :: PoolId -> PoolId -> Bool
< :: PoolId -> PoolId -> Bool
$c<= :: PoolId -> PoolId -> Bool
<= :: PoolId -> PoolId -> Bool
$c> :: PoolId -> PoolId -> Bool
> :: PoolId -> PoolId -> Bool
$c>= :: PoolId -> PoolId -> Bool
>= :: PoolId -> PoolId -> Bool
$cmax :: PoolId -> PoolId -> PoolId
max :: PoolId -> PoolId -> PoolId
$cmin :: PoolId -> PoolId -> PoolId
min :: PoolId -> PoolId -> PoolId
Ord, (forall x. PoolId -> Rep PoolId x)
-> (forall x. Rep PoolId x -> PoolId) -> Generic PoolId
forall x. Rep PoolId x -> PoolId
forall x. PoolId -> Rep PoolId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PoolId -> Rep PoolId x
from :: forall x. PoolId -> Rep PoolId x
$cto :: forall x. Rep PoolId x -> PoolId
to :: forall x. Rep PoolId x -> PoolId
Generic)
  deriving anyclass Context -> PoolId -> IO (Maybe ThunkInfo)
Proxy PoolId -> String
(Context -> PoolId -> IO (Maybe ThunkInfo))
-> (Context -> PoolId -> IO (Maybe ThunkInfo))
-> (Proxy PoolId -> String)
-> NoThunks PoolId
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> PoolId -> IO (Maybe ThunkInfo)
noThunks :: Context -> PoolId -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> PoolId -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> PoolId -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy PoolId -> String
showTypeOf :: Proxy PoolId -> String
NoThunks

instance FromCBOR PoolId where
  fromCBOR :: forall s. Decoder s PoolId
fromCBOR = do
    bytes <- Decoder s ByteString
forall s. Decoder s ByteString
forall a s. FromCBOR a => Decoder s a
fromCBOR
    case Hash.hashFromBytes bytes of
      Just Hash ADDRHASH (VerKeyDSIGN DSIGN)
hash ->
        PoolId -> Decoder s PoolId
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (KeyHash StakePool -> PoolId
PoolId (Hash ADDRHASH (VerKeyDSIGN DSIGN) -> KeyHash StakePool
forall (r :: KeyRole).
Hash ADDRHASH (VerKeyDSIGN DSIGN) -> KeyHash r
KeyHash Hash ADDRHASH (VerKeyDSIGN DSIGN)
hash))
      Maybe (Hash ADDRHASH (VerKeyDSIGN DSIGN))
Nothing ->
        String -> Decoder s PoolId
forall a. HasCallStack => String -> Decoder s a
forall (m :: * -> *) a.
(MonadFail m, HasCallStack) =>
String -> m a
fail (String
"failed to decode PoolId, invalid hash bytes: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ByteString -> String
forall a. Show a => a -> String
show ByteString
bytes)

instance ToCBOR PoolId where
  toCBOR :: PoolId -> Encoding
toCBOR (PoolId KeyHash StakePool
hash) =
    ByteString -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR (Hash ADDRHASH (VerKeyDSIGN DSIGN) -> ByteString
forall h a. Hash h a -> ByteString
Hash.hashToBytes (KeyHash StakePool -> Hash ADDRHASH (VerKeyDSIGN DSIGN)
forall (r :: KeyRole).
KeyHash r -> Hash ADDRHASH (VerKeyDSIGN DSIGN)
unKeyHash KeyHash StakePool
hash))

-- | Stake of a voter as reflected by the ledger state
newtype LedgerStake = LedgerStake
  { LedgerStake -> Rational
unLedgerStake :: Rational
  }
  deriving stock (Int -> LedgerStake -> ShowS
[LedgerStake] -> ShowS
LedgerStake -> String
(Int -> LedgerStake -> ShowS)
-> (LedgerStake -> String)
-> ([LedgerStake] -> ShowS)
-> Show LedgerStake
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LedgerStake -> ShowS
showsPrec :: Int -> LedgerStake -> ShowS
$cshow :: LedgerStake -> String
show :: LedgerStake -> String
$cshowList :: [LedgerStake] -> ShowS
showList :: [LedgerStake] -> ShowS
Show, LedgerStake -> LedgerStake -> Bool
(LedgerStake -> LedgerStake -> Bool)
-> (LedgerStake -> LedgerStake -> Bool) -> Eq LedgerStake
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LedgerStake -> LedgerStake -> Bool
== :: LedgerStake -> LedgerStake -> Bool
$c/= :: LedgerStake -> LedgerStake -> Bool
/= :: LedgerStake -> LedgerStake -> Bool
Eq, Eq LedgerStake
Eq LedgerStake =>
(LedgerStake -> LedgerStake -> Ordering)
-> (LedgerStake -> LedgerStake -> Bool)
-> (LedgerStake -> LedgerStake -> Bool)
-> (LedgerStake -> LedgerStake -> Bool)
-> (LedgerStake -> LedgerStake -> Bool)
-> (LedgerStake -> LedgerStake -> LedgerStake)
-> (LedgerStake -> LedgerStake -> LedgerStake)
-> Ord LedgerStake
LedgerStake -> LedgerStake -> Bool
LedgerStake -> LedgerStake -> Ordering
LedgerStake -> LedgerStake -> LedgerStake
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LedgerStake -> LedgerStake -> Ordering
compare :: LedgerStake -> LedgerStake -> Ordering
$c< :: LedgerStake -> LedgerStake -> Bool
< :: LedgerStake -> LedgerStake -> Bool
$c<= :: LedgerStake -> LedgerStake -> Bool
<= :: LedgerStake -> LedgerStake -> Bool
$c> :: LedgerStake -> LedgerStake -> Bool
> :: LedgerStake -> LedgerStake -> Bool
$c>= :: LedgerStake -> LedgerStake -> Bool
>= :: LedgerStake -> LedgerStake -> Bool
$cmax :: LedgerStake -> LedgerStake -> LedgerStake
max :: LedgerStake -> LedgerStake -> LedgerStake
$cmin :: LedgerStake -> LedgerStake -> LedgerStake
min :: LedgerStake -> LedgerStake -> LedgerStake
Ord, (forall x. LedgerStake -> Rep LedgerStake x)
-> (forall x. Rep LedgerStake x -> LedgerStake)
-> Generic LedgerStake
forall x. Rep LedgerStake x -> LedgerStake
forall x. LedgerStake -> Rep LedgerStake x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LedgerStake -> Rep LedgerStake x
from :: forall x. LedgerStake -> Rep LedgerStake x
$cto :: forall x. Rep LedgerStake x -> LedgerStake
to :: forall x. Rep LedgerStake x -> LedgerStake
Generic)
  deriving newtype (Integer -> LedgerStake
LedgerStake -> LedgerStake
LedgerStake -> LedgerStake -> LedgerStake
(LedgerStake -> LedgerStake -> LedgerStake)
-> (LedgerStake -> LedgerStake -> LedgerStake)
-> (LedgerStake -> LedgerStake -> LedgerStake)
-> (LedgerStake -> LedgerStake)
-> (LedgerStake -> LedgerStake)
-> (LedgerStake -> LedgerStake)
-> (Integer -> LedgerStake)
-> Num LedgerStake
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: LedgerStake -> LedgerStake -> LedgerStake
+ :: LedgerStake -> LedgerStake -> LedgerStake
$c- :: LedgerStake -> LedgerStake -> LedgerStake
- :: LedgerStake -> LedgerStake -> LedgerStake
$c* :: LedgerStake -> LedgerStake -> LedgerStake
* :: LedgerStake -> LedgerStake -> LedgerStake
$cnegate :: LedgerStake -> LedgerStake
negate :: LedgerStake -> LedgerStake
$cabs :: LedgerStake -> LedgerStake
abs :: LedgerStake -> LedgerStake
$csignum :: LedgerStake -> LedgerStake
signum :: LedgerStake -> LedgerStake
$cfromInteger :: Integer -> LedgerStake
fromInteger :: Integer -> LedgerStake
Num, LedgerStake -> Bool
(LedgerStake -> Bool) -> HasZero LedgerStake
forall a. (a -> Bool) -> HasZero a
$cisZero :: LedgerStake -> Bool
isZero :: LedgerStake -> Bool
HasZero, Typeable LedgerStake
Typeable LedgerStake =>
(forall s. Decoder s LedgerStake)
-> (Proxy LedgerStake -> Text) -> FromCBOR LedgerStake
Proxy LedgerStake -> Text
forall s. Decoder s LedgerStake
forall a.
Typeable a =>
(forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
$cfromCBOR :: forall s. Decoder s LedgerStake
fromCBOR :: forall s. Decoder s LedgerStake
$clabel :: Proxy LedgerStake -> Text
label :: Proxy LedgerStake -> Text
FromCBOR, Typeable LedgerStake
Typeable LedgerStake =>
(LedgerStake -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy LedgerStake -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [LedgerStake] -> Size)
-> ToCBOR LedgerStake
LedgerStake -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [LedgerStake] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy LedgerStake -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
$ctoCBOR :: LedgerStake -> Encoding
toCBOR :: LedgerStake -> Encoding
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy LedgerStake -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy LedgerStake -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [LedgerStake] -> Size
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [LedgerStake] -> Size
ToCBOR)
  deriving anyclass Context -> LedgerStake -> IO (Maybe ThunkInfo)
Proxy LedgerStake -> String
(Context -> LedgerStake -> IO (Maybe ThunkInfo))
-> (Context -> LedgerStake -> IO (Maybe ThunkInfo))
-> (Proxy LedgerStake -> String)
-> NoThunks LedgerStake
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> LedgerStake -> IO (Maybe ThunkInfo)
noThunks :: Context -> LedgerStake -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> LedgerStake -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> LedgerStake -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy LedgerStake -> String
showTypeOf :: Proxy LedgerStake -> String
NoThunks

-- | Relative voting power of a voter in the committee selection scheme
newtype VoteWeight = VoteWeight
  { VoteWeight -> Rational
unVoteWeight :: Rational
  }
  deriving stock (Int -> VoteWeight -> ShowS
[VoteWeight] -> ShowS
VoteWeight -> String
(Int -> VoteWeight -> ShowS)
-> (VoteWeight -> String)
-> ([VoteWeight] -> ShowS)
-> Show VoteWeight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VoteWeight -> ShowS
showsPrec :: Int -> VoteWeight -> ShowS
$cshow :: VoteWeight -> String
show :: VoteWeight -> String
$cshowList :: [VoteWeight] -> ShowS
showList :: [VoteWeight] -> ShowS
Show, VoteWeight -> VoteWeight -> Bool
(VoteWeight -> VoteWeight -> Bool)
-> (VoteWeight -> VoteWeight -> Bool) -> Eq VoteWeight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VoteWeight -> VoteWeight -> Bool
== :: VoteWeight -> VoteWeight -> Bool
$c/= :: VoteWeight -> VoteWeight -> Bool
/= :: VoteWeight -> VoteWeight -> Bool
Eq, Eq VoteWeight
Eq VoteWeight =>
(VoteWeight -> VoteWeight -> Ordering)
-> (VoteWeight -> VoteWeight -> Bool)
-> (VoteWeight -> VoteWeight -> Bool)
-> (VoteWeight -> VoteWeight -> Bool)
-> (VoteWeight -> VoteWeight -> Bool)
-> (VoteWeight -> VoteWeight -> VoteWeight)
-> (VoteWeight -> VoteWeight -> VoteWeight)
-> Ord VoteWeight
VoteWeight -> VoteWeight -> Bool
VoteWeight -> VoteWeight -> Ordering
VoteWeight -> VoteWeight -> VoteWeight
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: VoteWeight -> VoteWeight -> Ordering
compare :: VoteWeight -> VoteWeight -> Ordering
$c< :: VoteWeight -> VoteWeight -> Bool
< :: VoteWeight -> VoteWeight -> Bool
$c<= :: VoteWeight -> VoteWeight -> Bool
<= :: VoteWeight -> VoteWeight -> Bool
$c> :: VoteWeight -> VoteWeight -> Bool
> :: VoteWeight -> VoteWeight -> Bool
$c>= :: VoteWeight -> VoteWeight -> Bool
>= :: VoteWeight -> VoteWeight -> Bool
$cmax :: VoteWeight -> VoteWeight -> VoteWeight
max :: VoteWeight -> VoteWeight -> VoteWeight
$cmin :: VoteWeight -> VoteWeight -> VoteWeight
min :: VoteWeight -> VoteWeight -> VoteWeight
Ord, (forall x. VoteWeight -> Rep VoteWeight x)
-> (forall x. Rep VoteWeight x -> VoteWeight) -> Generic VoteWeight
forall x. Rep VoteWeight x -> VoteWeight
forall x. VoteWeight -> Rep VoteWeight x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. VoteWeight -> Rep VoteWeight x
from :: forall x. VoteWeight -> Rep VoteWeight x
$cto :: forall x. Rep VoteWeight x -> VoteWeight
to :: forall x. Rep VoteWeight x -> VoteWeight
Generic)
  deriving newtype (Integer -> VoteWeight
VoteWeight -> VoteWeight
VoteWeight -> VoteWeight -> VoteWeight
(VoteWeight -> VoteWeight -> VoteWeight)
-> (VoteWeight -> VoteWeight -> VoteWeight)
-> (VoteWeight -> VoteWeight -> VoteWeight)
-> (VoteWeight -> VoteWeight)
-> (VoteWeight -> VoteWeight)
-> (VoteWeight -> VoteWeight)
-> (Integer -> VoteWeight)
-> Num VoteWeight
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: VoteWeight -> VoteWeight -> VoteWeight
+ :: VoteWeight -> VoteWeight -> VoteWeight
$c- :: VoteWeight -> VoteWeight -> VoteWeight
- :: VoteWeight -> VoteWeight -> VoteWeight
$c* :: VoteWeight -> VoteWeight -> VoteWeight
* :: VoteWeight -> VoteWeight -> VoteWeight
$cnegate :: VoteWeight -> VoteWeight
negate :: VoteWeight -> VoteWeight
$cabs :: VoteWeight -> VoteWeight
abs :: VoteWeight -> VoteWeight
$csignum :: VoteWeight -> VoteWeight
signum :: VoteWeight -> VoteWeight
$cfromInteger :: Integer -> VoteWeight
fromInteger :: Integer -> VoteWeight
Num, Num VoteWeight
Num VoteWeight =>
(VoteWeight -> VoteWeight -> VoteWeight)
-> (VoteWeight -> VoteWeight)
-> (Rational -> VoteWeight)
-> Fractional VoteWeight
Rational -> VoteWeight
VoteWeight -> VoteWeight
VoteWeight -> VoteWeight -> VoteWeight
forall a.
Num a =>
(a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
$c/ :: VoteWeight -> VoteWeight -> VoteWeight
/ :: VoteWeight -> VoteWeight -> VoteWeight
$crecip :: VoteWeight -> VoteWeight
recip :: VoteWeight -> VoteWeight
$cfromRational :: Rational -> VoteWeight
fromRational :: Rational -> VoteWeight
Fractional, VoteWeight -> ()
(VoteWeight -> ()) -> NFData VoteWeight
forall a. (a -> ()) -> NFData a
$crnf :: VoteWeight -> ()
rnf :: VoteWeight -> ()
NFData, Typeable VoteWeight
Typeable VoteWeight =>
(forall s. Decoder s VoteWeight)
-> (Proxy VoteWeight -> Text) -> FromCBOR VoteWeight
Proxy VoteWeight -> Text
forall s. Decoder s VoteWeight
forall a.
Typeable a =>
(forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
$cfromCBOR :: forall s. Decoder s VoteWeight
fromCBOR :: forall s. Decoder s VoteWeight
$clabel :: Proxy VoteWeight -> Text
label :: Proxy VoteWeight -> Text
FromCBOR, Typeable VoteWeight
Typeable VoteWeight =>
(VoteWeight -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy VoteWeight -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [VoteWeight] -> Size)
-> ToCBOR VoteWeight
VoteWeight -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VoteWeight] -> Size
(forall t. ToCBOR t => Proxy t -> Size) -> Proxy VoteWeight -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
$ctoCBOR :: VoteWeight -> Encoding
toCBOR :: VoteWeight -> Encoding
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy VoteWeight -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy VoteWeight -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VoteWeight] -> Size
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [VoteWeight] -> Size
ToCBOR)
  deriving anyclass Context -> VoteWeight -> IO (Maybe ThunkInfo)
Proxy VoteWeight -> String
(Context -> VoteWeight -> IO (Maybe ThunkInfo))
-> (Context -> VoteWeight -> IO (Maybe ThunkInfo))
-> (Proxy VoteWeight -> String)
-> NoThunks VoteWeight
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> VoteWeight -> IO (Maybe ThunkInfo)
noThunks :: Context -> VoteWeight -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> VoteWeight -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> VoteWeight -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy VoteWeight -> String
showTypeOf :: Proxy VoteWeight -> String
NoThunks
  deriving NonEmpty VoteWeight -> VoteWeight
VoteWeight -> VoteWeight -> VoteWeight
(VoteWeight -> VoteWeight -> VoteWeight)
-> (NonEmpty VoteWeight -> VoteWeight)
-> (forall b. Integral b => b -> VoteWeight -> VoteWeight)
-> Semigroup VoteWeight
forall b. Integral b => b -> VoteWeight -> VoteWeight
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: VoteWeight -> VoteWeight -> VoteWeight
<> :: VoteWeight -> VoteWeight -> VoteWeight
$csconcat :: NonEmpty VoteWeight -> VoteWeight
sconcat :: NonEmpty VoteWeight -> VoteWeight
$cstimes :: forall b. Integral b => b -> VoteWeight -> VoteWeight
stimes :: forall b. Integral b => b -> VoteWeight -> VoteWeight
Semigroup via Sum Rational
  deriving Semigroup VoteWeight
VoteWeight
Semigroup VoteWeight =>
VoteWeight
-> (VoteWeight -> VoteWeight -> VoteWeight)
-> ([VoteWeight] -> VoteWeight)
-> Monoid VoteWeight
[VoteWeight] -> VoteWeight
VoteWeight -> VoteWeight -> VoteWeight
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: VoteWeight
mempty :: VoteWeight
$cmappend :: VoteWeight -> VoteWeight -> VoteWeight
mappend :: VoteWeight -> VoteWeight -> VoteWeight
$cmconcat :: [VoteWeight] -> VoteWeight
mconcat :: [VoteWeight] -> VoteWeight
Monoid via Sum Rational

-- | Target committee size
newtype TargetCommitteeSize = TargetCommitteeSize
  { TargetCommitteeSize -> Word64
unTargetCommitteeSize :: Word64
  }
  deriving stock (Int -> TargetCommitteeSize -> ShowS
[TargetCommitteeSize] -> ShowS
TargetCommitteeSize -> String
(Int -> TargetCommitteeSize -> ShowS)
-> (TargetCommitteeSize -> String)
-> ([TargetCommitteeSize] -> ShowS)
-> Show TargetCommitteeSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TargetCommitteeSize -> ShowS
showsPrec :: Int -> TargetCommitteeSize -> ShowS
$cshow :: TargetCommitteeSize -> String
show :: TargetCommitteeSize -> String
$cshowList :: [TargetCommitteeSize] -> ShowS
showList :: [TargetCommitteeSize] -> ShowS
Show, TargetCommitteeSize -> TargetCommitteeSize -> Bool
(TargetCommitteeSize -> TargetCommitteeSize -> Bool)
-> (TargetCommitteeSize -> TargetCommitteeSize -> Bool)
-> Eq TargetCommitteeSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TargetCommitteeSize -> TargetCommitteeSize -> Bool
== :: TargetCommitteeSize -> TargetCommitteeSize -> Bool
$c/= :: TargetCommitteeSize -> TargetCommitteeSize -> Bool
/= :: TargetCommitteeSize -> TargetCommitteeSize -> Bool
Eq, (forall x. TargetCommitteeSize -> Rep TargetCommitteeSize x)
-> (forall x. Rep TargetCommitteeSize x -> TargetCommitteeSize)
-> Generic TargetCommitteeSize
forall x. Rep TargetCommitteeSize x -> TargetCommitteeSize
forall x. TargetCommitteeSize -> Rep TargetCommitteeSize x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TargetCommitteeSize -> Rep TargetCommitteeSize x
from :: forall x. TargetCommitteeSize -> Rep TargetCommitteeSize x
$cto :: forall x. Rep TargetCommitteeSize x -> TargetCommitteeSize
to :: forall x. Rep TargetCommitteeSize x -> TargetCommitteeSize
Generic)
  deriving newtype (Typeable TargetCommitteeSize
Typeable TargetCommitteeSize =>
(forall s. Decoder s TargetCommitteeSize)
-> (Proxy TargetCommitteeSize -> Text)
-> FromCBOR TargetCommitteeSize
Proxy TargetCommitteeSize -> Text
forall s. Decoder s TargetCommitteeSize
forall a.
Typeable a =>
(forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
$cfromCBOR :: forall s. Decoder s TargetCommitteeSize
fromCBOR :: forall s. Decoder s TargetCommitteeSize
$clabel :: Proxy TargetCommitteeSize -> Text
label :: Proxy TargetCommitteeSize -> Text
FromCBOR, Typeable TargetCommitteeSize
Typeable TargetCommitteeSize =>
(TargetCommitteeSize -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy TargetCommitteeSize -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [TargetCommitteeSize] -> Size)
-> ToCBOR TargetCommitteeSize
TargetCommitteeSize -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [TargetCommitteeSize] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy TargetCommitteeSize -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
$ctoCBOR :: TargetCommitteeSize -> Encoding
toCBOR :: TargetCommitteeSize -> Encoding
$cencodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy TargetCommitteeSize -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy TargetCommitteeSize -> Size
$cencodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [TargetCommitteeSize] -> Size
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [TargetCommitteeSize] -> Size
ToCBOR)
  deriving anyclass Context -> TargetCommitteeSize -> IO (Maybe ThunkInfo)
Proxy TargetCommitteeSize -> String
(Context -> TargetCommitteeSize -> IO (Maybe ThunkInfo))
-> (Context -> TargetCommitteeSize -> IO (Maybe ThunkInfo))
-> (Proxy TargetCommitteeSize -> String)
-> NoThunks TargetCommitteeSize
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> TargetCommitteeSize -> IO (Maybe ThunkInfo)
noThunks :: Context -> TargetCommitteeSize -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> TargetCommitteeSize -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> TargetCommitteeSize -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy TargetCommitteeSize -> String
showTypeOf :: Proxy TargetCommitteeSize -> String
NoThunks

-- | Wrapper to tag accumulated resources
newtype Cumulative a = Cumulative
  { forall a. Cumulative a -> a
unCumulative :: a
  }
  deriving stock (Int -> Cumulative a -> ShowS
[Cumulative a] -> ShowS
Cumulative a -> String
(Int -> Cumulative a -> ShowS)
-> (Cumulative a -> String)
-> ([Cumulative a] -> ShowS)
-> Show (Cumulative a)
forall a. Show a => Int -> Cumulative a -> ShowS
forall a. Show a => [Cumulative a] -> ShowS
forall a. Show a => Cumulative a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Cumulative a -> ShowS
showsPrec :: Int -> Cumulative a -> ShowS
$cshow :: forall a. Show a => Cumulative a -> String
show :: Cumulative a -> String
$cshowList :: forall a. Show a => [Cumulative a] -> ShowS
showList :: [Cumulative a] -> ShowS
Show, Cumulative a -> Cumulative a -> Bool
(Cumulative a -> Cumulative a -> Bool)
-> (Cumulative a -> Cumulative a -> Bool) -> Eq (Cumulative a)
forall a. Eq a => Cumulative a -> Cumulative a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Cumulative a -> Cumulative a -> Bool
== :: Cumulative a -> Cumulative a -> Bool
$c/= :: forall a. Eq a => Cumulative a -> Cumulative a -> Bool
/= :: Cumulative a -> Cumulative a -> Bool
Eq, (forall x. Cumulative a -> Rep (Cumulative a) x)
-> (forall x. Rep (Cumulative a) x -> Cumulative a)
-> Generic (Cumulative a)
forall x. Rep (Cumulative a) x -> Cumulative a
forall x. Cumulative a -> Rep (Cumulative a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Cumulative a) x -> Cumulative a
forall a x. Cumulative a -> Rep (Cumulative a) x
$cfrom :: forall a x. Cumulative a -> Rep (Cumulative a) x
from :: forall x. Cumulative a -> Rep (Cumulative a) x
$cto :: forall a x. Rep (Cumulative a) x -> Cumulative a
to :: forall x. Rep (Cumulative a) x -> Cumulative a
Generic)
  deriving newtype (Typeable (Cumulative a)
Typeable (Cumulative a) =>
(forall s. Decoder s (Cumulative a))
-> (Proxy (Cumulative a) -> Text) -> FromCBOR (Cumulative a)
Proxy (Cumulative a) -> Text
forall s. Decoder s (Cumulative a)
forall a.
Typeable a =>
(forall s. Decoder s a) -> (Proxy a -> Text) -> FromCBOR a
forall a. FromCBOR a => Typeable (Cumulative a)
forall a. FromCBOR a => Proxy (Cumulative a) -> Text
forall a s. FromCBOR a => Decoder s (Cumulative a)
$cfromCBOR :: forall a s. FromCBOR a => Decoder s (Cumulative a)
fromCBOR :: forall s. Decoder s (Cumulative a)
$clabel :: forall a. FromCBOR a => Proxy (Cumulative a) -> Text
label :: Proxy (Cumulative a) -> Text
FromCBOR, Typeable (Cumulative a)
Typeable (Cumulative a) =>
(Cumulative a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy (Cumulative a) -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size)
    -> Proxy [Cumulative a] -> Size)
-> ToCBOR (Cumulative a)
Cumulative a -> Encoding
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Cumulative a] -> Size
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Cumulative a) -> Size
forall a.
Typeable a =>
(a -> Encoding)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size)
-> ((forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size)
-> ToCBOR a
forall a. ToCBOR a => Typeable (Cumulative a)
forall a. ToCBOR a => Cumulative a -> Encoding
forall a.
ToCBOR a =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Cumulative a] -> Size
forall a.
ToCBOR a =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Cumulative a) -> Size
$ctoCBOR :: forall a. ToCBOR a => Cumulative a -> Encoding
toCBOR :: Cumulative a -> Encoding
$cencodedSizeExpr :: forall a.
ToCBOR a =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Cumulative a) -> Size
encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (Cumulative a) -> Size
$cencodedListSizeExpr :: forall a.
ToCBOR a =>
(forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Cumulative a] -> Size
encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy [Cumulative a] -> Size
ToCBOR)
  deriving anyclass Context -> Cumulative a -> IO (Maybe ThunkInfo)
Proxy (Cumulative a) -> String
(Context -> Cumulative a -> IO (Maybe ThunkInfo))
-> (Context -> Cumulative a -> IO (Maybe ThunkInfo))
-> (Proxy (Cumulative a) -> String)
-> NoThunks (Cumulative a)
forall a.
NoThunks a =>
Context -> Cumulative a -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Proxy (Cumulative a) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: forall a.
NoThunks a =>
Context -> Cumulative a -> IO (Maybe ThunkInfo)
noThunks :: Context -> Cumulative a -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall a.
NoThunks a =>
Context -> Cumulative a -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> Cumulative a -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall a. NoThunks a => Proxy (Cumulative a) -> String
showTypeOf :: Proxy (Cumulative a) -> String
NoThunks