{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

-- | This module provides the 'StakePoolState' data type, which represents the
-- state of a stake pool within the ledger. Unlike 'PoolParams', which includes
-- the pool ID and is used for pool registration and updates, 'StakePoolState'
-- is designed specifically for state management and excludes the pool ID
-- (since it's already used as the key in state maps).
--
-- This separation allows for:
-- * More efficient state storage (no redundant pool ID)
-- * Future extensibility of pool state without affecting registration parameters
-- * Clear distinction between registration parameters and actual pool state
--
-- This module also contains all the legacy pool-related types that were
-- previously in 'Cardano.Ledger.PoolParams', which is now deprecated.
-- These types are re-exported by 'Cardano.Ledger.State' for convenient access.
module Cardano.Ledger.State.StakePool (
  -- * Stake Pool State
  StakePoolState (..),

  -- * Lenses
  spsVrfL,
  spsBlsKeyL,
  spsPledgeL,
  spsCostL,
  spsMarginL,
  spsAccountIdL,
  spsOwnersL,
  spsRelaysL,
  spsMetadataL,
  spsDelegatorsL,
  spsDepositL,

  -- * Conversions
  mkStakePoolState,
  BlsKeyState (..),
  bksKeyL,
  bksRegisteredInL,
  stakePoolStateToStakePoolParams,

  -- * Pool Parameters and Related Types

  -- | These types were previously defined in 'Cardano.Ledger.PoolParams'.
  -- They are now part of this module and re-exported by 'Cardano.Ledger.State'.
  StakePoolParams (
    ..,
    PoolParams,
    ppId,
    ppVrf,
    ppBlsKey,
    ppPledge,
    ppCost,
    ppMargin,
    ppAccountAddress,
    ppOwners,
    ppRelays,
    ppMetadata
  ),
  withStakePoolParamsFlatEncoding,
  decodeStakePoolParamsFlat,
  PoolMetadata (..),
  BlsKey (..),
  StakePoolRelay (..),
  SizeOfPoolRelays (..),
  SizeOfPoolOwners (..),
  sppCostL,
  sppMetadataL,
  sppVrfL,
) where

import Cardano.Base.IP (IPv4, IPv6)
import Cardano.Crypto.DSIGN (
  BLS12381MinSigDSIGN,
  DSIGNAggregatable (PossessionProofDSIGN),
  DSIGNAlgorithm (VerKeyDSIGN),
 )
import Cardano.Ledger.Address (AccountAddress (..), AccountId (..))
import Cardano.Ledger.BaseTypes (
  DnsName,
  EpochNo,
  Network,
  Port,
  StrictMaybe (..),
  UnitInterval,
  Url,
  invalidKey,
 )
import Cardano.Ledger.Binary (
  DecCBOR (..),
  DecShareCBOR (..),
  Decoder,
  EncCBOR (..),
  Encoding,
  Interns,
  TokenType (TypeListLen, TypeListLen64, TypeListLenIndef, TypeNull),
  decodeFixedSized,
  decodeNull,
  decodeNullStrictMaybe,
  decodeRecordNamed,
  decodeRecordNamedT,
  decodeRecordSum,
  encodeFixedSized,
  encodeListLen,
  encodeNullStrictMaybe,
  ifDecoderVersionAtLeast,
  natVersion,
  peekTokenType,
  rawDecodeFixedSized,
  rawEncodeFixedSized,
  withCurrentEncodingVersion,
 )
import Cardano.Ledger.Binary.Coders (
  Decode (..),
  Encode (..),
  decode,
  encode,
  (!>),
  (<!),
 )
import Cardano.Ledger.Coin (Coin (..), CompactForm)
import Cardano.Ledger.Core.Era (Era)
import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.Keys (KeyHash (..), KeyRole (..), KeyRoleVRF (StakePoolVRF), VRFVerKeyHash)
import Cardano.Ledger.Orphans ()
import Control.Applicative ((<|>))
import Control.DeepSeq (NFData)
import Control.Monad (unless)
import Control.Monad.Trans (lift)
import Data.Aeson (FromJSON (..), ToJSON (..), Value, (.!=), (.:), (.:?), (.=))
import qualified Data.Aeson as Aeson
import Data.Aeson.Types (Parser, explicitParseField)
import Data.Array.Byte (ByteArray (..))
import qualified Data.ByteString.Base16 as B16
import qualified Data.ByteString.Short as SBS
import Data.Default (Default (..))
import Data.Foldable (asum)
import Data.MemPack.Buffer (byteArrayFromShortByteString, byteArrayToShortByteString)
import Data.Sequence.Strict (StrictSeq)
import Data.Set (Set)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Word (Word8)
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (NoThunks (..))

-- | State representation of a stake pool. This type contains all the same
-- information as 'PoolParams' except for the pool ID, which is stored
-- separately as the key in state maps.
data StakePoolState = StakePoolState
  { StakePoolState -> VRFVerKeyHash StakePoolVRF
spsVrf :: !(VRFVerKeyHash StakePoolVRF)
  -- ^ VRF verification key hash for leader election
  , StakePoolState -> StrictMaybe BlsKeyState
spsBlsKey :: !(StrictMaybe BlsKeyState)
  , StakePoolState -> Coin
spsPledge :: !Coin
  -- ^ Pledge amount committed by the pool operator
  , StakePoolState -> Coin
spsCost :: !Coin
  -- ^ Fixed operational cost per epoch
  , StakePoolState -> UnitInterval
spsMargin :: !UnitInterval
  -- ^ Pool profit margin (variable fee percentage)
  , StakePoolState -> AccountId
spsAccountId :: !AccountId
  -- ^ Account address credential for pool rewards
  , StakePoolState -> Set (KeyHash Staking)
spsOwners :: !(Set (KeyHash Staking))
  -- ^ Set of stake key hashes that own this pool
  , StakePoolState -> StrictSeq StakePoolRelay
spsRelays :: !(StrictSeq StakePoolRelay)
  -- ^ Network relay information for pool connectivity
  , StakePoolState -> StrictMaybe PoolMetadata
spsMetadata :: !(StrictMaybe PoolMetadata)
  -- ^ Optional metadata (URL and hash)
  , StakePoolState -> CompactForm Coin
spsDeposit :: !(CompactForm Coin)
  -- ^ Deposit for each pool
  , StakePoolState -> Set (Credential Staking)
spsDelegators :: !(Set (Credential Staking))
  -- ^ Credentials that have delegated to the pool
  }
  deriving (Int -> StakePoolState -> ShowS
[StakePoolState] -> ShowS
StakePoolState -> String
(Int -> StakePoolState -> ShowS)
-> (StakePoolState -> String)
-> ([StakePoolState] -> ShowS)
-> Show StakePoolState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StakePoolState -> ShowS
showsPrec :: Int -> StakePoolState -> ShowS
$cshow :: StakePoolState -> String
show :: StakePoolState -> String
$cshowList :: [StakePoolState] -> ShowS
showList :: [StakePoolState] -> ShowS
Show, (forall x. StakePoolState -> Rep StakePoolState x)
-> (forall x. Rep StakePoolState x -> StakePoolState)
-> Generic StakePoolState
forall x. Rep StakePoolState x -> StakePoolState
forall x. StakePoolState -> Rep StakePoolState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. StakePoolState -> Rep StakePoolState x
from :: forall x. StakePoolState -> Rep StakePoolState x
$cto :: forall x. Rep StakePoolState x -> StakePoolState
to :: forall x. Rep StakePoolState x -> StakePoolState
Generic, StakePoolState -> StakePoolState -> Bool
(StakePoolState -> StakePoolState -> Bool)
-> (StakePoolState -> StakePoolState -> Bool) -> Eq StakePoolState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StakePoolState -> StakePoolState -> Bool
== :: StakePoolState -> StakePoolState -> Bool
$c/= :: StakePoolState -> StakePoolState -> Bool
/= :: StakePoolState -> StakePoolState -> Bool
Eq, Eq StakePoolState
Eq StakePoolState =>
(StakePoolState -> StakePoolState -> Ordering)
-> (StakePoolState -> StakePoolState -> Bool)
-> (StakePoolState -> StakePoolState -> Bool)
-> (StakePoolState -> StakePoolState -> Bool)
-> (StakePoolState -> StakePoolState -> Bool)
-> (StakePoolState -> StakePoolState -> StakePoolState)
-> (StakePoolState -> StakePoolState -> StakePoolState)
-> Ord StakePoolState
StakePoolState -> StakePoolState -> Bool
StakePoolState -> StakePoolState -> Ordering
StakePoolState -> StakePoolState -> StakePoolState
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 :: StakePoolState -> StakePoolState -> Ordering
compare :: StakePoolState -> StakePoolState -> Ordering
$c< :: StakePoolState -> StakePoolState -> Bool
< :: StakePoolState -> StakePoolState -> Bool
$c<= :: StakePoolState -> StakePoolState -> Bool
<= :: StakePoolState -> StakePoolState -> Bool
$c> :: StakePoolState -> StakePoolState -> Bool
> :: StakePoolState -> StakePoolState -> Bool
$c>= :: StakePoolState -> StakePoolState -> Bool
>= :: StakePoolState -> StakePoolState -> Bool
$cmax :: StakePoolState -> StakePoolState -> StakePoolState
max :: StakePoolState -> StakePoolState -> StakePoolState
$cmin :: StakePoolState -> StakePoolState -> StakePoolState
min :: StakePoolState -> StakePoolState -> StakePoolState
Ord, Context -> StakePoolState -> IO (Maybe ThunkInfo)
Proxy StakePoolState -> String
(Context -> StakePoolState -> IO (Maybe ThunkInfo))
-> (Context -> StakePoolState -> IO (Maybe ThunkInfo))
-> (Proxy StakePoolState -> String)
-> NoThunks StakePoolState
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> StakePoolState -> IO (Maybe ThunkInfo)
noThunks :: Context -> StakePoolState -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> StakePoolState -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> StakePoolState -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy StakePoolState -> String
showTypeOf :: Proxy StakePoolState -> String
NoThunks, StakePoolState -> ()
(StakePoolState -> ()) -> NFData StakePoolState
forall a. (a -> ()) -> NFData a
$crnf :: StakePoolState -> ()
rnf :: StakePoolState -> ()
NFData, Maybe StakePoolState
Value -> Parser [StakePoolState]
Value -> Parser StakePoolState
(Value -> Parser StakePoolState)
-> (Value -> Parser [StakePoolState])
-> Maybe StakePoolState
-> FromJSON StakePoolState
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser StakePoolState
parseJSON :: Value -> Parser StakePoolState
$cparseJSONList :: Value -> Parser [StakePoolState]
parseJSONList :: Value -> Parser [StakePoolState]
$comittedField :: Maybe StakePoolState
omittedField :: Maybe StakePoolState
FromJSON, [StakePoolState] -> Value
[StakePoolState] -> Encoding
StakePoolState -> Bool
StakePoolState -> Value
StakePoolState -> Encoding
(StakePoolState -> Value)
-> (StakePoolState -> Encoding)
-> ([StakePoolState] -> Value)
-> ([StakePoolState] -> Encoding)
-> (StakePoolState -> Bool)
-> ToJSON StakePoolState
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: StakePoolState -> Value
toJSON :: StakePoolState -> Value
$ctoEncoding :: StakePoolState -> Encoding
toEncoding :: StakePoolState -> Encoding
$ctoJSONList :: [StakePoolState] -> Value
toJSONList :: [StakePoolState] -> Value
$ctoEncodingList :: [StakePoolState] -> Encoding
toEncodingList :: [StakePoolState] -> Encoding
$comitField :: StakePoolState -> Bool
omitField :: StakePoolState -> Bool
ToJSON)

spsVrfL :: Lens' StakePoolState (VRFVerKeyHash StakePoolVRF)
spsVrfL :: Lens' StakePoolState (VRFVerKeyHash StakePoolVRF)
spsVrfL = (StakePoolState -> VRFVerKeyHash StakePoolVRF)
-> (StakePoolState -> VRFVerKeyHash StakePoolVRF -> StakePoolState)
-> Lens' StakePoolState (VRFVerKeyHash StakePoolVRF)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> VRFVerKeyHash StakePoolVRF
spsVrf (\StakePoolState
sps VRFVerKeyHash StakePoolVRF
u -> StakePoolState
sps {spsVrf = u})

spsBlsKeyL :: Lens' StakePoolState (StrictMaybe BlsKeyState)
spsBlsKeyL :: Lens' StakePoolState (StrictMaybe BlsKeyState)
spsBlsKeyL = (StakePoolState -> StrictMaybe BlsKeyState)
-> (StakePoolState -> StrictMaybe BlsKeyState -> StakePoolState)
-> Lens' StakePoolState (StrictMaybe BlsKeyState)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> StrictMaybe BlsKeyState
spsBlsKey ((StakePoolState -> StrictMaybe BlsKeyState -> StakePoolState)
 -> Lens' StakePoolState (StrictMaybe BlsKeyState))
-> (StakePoolState -> StrictMaybe BlsKeyState -> StakePoolState)
-> Lens' StakePoolState (StrictMaybe BlsKeyState)
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps StrictMaybe BlsKeyState
blsKey -> StakePoolState
sps {spsBlsKey = blsKey}

spsPledgeL :: Lens' StakePoolState Coin
spsPledgeL :: Lens' StakePoolState Coin
spsPledgeL = (StakePoolState -> Coin)
-> (StakePoolState -> Coin -> StakePoolState)
-> Lens' StakePoolState Coin
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> Coin
spsPledge ((StakePoolState -> Coin -> StakePoolState)
 -> Lens' StakePoolState Coin)
-> (StakePoolState -> Coin -> StakePoolState)
-> Lens' StakePoolState Coin
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps Coin
c -> StakePoolState
sps {spsPledge = c}

spsCostL :: Lens' StakePoolState Coin
spsCostL :: Lens' StakePoolState Coin
spsCostL = (StakePoolState -> Coin)
-> (StakePoolState -> Coin -> StakePoolState)
-> Lens' StakePoolState Coin
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> Coin
spsCost ((StakePoolState -> Coin -> StakePoolState)
 -> Lens' StakePoolState Coin)
-> (StakePoolState -> Coin -> StakePoolState)
-> Lens' StakePoolState Coin
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps Coin
c -> StakePoolState
sps {spsCost = c}

spsMarginL :: Lens' StakePoolState UnitInterval
spsMarginL :: Lens' StakePoolState UnitInterval
spsMarginL = (StakePoolState -> UnitInterval)
-> (StakePoolState -> UnitInterval -> StakePoolState)
-> Lens' StakePoolState UnitInterval
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> UnitInterval
spsMargin ((StakePoolState -> UnitInterval -> StakePoolState)
 -> Lens' StakePoolState UnitInterval)
-> (StakePoolState -> UnitInterval -> StakePoolState)
-> Lens' StakePoolState UnitInterval
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps UnitInterval
m -> StakePoolState
sps {spsMargin = m}

spsAccountIdL :: Lens' StakePoolState AccountId
spsAccountIdL :: Lens' StakePoolState AccountId
spsAccountIdL = (StakePoolState -> AccountId)
-> (StakePoolState -> AccountId -> StakePoolState)
-> Lens' StakePoolState AccountId
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> AccountId
spsAccountId ((StakePoolState -> AccountId -> StakePoolState)
 -> Lens' StakePoolState AccountId)
-> (StakePoolState -> AccountId -> StakePoolState)
-> Lens' StakePoolState AccountId
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps AccountId
sc -> StakePoolState
sps {spsAccountId = sc}

spsOwnersL :: Lens' StakePoolState (Set (KeyHash Staking))
spsOwnersL :: Lens' StakePoolState (Set (KeyHash Staking))
spsOwnersL = (StakePoolState -> Set (KeyHash Staking))
-> (StakePoolState -> Set (KeyHash Staking) -> StakePoolState)
-> Lens' StakePoolState (Set (KeyHash Staking))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> Set (KeyHash Staking)
spsOwners ((StakePoolState -> Set (KeyHash Staking) -> StakePoolState)
 -> Lens' StakePoolState (Set (KeyHash Staking)))
-> (StakePoolState -> Set (KeyHash Staking) -> StakePoolState)
-> Lens' StakePoolState (Set (KeyHash Staking))
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps Set (KeyHash Staking)
s -> StakePoolState
sps {spsOwners = s}

spsRelaysL :: Lens' StakePoolState (StrictSeq StakePoolRelay)
spsRelaysL :: Lens' StakePoolState (StrictSeq StakePoolRelay)
spsRelaysL = (StakePoolState -> StrictSeq StakePoolRelay)
-> (StakePoolState -> StrictSeq StakePoolRelay -> StakePoolState)
-> Lens' StakePoolState (StrictSeq StakePoolRelay)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> StrictSeq StakePoolRelay
spsRelays ((StakePoolState -> StrictSeq StakePoolRelay -> StakePoolState)
 -> Lens' StakePoolState (StrictSeq StakePoolRelay))
-> (StakePoolState -> StrictSeq StakePoolRelay -> StakePoolState)
-> Lens' StakePoolState (StrictSeq StakePoolRelay)
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps StrictSeq StakePoolRelay
rs -> StakePoolState
sps {spsRelays = rs}

spsMetadataL :: Lens' StakePoolState (StrictMaybe PoolMetadata)
spsMetadataL :: Lens' StakePoolState (StrictMaybe PoolMetadata)
spsMetadataL = (StakePoolState -> StrictMaybe PoolMetadata)
-> (StakePoolState -> StrictMaybe PoolMetadata -> StakePoolState)
-> Lens' StakePoolState (StrictMaybe PoolMetadata)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> StrictMaybe PoolMetadata
spsMetadata ((StakePoolState -> StrictMaybe PoolMetadata -> StakePoolState)
 -> Lens' StakePoolState (StrictMaybe PoolMetadata))
-> (StakePoolState -> StrictMaybe PoolMetadata -> StakePoolState)
-> Lens' StakePoolState (StrictMaybe PoolMetadata)
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps StrictMaybe PoolMetadata
md -> StakePoolState
sps {spsMetadata = md}

spsDepositL :: Lens' StakePoolState (CompactForm Coin)
spsDepositL :: Lens' StakePoolState (CompactForm Coin)
spsDepositL = (StakePoolState -> CompactForm Coin)
-> (StakePoolState -> CompactForm Coin -> StakePoolState)
-> Lens' StakePoolState (CompactForm Coin)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> CompactForm Coin
spsDeposit ((StakePoolState -> CompactForm Coin -> StakePoolState)
 -> Lens' StakePoolState (CompactForm Coin))
-> (StakePoolState -> CompactForm Coin -> StakePoolState)
-> Lens' StakePoolState (CompactForm Coin)
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps CompactForm Coin
d -> StakePoolState
sps {spsDeposit = d}

spsDelegatorsL :: Lens' StakePoolState (Set (Credential Staking))
spsDelegatorsL :: Lens' StakePoolState (Set (Credential Staking))
spsDelegatorsL = (StakePoolState -> Set (Credential Staking))
-> (StakePoolState -> Set (Credential Staking) -> StakePoolState)
-> Lens' StakePoolState (Set (Credential Staking))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolState -> Set (Credential Staking)
spsDelegators ((StakePoolState -> Set (Credential Staking) -> StakePoolState)
 -> Lens' StakePoolState (Set (Credential Staking)))
-> (StakePoolState -> Set (Credential Staking) -> StakePoolState)
-> Lens' StakePoolState (Set (Credential Staking))
forall a b. (a -> b) -> a -> b
$ \StakePoolState
sps Set (Credential Staking)
delegators -> StakePoolState
sps {spsDelegators = delegators}

instance EncCBOR StakePoolState where
  encCBOR :: StakePoolState -> Encoding
encCBOR StakePoolState
sps =
    Encode (Closed Dense) StakePoolState -> Encoding
forall (w :: Wrapped) t. Encode w t -> Encoding
encode (Encode (Closed Dense) StakePoolState -> Encoding)
-> Encode (Closed Dense) StakePoolState -> Encoding
forall a b. (a -> b) -> a -> b
$
      (VRFVerKeyHash StakePoolVRF
 -> StrictMaybe BlsKeyState
 -> Coin
 -> Coin
 -> UnitInterval
 -> AccountId
 -> Set (KeyHash Staking)
 -> StrictSeq StakePoolRelay
 -> StrictMaybe PoolMetadata
 -> CompactForm Coin
 -> Set (Credential Staking)
 -> StakePoolState)
-> Encode
     (Closed Dense)
     (VRFVerKeyHash StakePoolVRF
      -> StrictMaybe BlsKeyState
      -> Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall t. t -> Encode (Closed Dense) t
Rec VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKeyState
-> Coin
-> Coin
-> UnitInterval
-> AccountId
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> CompactForm Coin
-> Set (Credential Staking)
-> StakePoolState
StakePoolState
        Encode
  (Closed Dense)
  (VRFVerKeyHash StakePoolVRF
   -> StrictMaybe BlsKeyState
   -> Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) (VRFVerKeyHash StakePoolVRF)
-> Encode
     (Closed Dense)
     (StrictMaybe BlsKeyState
      -> Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> VRFVerKeyHash StakePoolVRF
-> Encode (Closed Dense) (VRFVerKeyHash StakePoolVRF)
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> VRFVerKeyHash StakePoolVRF
spsVrf StakePoolState
sps)
        Encode
  (Closed Dense)
  (StrictMaybe BlsKeyState
   -> Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) (StrictMaybe BlsKeyState)
-> Encode
     (Closed Dense)
     (Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> StrictMaybe BlsKeyState
-> Encode (Closed Dense) (StrictMaybe BlsKeyState)
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> StrictMaybe BlsKeyState
spsBlsKey StakePoolState
sps)
        Encode
  (Closed Dense)
  (Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) Coin
-> Encode
     (Closed Dense)
     (Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> Coin -> Encode (Closed Dense) Coin
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> Coin
spsPledge StakePoolState
sps)
        Encode
  (Closed Dense)
  (Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) Coin
-> Encode
     (Closed Dense)
     (UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> Coin -> Encode (Closed Dense) Coin
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> Coin
spsCost StakePoolState
sps)
        Encode
  (Closed Dense)
  (UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) UnitInterval
-> Encode
     (Closed Dense)
     (AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> UnitInterval -> Encode (Closed Dense) UnitInterval
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> UnitInterval
spsMargin StakePoolState
sps)
        Encode
  (Closed Dense)
  (AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) AccountId
-> Encode
     (Closed Dense)
     (Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> AccountId -> Encode (Closed Dense) AccountId
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> AccountId
spsAccountId StakePoolState
sps)
        Encode
  (Closed Dense)
  (Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) (Set (KeyHash Staking))
-> Encode
     (Closed Dense)
     (StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> Set (KeyHash Staking)
-> Encode (Closed Dense) (Set (KeyHash Staking))
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> Set (KeyHash Staking)
spsOwners StakePoolState
sps)
        Encode
  (Closed Dense)
  (StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Encode (Closed Dense) (StrictSeq StakePoolRelay)
-> Encode
     (Closed Dense)
     (StrictMaybe PoolMetadata
      -> CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> StrictSeq StakePoolRelay
-> Encode (Closed Dense) (StrictSeq StakePoolRelay)
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> StrictSeq StakePoolRelay
spsRelays StakePoolState
sps)
        Encode
  (Closed Dense)
  (StrictMaybe PoolMetadata
   -> CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
-> Encode (Closed Dense) (StrictMaybe PoolMetadata)
-> Encode
     (Closed Dense)
     (CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> StrictMaybe PoolMetadata
-> Encode (Closed Dense) (StrictMaybe PoolMetadata)
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> StrictMaybe PoolMetadata
spsMetadata StakePoolState
sps)
        Encode
  (Closed Dense)
  (CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
-> Encode (Closed Dense) (CompactForm Coin)
-> Encode
     (Closed Dense) (Set (Credential Staking) -> StakePoolState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> CompactForm Coin -> Encode (Closed Dense) (CompactForm Coin)
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> CompactForm Coin
spsDeposit StakePoolState
sps)
        Encode (Closed Dense) (Set (Credential Staking) -> StakePoolState)
-> Encode (Closed Dense) (Set (Credential Staking))
-> Encode (Closed Dense) StakePoolState
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> Set (Credential Staking)
-> Encode (Closed Dense) (Set (Credential Staking))
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (StakePoolState -> Set (Credential Staking)
spsDelegators StakePoolState
sps)

instance DecCBOR StakePoolState where
  decCBOR :: forall s. Decoder s StakePoolState
decCBOR =
    Decode (Closed Dense) StakePoolState -> Decoder s StakePoolState
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode (Decode (Closed Dense) StakePoolState -> Decoder s StakePoolState)
-> Decode (Closed Dense) StakePoolState -> Decoder s StakePoolState
forall a b. (a -> b) -> a -> b
$
      (VRFVerKeyHash StakePoolVRF
 -> StrictMaybe BlsKeyState
 -> Coin
 -> Coin
 -> UnitInterval
 -> AccountId
 -> Set (KeyHash Staking)
 -> StrictSeq StakePoolRelay
 -> StrictMaybe PoolMetadata
 -> CompactForm Coin
 -> Set (Credential Staking)
 -> StakePoolState)
-> Decode
     (Closed Dense)
     (VRFVerKeyHash StakePoolVRF
      -> StrictMaybe BlsKeyState
      -> Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall t. t -> Decode (Closed Dense) t
RecD VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKeyState
-> Coin
-> Coin
-> UnitInterval
-> AccountId
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> CompactForm Coin
-> Set (Credential Staking)
-> StakePoolState
StakePoolState
        Decode
  (Closed Dense)
  (VRFVerKeyHash StakePoolVRF
   -> StrictMaybe BlsKeyState
   -> Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 10)) (VRFVerKeyHash StakePoolVRF)
-> Decode
     (Closed Dense)
     (StrictMaybe BlsKeyState
      -> Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 10)) (VRFVerKeyHash StakePoolVRF)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (StrictMaybe BlsKeyState
   -> Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 9)) (StrictMaybe BlsKeyState)
-> Decode
     (Closed Dense)
     (Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 9)) (StrictMaybe BlsKeyState)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 8)) Coin
-> Decode
     (Closed Dense)
     (Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 8)) Coin
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 7)) Coin
-> Decode
     (Closed Dense)
     (UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 7)) Coin
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 6)) UnitInterval
-> Decode
     (Closed Dense)
     (AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 6)) UnitInterval
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 5)) AccountId
-> Decode
     (Closed Dense)
     (Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 5)) AccountId
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 4)) (Set (KeyHash Staking))
-> Decode
     (Closed Dense)
     (StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 4)) (Set (KeyHash Staking))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> Decode (Closed (ZonkAny 3)) (StrictSeq StakePoolRelay)
-> Decode
     (Closed Dense)
     (StrictMaybe PoolMetadata
      -> CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 3)) (StrictSeq StakePoolRelay)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (StrictMaybe PoolMetadata
   -> CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
-> Decode (Closed (ZonkAny 2)) (StrictMaybe PoolMetadata)
-> Decode
     (Closed Dense)
     (CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 2)) (StrictMaybe PoolMetadata)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode
  (Closed Dense)
  (CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
-> Decode (Closed (ZonkAny 1)) (CompactForm Coin)
-> Decode
     (Closed Dense) (Set (Credential Staking) -> StakePoolState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 1)) (CompactForm Coin)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode (Closed Dense) (Set (Credential Staking) -> StakePoolState)
-> Decode (Closed (ZonkAny 0)) (Set (Credential Staking))
-> Decode (Closed Dense) StakePoolState
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 0)) (Set (Credential Staking))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From

instance DecShareCBOR StakePoolState where
  type Share StakePoolState = Interns (Credential Staking)
  decSharePlusCBOR :: forall s. StateT (Share StakePoolState) (Decoder s) StakePoolState
decSharePlusCBOR =
    Text
-> (StakePoolState -> Int)
-> StateT (Share StakePoolState) (Decoder s) StakePoolState
-> StateT (Share StakePoolState) (Decoder s) StakePoolState
forall (m :: (* -> *) -> * -> *) s a.
(MonadTrans m, Monad (m (Decoder s))) =>
Text -> (a -> Int) -> m (Decoder s) a -> m (Decoder s) a
decodeRecordNamedT Text
"StakePoolState" (Int -> StakePoolState -> Int
forall a b. a -> b -> a
const Int
11) (StateT (Share StakePoolState) (Decoder s) StakePoolState
 -> StateT (Share StakePoolState) (Decoder s) StakePoolState)
-> StateT (Share StakePoolState) (Decoder s) StakePoolState
-> StateT (Share StakePoolState) (Decoder s) StakePoolState
forall a b. (a -> b) -> a -> b
$
      VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKeyState
-> Coin
-> Coin
-> UnitInterval
-> AccountId
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> CompactForm Coin
-> Set (Credential Staking)
-> StakePoolState
StakePoolState
        (VRFVerKeyHash StakePoolVRF
 -> StrictMaybe BlsKeyState
 -> Coin
 -> Coin
 -> UnitInterval
 -> AccountId
 -> Set (KeyHash Staking)
 -> StrictSeq StakePoolRelay
 -> StrictMaybe PoolMetadata
 -> CompactForm Coin
 -> Set (Credential Staking)
 -> StakePoolState)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (VRFVerKeyHash StakePoolVRF)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictMaybe BlsKeyState
      -> Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (VRFVerKeyHash StakePoolVRF)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (VRFVerKeyHash StakePoolVRF)
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s (VRFVerKeyHash StakePoolVRF)
forall s. Decoder s (VRFVerKeyHash StakePoolVRF)
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (StrictMaybe BlsKeyState
   -> Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictMaybe BlsKeyState)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (Coin
      -> Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (StrictMaybe BlsKeyState)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictMaybe BlsKeyState)
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s (StrictMaybe BlsKeyState)
forall s. Decoder s (StrictMaybe BlsKeyState)
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (Coin
   -> Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> StateT (Interns (Credential Staking)) (Decoder s) Coin
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (Coin
      -> UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Coin
-> StateT (Interns (Credential Staking)) (Decoder s) Coin
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s Coin
forall s. Decoder s Coin
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (Coin
   -> UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> StateT (Interns (Credential Staking)) (Decoder s) Coin
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (UnitInterval
      -> AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Coin
-> StateT (Interns (Credential Staking)) (Decoder s) Coin
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s Coin
forall s. Decoder s Coin
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (UnitInterval
   -> AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> StateT (Interns (Credential Staking)) (Decoder s) UnitInterval
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (AccountId
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s UnitInterval
-> StateT (Interns (Credential Staking)) (Decoder s) UnitInterval
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s UnitInterval
forall s. Decoder s UnitInterval
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (AccountId
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> StateT (Interns (Credential Staking)) (Decoder s) AccountId
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s AccountId
-> StateT (Interns (Credential Staking)) (Decoder s) AccountId
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s AccountId
forall s. Decoder s AccountId
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> StateT
     (Interns (Credential Staking)) (Decoder s) (Set (KeyHash Staking))
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> CompactForm Coin
      -> Set (Credential Staking)
      -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (Set (KeyHash Staking))
-> StateT
     (Interns (Credential Staking)) (Decoder s) (Set (KeyHash Staking))
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s (Set (KeyHash Staking))
forall s. Decoder s (Set (KeyHash Staking))
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> CompactForm Coin
   -> Set (Credential Staking)
   -> StakePoolState)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictSeq StakePoolRelay)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictMaybe PoolMetadata
      -> CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (StrictSeq StakePoolRelay)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictSeq StakePoolRelay)
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s (StrictSeq StakePoolRelay)
forall s. Decoder s (StrictSeq StakePoolRelay)
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (StrictMaybe PoolMetadata
   -> CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictMaybe PoolMetadata)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (StrictMaybe PoolMetadata)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (StrictMaybe PoolMetadata)
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s (StrictMaybe PoolMetadata)
forall s. Decoder s (StrictMaybe PoolMetadata)
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (CompactForm Coin -> Set (Credential Staking) -> StakePoolState)
-> StateT
     (Interns (Credential Staking)) (Decoder s) (CompactForm Coin)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (Set (Credential Staking) -> StakePoolState)
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (CompactForm Coin)
-> StateT
     (Interns (Credential Staking)) (Decoder s) (CompactForm Coin)
forall (m :: * -> *) a.
Monad m =>
m a -> StateT (Interns (Credential Staking)) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s (CompactForm Coin)
forall s. Decoder s (CompactForm Coin)
forall a s. DecCBOR a => Decoder s a
decCBOR
        StateT
  (Interns (Credential Staking))
  (Decoder s)
  (Set (Credential Staking) -> StakePoolState)
-> StateT
     (Interns (Credential Staking))
     (Decoder s)
     (Set (Credential Staking))
-> StateT (Interns (Credential Staking)) (Decoder s) StakePoolState
forall a b.
StateT (Interns (Credential Staking)) (Decoder s) (a -> b)
-> StateT (Interns (Credential Staking)) (Decoder s) a
-> StateT (Interns (Credential Staking)) (Decoder s) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> StateT
  (Share (Set (Credential Staking)))
  (Decoder s)
  (Set (Credential Staking))
StateT
  (Interns (Credential Staking))
  (Decoder s)
  (Set (Credential Staking))
forall s.
StateT
  (Share (Set (Credential Staking)))
  (Decoder s)
  (Set (Credential Staking))
forall a s. DecShareCBOR a => StateT (Share a) (Decoder s) a
decSharePlusCBOR

instance Default StakePoolState where
  def :: StakePoolState
def =
    StakePoolState
      { spsVrf :: VRFVerKeyHash StakePoolVRF
spsVrf = VRFVerKeyHash StakePoolVRF
forall a. Default a => a
def
      , spsBlsKey :: StrictMaybe BlsKeyState
spsBlsKey = StrictMaybe BlsKeyState
forall a. Default a => a
def
      , spsPledge :: Coin
spsPledge = Integer -> Coin
Coin Integer
0
      , spsCost :: Coin
spsCost = Integer -> Coin
Coin Integer
0
      , spsMargin :: UnitInterval
spsMargin = UnitInterval
forall a. Default a => a
def
      , spsAccountId :: AccountId
spsAccountId = Credential Staking -> AccountId
AccountId Credential Staking
forall a. Default a => a
def
      , spsOwners :: Set (KeyHash Staking)
spsOwners = Set (KeyHash Staking)
forall a. Default a => a
def
      , spsRelays :: StrictSeq StakePoolRelay
spsRelays = StrictSeq StakePoolRelay
forall a. Default a => a
def
      , spsMetadata :: StrictMaybe PoolMetadata
spsMetadata = StrictMaybe PoolMetadata
forall a. Default a => a
def
      , spsDeposit :: CompactForm Coin
spsDeposit = CompactForm Coin
forall a. Monoid a => a
mempty
      , spsDelegators :: Set (Credential Staking)
spsDelegators = Set (Credential Staking)
forall a. Default a => a
def
      }

-- | Convert 'StakePoolParams' to 'StakePoolState' by dropping the pool ID.
-- This is the primary way to create a 'StakePoolState' from registration
-- or update parameters. The epoch is the one the parameters take effect in:
-- a voting key carried by the parameters is stamped with it, so registering
-- again renews the key.
mkStakePoolState ::
  EpochNo -> CompactForm Coin -> Set (Credential Staking) -> StakePoolParams era -> StakePoolState
mkStakePoolState :: forall era.
EpochNo
-> CompactForm Coin
-> Set (Credential Staking)
-> StakePoolParams era
-> StakePoolState
mkStakePoolState EpochNo
epochNo CompactForm Coin
deposit Set (Credential Staking)
delegators StakePoolParams era
spp =
  StakePoolState
    { spsVrf :: VRFVerKeyHash StakePoolVRF
spsVrf = StakePoolParams era -> VRFVerKeyHash StakePoolVRF
forall era. StakePoolParams era -> VRFVerKeyHash StakePoolVRF
sppVrf StakePoolParams era
spp
    , spsBlsKey :: StrictMaybe BlsKeyState
spsBlsKey = (BlsKey -> EpochNo -> BlsKeyState
`BlsKeyState` EpochNo
epochNo) (BlsKey -> BlsKeyState)
-> StrictMaybe BlsKey -> StrictMaybe BlsKeyState
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StakePoolParams era -> StrictMaybe BlsKey
forall era. StakePoolParams era -> StrictMaybe BlsKey
sppBlsKey StakePoolParams era
spp
    , spsPledge :: Coin
spsPledge = StakePoolParams era -> Coin
forall era. StakePoolParams era -> Coin
sppPledge StakePoolParams era
spp
    , spsCost :: Coin
spsCost = StakePoolParams era -> Coin
forall era. StakePoolParams era -> Coin
sppCost StakePoolParams era
spp
    , spsMargin :: UnitInterval
spsMargin = StakePoolParams era -> UnitInterval
forall era. StakePoolParams era -> UnitInterval
sppMargin StakePoolParams era
spp
    , spsAccountId :: AccountId
spsAccountId = AccountAddress -> AccountId
aaId (StakePoolParams era -> AccountAddress
forall era. StakePoolParams era -> AccountAddress
sppAccountAddress StakePoolParams era
spp)
    , spsOwners :: Set (KeyHash Staking)
spsOwners = StakePoolParams era -> Set (KeyHash Staking)
forall era. StakePoolParams era -> Set (KeyHash Staking)
sppOwners StakePoolParams era
spp
    , spsRelays :: StrictSeq StakePoolRelay
spsRelays = StakePoolParams era -> StrictSeq StakePoolRelay
forall era. StakePoolParams era -> StrictSeq StakePoolRelay
sppRelays StakePoolParams era
spp
    , spsMetadata :: StrictMaybe PoolMetadata
spsMetadata = StakePoolParams era -> StrictMaybe PoolMetadata
forall era. StakePoolParams era -> StrictMaybe PoolMetadata
sppMetadata StakePoolParams era
spp
    , spsDeposit :: CompactForm Coin
spsDeposit = CompactForm Coin
deposit
    , spsDelegators :: Set (Credential Staking)
spsDelegators = Set (Credential Staking)
delegators
    }

-- | Convert 'StakePoolState' back to 'StakePoolParams' by providing the pool ID.
-- This is useful when you need to reconstruct the full parameters from
-- the state representation.
stakePoolStateToStakePoolParams ::
  Network -> KeyHash StakePool -> StakePoolState -> StakePoolParams era
stakePoolStateToStakePoolParams :: forall era.
Network
-> KeyHash StakePool -> StakePoolState -> StakePoolParams era
stakePoolStateToStakePoolParams Network
networkId KeyHash StakePool
poolId StakePoolState
sps =
  StakePoolParams
    { sppId :: KeyHash StakePool
sppId = KeyHash StakePool
poolId
    , sppVrf :: VRFVerKeyHash StakePoolVRF
sppVrf = StakePoolState -> VRFVerKeyHash StakePoolVRF
spsVrf StakePoolState
sps
    , sppBlsKey :: StrictMaybe BlsKey
sppBlsKey = BlsKeyState -> BlsKey
bksKey (BlsKeyState -> BlsKey)
-> StrictMaybe BlsKeyState -> StrictMaybe BlsKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> StakePoolState -> StrictMaybe BlsKeyState
spsBlsKey StakePoolState
sps
    , sppPledge :: Coin
sppPledge = StakePoolState -> Coin
spsPledge StakePoolState
sps
    , sppCost :: Coin
sppCost = StakePoolState -> Coin
spsCost StakePoolState
sps
    , sppMargin :: UnitInterval
sppMargin = StakePoolState -> UnitInterval
spsMargin StakePoolState
sps
    , sppAccountAddress :: AccountAddress
sppAccountAddress =
        AccountAddress
          { aaNetworkId :: Network
aaNetworkId = Network
networkId
          , aaId :: AccountId
aaId = StakePoolState -> AccountId
spsAccountId StakePoolState
sps
          }
    , sppOwners :: Set (KeyHash Staking)
sppOwners = StakePoolState -> Set (KeyHash Staking)
spsOwners StakePoolState
sps
    , sppRelays :: StrictSeq StakePoolRelay
sppRelays = StakePoolState -> StrictSeq StakePoolRelay
spsRelays StakePoolState
sps
    , sppMetadata :: StrictMaybe PoolMetadata
sppMetadata = StakePoolState -> StrictMaybe PoolMetadata
spsMetadata StakePoolState
sps
    }

data PoolMetadata = PoolMetadata
  { PoolMetadata -> Url
pmUrl :: !Url
  , PoolMetadata -> ByteArray
pmHash :: !ByteArray
  }
  deriving (PoolMetadata -> PoolMetadata -> Bool
(PoolMetadata -> PoolMetadata -> Bool)
-> (PoolMetadata -> PoolMetadata -> Bool) -> Eq PoolMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PoolMetadata -> PoolMetadata -> Bool
== :: PoolMetadata -> PoolMetadata -> Bool
$c/= :: PoolMetadata -> PoolMetadata -> Bool
/= :: PoolMetadata -> PoolMetadata -> Bool
Eq, Eq PoolMetadata
Eq PoolMetadata =>
(PoolMetadata -> PoolMetadata -> Ordering)
-> (PoolMetadata -> PoolMetadata -> Bool)
-> (PoolMetadata -> PoolMetadata -> Bool)
-> (PoolMetadata -> PoolMetadata -> Bool)
-> (PoolMetadata -> PoolMetadata -> Bool)
-> (PoolMetadata -> PoolMetadata -> PoolMetadata)
-> (PoolMetadata -> PoolMetadata -> PoolMetadata)
-> Ord PoolMetadata
PoolMetadata -> PoolMetadata -> Bool
PoolMetadata -> PoolMetadata -> Ordering
PoolMetadata -> PoolMetadata -> PoolMetadata
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 :: PoolMetadata -> PoolMetadata -> Ordering
compare :: PoolMetadata -> PoolMetadata -> Ordering
$c< :: PoolMetadata -> PoolMetadata -> Bool
< :: PoolMetadata -> PoolMetadata -> Bool
$c<= :: PoolMetadata -> PoolMetadata -> Bool
<= :: PoolMetadata -> PoolMetadata -> Bool
$c> :: PoolMetadata -> PoolMetadata -> Bool
> :: PoolMetadata -> PoolMetadata -> Bool
$c>= :: PoolMetadata -> PoolMetadata -> Bool
>= :: PoolMetadata -> PoolMetadata -> Bool
$cmax :: PoolMetadata -> PoolMetadata -> PoolMetadata
max :: PoolMetadata -> PoolMetadata -> PoolMetadata
$cmin :: PoolMetadata -> PoolMetadata -> PoolMetadata
min :: PoolMetadata -> PoolMetadata -> PoolMetadata
Ord, (forall x. PoolMetadata -> Rep PoolMetadata x)
-> (forall x. Rep PoolMetadata x -> PoolMetadata)
-> Generic PoolMetadata
forall x. Rep PoolMetadata x -> PoolMetadata
forall x. PoolMetadata -> Rep PoolMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PoolMetadata -> Rep PoolMetadata x
from :: forall x. PoolMetadata -> Rep PoolMetadata x
$cto :: forall x. Rep PoolMetadata x -> PoolMetadata
to :: forall x. Rep PoolMetadata x -> PoolMetadata
Generic, Int -> PoolMetadata -> ShowS
[PoolMetadata] -> ShowS
PoolMetadata -> String
(Int -> PoolMetadata -> ShowS)
-> (PoolMetadata -> String)
-> ([PoolMetadata] -> ShowS)
-> Show PoolMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PoolMetadata -> ShowS
showsPrec :: Int -> PoolMetadata -> ShowS
$cshow :: PoolMetadata -> String
show :: PoolMetadata -> String
$cshowList :: [PoolMetadata] -> ShowS
showList :: [PoolMetadata] -> ShowS
Show)

deriving instance NFData PoolMetadata

instance ToJSON PoolMetadata where
  toJSON :: PoolMetadata -> Value
toJSON PoolMetadata
pmd =
    [Pair] -> Value
Aeson.object
      [ Key
"url" Key -> Url -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= PoolMetadata -> Url
pmUrl PoolMetadata
pmd
      , Key
"hash" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ByteString -> Text
Text.decodeLatin1 (ByteString -> ByteString
B16.encode (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ ShortByteString -> ByteString
SBS.fromShort (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ ByteArray -> ShortByteString
byteArrayToShortByteString (ByteArray -> ShortByteString) -> ByteArray -> ShortByteString
forall a b. (a -> b) -> a -> b
$ PoolMetadata -> ByteArray
pmHash PoolMetadata
pmd)
      ]

instance FromJSON PoolMetadata where
  parseJSON :: Value -> Parser PoolMetadata
parseJSON =
    String
-> (Object -> Parser PoolMetadata) -> Value -> Parser PoolMetadata
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"PoolMetadata" ((Object -> Parser PoolMetadata) -> Value -> Parser PoolMetadata)
-> (Object -> Parser PoolMetadata) -> Value -> Parser PoolMetadata
forall a b. (a -> b) -> a -> b
$ \Object
obj -> do
      url <- Object
obj Object -> Key -> Parser Url
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"url"
      hash <- explicitParseField parseJsonBase16 obj "hash"
      return $ PoolMetadata url hash

parseJsonBase16 :: Value -> Parser ByteArray
parseJsonBase16 :: Value -> Parser ByteArray
parseJsonBase16 Value
v = do
  txt <- Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v
  unless (Text.isAscii txt) $ fail $ "Supplied text contains non-ASCII characters: " <> show txt
  case B16.decode $ Text.encodeUtf8 txt of
    Right ByteString
bs -> ByteArray -> Parser ByteArray
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray -> Parser ByteArray) -> ByteArray -> Parser ByteArray
forall a b. (a -> b) -> a -> b
$ ShortByteString -> ByteArray
byteArrayFromShortByteString (ShortByteString -> ByteArray) -> ShortByteString -> ByteArray
forall a b. (a -> b) -> a -> b
$ ByteString -> ShortByteString
SBS.toShort ByteString
bs
    Left String
msg -> String -> Parser ByteArray
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
msg

-- | Check WHNF by pattern-matching on both fields, since they both are strict, and just contain ByteArray#
instance NoThunks PoolMetadata where
  wNoThunks :: Context -> PoolMetadata -> IO (Maybe ThunkInfo)
wNoThunks Context
_ (PoolMetadata Url
_ ByteArray
_) = Maybe ThunkInfo -> IO (Maybe ThunkInfo)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ThunkInfo
forall a. Maybe a
Nothing
  showTypeOf :: Proxy PoolMetadata -> String
showTypeOf Proxy PoolMetadata
_ = String
"PoolMetadata"

data StakePoolRelay
  = -- | One or both of IPv4 & IPv6
    SingleHostAddr !(StrictMaybe Port) !(StrictMaybe IPv4) !(StrictMaybe IPv6)
  | -- | An @A@ or @AAAA@ DNS record
    SingleHostName !(StrictMaybe Port) !DnsName
  | -- | A @SRV@ DNS record
    MultiHostName !DnsName
  deriving (StakePoolRelay -> StakePoolRelay -> Bool
(StakePoolRelay -> StakePoolRelay -> Bool)
-> (StakePoolRelay -> StakePoolRelay -> Bool) -> Eq StakePoolRelay
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StakePoolRelay -> StakePoolRelay -> Bool
== :: StakePoolRelay -> StakePoolRelay -> Bool
$c/= :: StakePoolRelay -> StakePoolRelay -> Bool
/= :: StakePoolRelay -> StakePoolRelay -> Bool
Eq, Eq StakePoolRelay
Eq StakePoolRelay =>
(StakePoolRelay -> StakePoolRelay -> Ordering)
-> (StakePoolRelay -> StakePoolRelay -> Bool)
-> (StakePoolRelay -> StakePoolRelay -> Bool)
-> (StakePoolRelay -> StakePoolRelay -> Bool)
-> (StakePoolRelay -> StakePoolRelay -> Bool)
-> (StakePoolRelay -> StakePoolRelay -> StakePoolRelay)
-> (StakePoolRelay -> StakePoolRelay -> StakePoolRelay)
-> Ord StakePoolRelay
StakePoolRelay -> StakePoolRelay -> Bool
StakePoolRelay -> StakePoolRelay -> Ordering
StakePoolRelay -> StakePoolRelay -> StakePoolRelay
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 :: StakePoolRelay -> StakePoolRelay -> Ordering
compare :: StakePoolRelay -> StakePoolRelay -> Ordering
$c< :: StakePoolRelay -> StakePoolRelay -> Bool
< :: StakePoolRelay -> StakePoolRelay -> Bool
$c<= :: StakePoolRelay -> StakePoolRelay -> Bool
<= :: StakePoolRelay -> StakePoolRelay -> Bool
$c> :: StakePoolRelay -> StakePoolRelay -> Bool
> :: StakePoolRelay -> StakePoolRelay -> Bool
$c>= :: StakePoolRelay -> StakePoolRelay -> Bool
>= :: StakePoolRelay -> StakePoolRelay -> Bool
$cmax :: StakePoolRelay -> StakePoolRelay -> StakePoolRelay
max :: StakePoolRelay -> StakePoolRelay -> StakePoolRelay
$cmin :: StakePoolRelay -> StakePoolRelay -> StakePoolRelay
min :: StakePoolRelay -> StakePoolRelay -> StakePoolRelay
Ord, (forall x. StakePoolRelay -> Rep StakePoolRelay x)
-> (forall x. Rep StakePoolRelay x -> StakePoolRelay)
-> Generic StakePoolRelay
forall x. Rep StakePoolRelay x -> StakePoolRelay
forall x. StakePoolRelay -> Rep StakePoolRelay x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. StakePoolRelay -> Rep StakePoolRelay x
from :: forall x. StakePoolRelay -> Rep StakePoolRelay x
$cto :: forall x. Rep StakePoolRelay x -> StakePoolRelay
to :: forall x. Rep StakePoolRelay x -> StakePoolRelay
Generic, Int -> StakePoolRelay -> ShowS
[StakePoolRelay] -> ShowS
StakePoolRelay -> String
(Int -> StakePoolRelay -> ShowS)
-> (StakePoolRelay -> String)
-> ([StakePoolRelay] -> ShowS)
-> Show StakePoolRelay
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StakePoolRelay -> ShowS
showsPrec :: Int -> StakePoolRelay -> ShowS
$cshow :: StakePoolRelay -> String
show :: StakePoolRelay -> String
$cshowList :: [StakePoolRelay] -> ShowS
showList :: [StakePoolRelay] -> ShowS
Show)

instance FromJSON StakePoolRelay where
  parseJSON :: Value -> Parser StakePoolRelay
parseJSON =
    String
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"StakePoolRelay" ((Object -> Parser StakePoolRelay)
 -> Value -> Parser StakePoolRelay)
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
      [Parser StakePoolRelay] -> Parser StakePoolRelay
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
        [ (Value -> Parser StakePoolRelay)
-> Object -> Key -> Parser StakePoolRelay
forall a. (Value -> Parser a) -> Object -> Key -> Parser a
explicitParseField Value -> Parser StakePoolRelay
parser1 Object
obj Key
"single host address"
        , (Value -> Parser StakePoolRelay)
-> Object -> Key -> Parser StakePoolRelay
forall a. (Value -> Parser a) -> Object -> Key -> Parser a
explicitParseField Value -> Parser StakePoolRelay
parser2 Object
obj Key
"single host name"
        , (Value -> Parser StakePoolRelay)
-> Object -> Key -> Parser StakePoolRelay
forall a. (Value -> Parser a) -> Object -> Key -> Parser a
explicitParseField Value -> Parser StakePoolRelay
parser3 Object
obj Key
"multi host name"
        ]
    where
      parser1 :: Value -> Parser StakePoolRelay
parser1 = String
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"SingleHostAddr" ((Object -> Parser StakePoolRelay)
 -> Value -> Parser StakePoolRelay)
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
        StrictMaybe Port
-> StrictMaybe IPv4 -> StrictMaybe IPv6 -> StakePoolRelay
SingleHostAddr
          (StrictMaybe Port
 -> StrictMaybe IPv4 -> StrictMaybe IPv6 -> StakePoolRelay)
-> Parser (StrictMaybe Port)
-> Parser (StrictMaybe IPv4 -> StrictMaybe IPv6 -> StakePoolRelay)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Maybe (StrictMaybe Port))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"port" Parser (Maybe (StrictMaybe Port))
-> StrictMaybe Port -> Parser (StrictMaybe Port)
forall a. Parser (Maybe a) -> a -> Parser a
.!= StrictMaybe Port
forall a. StrictMaybe a
SNothing
          Parser (StrictMaybe IPv4 -> StrictMaybe IPv6 -> StakePoolRelay)
-> Parser (StrictMaybe IPv4)
-> Parser (StrictMaybe IPv6 -> StakePoolRelay)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Maybe (StrictMaybe IPv4))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"IPv4" Parser (Maybe (StrictMaybe IPv4))
-> StrictMaybe IPv4 -> Parser (StrictMaybe IPv4)
forall a. Parser (Maybe a) -> a -> Parser a
.!= StrictMaybe IPv4
forall a. StrictMaybe a
SNothing
          Parser (StrictMaybe IPv6 -> StakePoolRelay)
-> Parser (StrictMaybe IPv6) -> Parser StakePoolRelay
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Maybe (StrictMaybe IPv6))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"IPv6" Parser (Maybe (StrictMaybe IPv6))
-> StrictMaybe IPv6 -> Parser (StrictMaybe IPv6)
forall a. Parser (Maybe a) -> a -> Parser a
.!= StrictMaybe IPv6
forall a. StrictMaybe a
SNothing
      parser2 :: Value -> Parser StakePoolRelay
parser2 = String
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"SingleHostName" ((Object -> Parser StakePoolRelay)
 -> Value -> Parser StakePoolRelay)
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
        StrictMaybe Port -> DnsName -> StakePoolRelay
SingleHostName
          (StrictMaybe Port -> DnsName -> StakePoolRelay)
-> Parser (StrictMaybe Port) -> Parser (DnsName -> StakePoolRelay)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Maybe (StrictMaybe Port))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"port" Parser (Maybe (StrictMaybe Port))
-> StrictMaybe Port -> Parser (StrictMaybe Port)
forall a. Parser (Maybe a) -> a -> Parser a
.!= StrictMaybe Port
forall a. StrictMaybe a
SNothing
          Parser (DnsName -> StakePoolRelay)
-> Parser DnsName -> Parser StakePoolRelay
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser DnsName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"dnsName"
      parser3 :: Value -> Parser StakePoolRelay
parser3 = String
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"MultiHostName" ((Object -> Parser StakePoolRelay)
 -> Value -> Parser StakePoolRelay)
-> (Object -> Parser StakePoolRelay)
-> Value
-> Parser StakePoolRelay
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
        DnsName -> StakePoolRelay
MultiHostName
          (DnsName -> StakePoolRelay)
-> Parser DnsName -> Parser StakePoolRelay
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser DnsName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"dnsName"

instance ToJSON StakePoolRelay where
  toJSON :: StakePoolRelay -> Value
toJSON (SingleHostAddr StrictMaybe Port
port StrictMaybe IPv4
ipv4 StrictMaybe IPv6
ipv6) =
    [Pair] -> Value
Aeson.object
      [ Key
"single host address"
          Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
Aeson.object
            [ Key
"port" Key -> StrictMaybe Port -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StrictMaybe Port
port
            , Key
"IPv4" Key -> StrictMaybe IPv4 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StrictMaybe IPv4
ipv4
            , Key
"IPv6" Key -> StrictMaybe IPv6 -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StrictMaybe IPv6
ipv6
            ]
      ]
  toJSON (SingleHostName StrictMaybe Port
port DnsName
dnsName) =
    [Pair] -> Value
Aeson.object
      [ Key
"single host name"
          Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
Aeson.object
            [ Key
"port" Key -> StrictMaybe Port -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StrictMaybe Port
port
            , Key
"dnsName" Key -> DnsName -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= DnsName
dnsName
            ]
      ]
  toJSON (MultiHostName DnsName
dnsName) =
    [Pair] -> Value
Aeson.object
      [ Key
"multi host name"
          Key -> Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [Pair] -> Value
Aeson.object
            [ Key
"dnsName" Key -> DnsName -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= DnsName
dnsName
            ]
      ]

instance NoThunks StakePoolRelay

instance NFData StakePoolRelay

instance EncCBOR StakePoolRelay where
  encCBOR :: StakePoolRelay -> Encoding
encCBOR (SingleHostAddr StrictMaybe Port
p StrictMaybe IPv4
ipv4 StrictMaybe IPv6
ipv6) =
    Word -> Encoding
encodeListLen Word
4
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word8
0 :: Word8)
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (Port -> Encoding) -> StrictMaybe Port -> Encoding
forall a. (a -> Encoding) -> StrictMaybe a -> Encoding
encodeNullStrictMaybe Port -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe Port
p
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (IPv4 -> Encoding) -> StrictMaybe IPv4 -> Encoding
forall a. (a -> Encoding) -> StrictMaybe a -> Encoding
encodeNullStrictMaybe IPv4 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe IPv4
ipv4
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (IPv6 -> Encoding) -> StrictMaybe IPv6 -> Encoding
forall a. (a -> Encoding) -> StrictMaybe a -> Encoding
encodeNullStrictMaybe IPv6 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe IPv6
ipv6
  encCBOR (SingleHostName StrictMaybe Port
p DnsName
n) =
    Word -> Encoding
encodeListLen Word
3
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word8
1 :: Word8)
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (Port -> Encoding) -> StrictMaybe Port -> Encoding
forall a. (a -> Encoding) -> StrictMaybe a -> Encoding
encodeNullStrictMaybe Port -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR StrictMaybe Port
p
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> DnsName -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR DnsName
n
  encCBOR (MultiHostName DnsName
n) =
    Word -> Encoding
encodeListLen Word
2
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word8
2 :: Word8)
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> DnsName -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR DnsName
n

instance DecCBOR StakePoolRelay where
  decCBOR :: forall s. Decoder s StakePoolRelay
decCBOR = Text
-> (Word -> Decoder s (Int, StakePoolRelay))
-> Decoder s StakePoolRelay
forall s a. Text -> (Word -> Decoder s (Int, a)) -> Decoder s a
decodeRecordSum Text
"StakePoolRelay" ((Word -> Decoder s (Int, StakePoolRelay))
 -> Decoder s StakePoolRelay)
-> (Word -> Decoder s (Int, StakePoolRelay))
-> Decoder s StakePoolRelay
forall a b. (a -> b) -> a -> b
$
    \case
      Word
0 ->
        (\StrictMaybe Port
x StrictMaybe IPv4
y StrictMaybe IPv6
z -> (Int
4, StrictMaybe Port
-> StrictMaybe IPv4 -> StrictMaybe IPv6 -> StakePoolRelay
SingleHostAddr StrictMaybe Port
x StrictMaybe IPv4
y StrictMaybe IPv6
z))
          (StrictMaybe Port
 -> StrictMaybe IPv4 -> StrictMaybe IPv6 -> (Int, StakePoolRelay))
-> Decoder s (StrictMaybe Port)
-> Decoder
     s (StrictMaybe IPv4 -> StrictMaybe IPv6 -> (Int, StakePoolRelay))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Port -> Decoder s (StrictMaybe Port)
forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeNullStrictMaybe Decoder s Port
forall s. Decoder s Port
forall a s. DecCBOR a => Decoder s a
decCBOR
          Decoder
  s (StrictMaybe IPv4 -> StrictMaybe IPv6 -> (Int, StakePoolRelay))
-> Decoder s (StrictMaybe IPv4)
-> Decoder s (StrictMaybe IPv6 -> (Int, StakePoolRelay))
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s IPv4 -> Decoder s (StrictMaybe IPv4)
forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeNullStrictMaybe Decoder s IPv4
forall s. Decoder s IPv4
forall a s. DecCBOR a => Decoder s a
decCBOR
          Decoder s (StrictMaybe IPv6 -> (Int, StakePoolRelay))
-> Decoder s (StrictMaybe IPv6) -> Decoder s (Int, StakePoolRelay)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s IPv6 -> Decoder s (StrictMaybe IPv6)
forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeNullStrictMaybe Decoder s IPv6
forall s. Decoder s IPv6
forall a s. DecCBOR a => Decoder s a
decCBOR
      Word
1 ->
        (\StrictMaybe Port
x DnsName
y -> (Int
3, StrictMaybe Port -> DnsName -> StakePoolRelay
SingleHostName StrictMaybe Port
x DnsName
y))
          (StrictMaybe Port -> DnsName -> (Int, StakePoolRelay))
-> Decoder s (StrictMaybe Port)
-> Decoder s (DnsName -> (Int, StakePoolRelay))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Port -> Decoder s (StrictMaybe Port)
forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeNullStrictMaybe Decoder s Port
forall s. Decoder s Port
forall a s. DecCBOR a => Decoder s a
decCBOR
          Decoder s (DnsName -> (Int, StakePoolRelay))
-> Decoder s DnsName -> Decoder s (Int, StakePoolRelay)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s DnsName
forall s. Decoder s DnsName
forall a s. DecCBOR a => Decoder s a
decCBOR
      Word
2 -> do
        x <- Decoder s DnsName
forall s. Decoder s DnsName
forall a s. DecCBOR a => Decoder s a
decCBOR
        pure (2, MultiHostName x)
      Word
k -> Word -> Decoder s (Int, StakePoolRelay)
forall a (m :: * -> *). (Typeable a, MonadFail m) => Word -> m a
invalidKey Word
k

-- | A stake pool.
data StakePoolParams era = StakePoolParams
  { forall era. StakePoolParams era -> KeyHash StakePool
sppId :: !(KeyHash StakePool)
  , forall era. StakePoolParams era -> VRFVerKeyHash StakePoolVRF
sppVrf :: !(VRFVerKeyHash StakePoolVRF)
  , forall era. StakePoolParams era -> StrictMaybe BlsKey
sppBlsKey :: !(StrictMaybe BlsKey)
  , forall era. StakePoolParams era -> Coin
sppPledge :: !Coin
  , forall era. StakePoolParams era -> Coin
sppCost :: !Coin
  , forall era. StakePoolParams era -> UnitInterval
sppMargin :: !UnitInterval
  , forall era. StakePoolParams era -> AccountAddress
sppAccountAddress :: !AccountAddress
  , forall era. StakePoolParams era -> Set (KeyHash Staking)
sppOwners :: !(Set (KeyHash Staking))
  , forall era. StakePoolParams era -> StrictSeq StakePoolRelay
sppRelays :: !(StrictSeq StakePoolRelay)
  , forall era. StakePoolParams era -> StrictMaybe PoolMetadata
sppMetadata :: !(StrictMaybe PoolMetadata)
  }
  deriving (Int -> StakePoolParams era -> ShowS
[StakePoolParams era] -> ShowS
StakePoolParams era -> String
(Int -> StakePoolParams era -> ShowS)
-> (StakePoolParams era -> String)
-> ([StakePoolParams era] -> ShowS)
-> Show (StakePoolParams era)
forall era. Int -> StakePoolParams era -> ShowS
forall era. [StakePoolParams era] -> ShowS
forall era. StakePoolParams era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era. Int -> StakePoolParams era -> ShowS
showsPrec :: Int -> StakePoolParams era -> ShowS
$cshow :: forall era. StakePoolParams era -> String
show :: StakePoolParams era -> String
$cshowList :: forall era. [StakePoolParams era] -> ShowS
showList :: [StakePoolParams era] -> ShowS
Show, (forall x. StakePoolParams era -> Rep (StakePoolParams era) x)
-> (forall x. Rep (StakePoolParams era) x -> StakePoolParams era)
-> Generic (StakePoolParams era)
forall x. Rep (StakePoolParams era) x -> StakePoolParams era
forall x. StakePoolParams era -> Rep (StakePoolParams era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x. Rep (StakePoolParams era) x -> StakePoolParams era
forall era x. StakePoolParams era -> Rep (StakePoolParams era) x
$cfrom :: forall era x. StakePoolParams era -> Rep (StakePoolParams era) x
from :: forall x. StakePoolParams era -> Rep (StakePoolParams era) x
$cto :: forall era x. Rep (StakePoolParams era) x -> StakePoolParams era
to :: forall x. Rep (StakePoolParams era) x -> StakePoolParams era
Generic, StakePoolParams era -> StakePoolParams era -> Bool
(StakePoolParams era -> StakePoolParams era -> Bool)
-> (StakePoolParams era -> StakePoolParams era -> Bool)
-> Eq (StakePoolParams era)
forall era. StakePoolParams era -> StakePoolParams era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall era. StakePoolParams era -> StakePoolParams era -> Bool
== :: StakePoolParams era -> StakePoolParams era -> Bool
$c/= :: forall era. StakePoolParams era -> StakePoolParams era -> Bool
/= :: StakePoolParams era -> StakePoolParams era -> Bool
Eq, Eq (StakePoolParams era)
Eq (StakePoolParams era) =>
(StakePoolParams era -> StakePoolParams era -> Ordering)
-> (StakePoolParams era -> StakePoolParams era -> Bool)
-> (StakePoolParams era -> StakePoolParams era -> Bool)
-> (StakePoolParams era -> StakePoolParams era -> Bool)
-> (StakePoolParams era -> StakePoolParams era -> Bool)
-> (StakePoolParams era
    -> StakePoolParams era -> StakePoolParams era)
-> (StakePoolParams era
    -> StakePoolParams era -> StakePoolParams era)
-> Ord (StakePoolParams era)
StakePoolParams era -> StakePoolParams era -> Bool
StakePoolParams era -> StakePoolParams era -> Ordering
StakePoolParams era -> StakePoolParams era -> StakePoolParams era
forall era. Eq (StakePoolParams era)
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
forall era. StakePoolParams era -> StakePoolParams era -> Bool
forall era. StakePoolParams era -> StakePoolParams era -> Ordering
forall era.
StakePoolParams era -> StakePoolParams era -> StakePoolParams era
$ccompare :: forall era. StakePoolParams era -> StakePoolParams era -> Ordering
compare :: StakePoolParams era -> StakePoolParams era -> Ordering
$c< :: forall era. StakePoolParams era -> StakePoolParams era -> Bool
< :: StakePoolParams era -> StakePoolParams era -> Bool
$c<= :: forall era. StakePoolParams era -> StakePoolParams era -> Bool
<= :: StakePoolParams era -> StakePoolParams era -> Bool
$c> :: forall era. StakePoolParams era -> StakePoolParams era -> Bool
> :: StakePoolParams era -> StakePoolParams era -> Bool
$c>= :: forall era. StakePoolParams era -> StakePoolParams era -> Bool
>= :: StakePoolParams era -> StakePoolParams era -> Bool
$cmax :: forall era.
StakePoolParams era -> StakePoolParams era -> StakePoolParams era
max :: StakePoolParams era -> StakePoolParams era -> StakePoolParams era
$cmin :: forall era.
StakePoolParams era -> StakePoolParams era -> StakePoolParams era
min :: StakePoolParams era -> StakePoolParams era -> StakePoolParams era
Ord)

data BlsKey = BlsKey
  { BlsKey -> VerKeyDSIGN BLS12381MinSigDSIGN
blsPubKey :: !(VerKeyDSIGN BLS12381MinSigDSIGN)
  , BlsKey -> PossessionProofDSIGN BLS12381MinSigDSIGN
blsPossessionProof :: !(PossessionProofDSIGN BLS12381MinSigDSIGN)
  }
  deriving (Int -> BlsKey -> ShowS
[BlsKey] -> ShowS
BlsKey -> String
(Int -> BlsKey -> ShowS)
-> (BlsKey -> String) -> ([BlsKey] -> ShowS) -> Show BlsKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BlsKey -> ShowS
showsPrec :: Int -> BlsKey -> ShowS
$cshow :: BlsKey -> String
show :: BlsKey -> String
$cshowList :: [BlsKey] -> ShowS
showList :: [BlsKey] -> ShowS
Show, (forall x. BlsKey -> Rep BlsKey x)
-> (forall x. Rep BlsKey x -> BlsKey) -> Generic BlsKey
forall x. Rep BlsKey x -> BlsKey
forall x. BlsKey -> Rep BlsKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BlsKey -> Rep BlsKey x
from :: forall x. BlsKey -> Rep BlsKey x
$cto :: forall x. Rep BlsKey x -> BlsKey
to :: forall x. Rep BlsKey x -> BlsKey
Generic, BlsKey -> BlsKey -> Bool
(BlsKey -> BlsKey -> Bool)
-> (BlsKey -> BlsKey -> Bool) -> Eq BlsKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlsKey -> BlsKey -> Bool
== :: BlsKey -> BlsKey -> Bool
$c/= :: BlsKey -> BlsKey -> Bool
/= :: BlsKey -> BlsKey -> Bool
Eq, Context -> BlsKey -> IO (Maybe ThunkInfo)
Proxy BlsKey -> String
(Context -> BlsKey -> IO (Maybe ThunkInfo))
-> (Context -> BlsKey -> IO (Maybe ThunkInfo))
-> (Proxy BlsKey -> String)
-> NoThunks BlsKey
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> BlsKey -> IO (Maybe ThunkInfo)
noThunks :: Context -> BlsKey -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> BlsKey -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> BlsKey -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy BlsKey -> String
showTypeOf :: Proxy BlsKey -> String
NoThunks, BlsKey -> ()
(BlsKey -> ()) -> NFData BlsKey
forall a. (a -> ()) -> NFData a
$crnf :: BlsKey -> ()
rnf :: BlsKey -> ()
NFData)

instance Ord BlsKey where
  compare :: BlsKey -> BlsKey -> Ordering
compare BlsKey
a BlsKey
b =
    ByteString -> ByteString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
      (VerKeyDSIGN BLS12381MinSigDSIGN -> ByteString
forall a. FixedSizeCodec a => a -> ByteString
rawEncodeFixedSized (BlsKey -> VerKeyDSIGN BLS12381MinSigDSIGN
blsPubKey BlsKey
a))
      (VerKeyDSIGN BLS12381MinSigDSIGN -> ByteString
forall a. FixedSizeCodec a => a -> ByteString
rawEncodeFixedSized (BlsKey -> VerKeyDSIGN BLS12381MinSigDSIGN
blsPubKey BlsKey
b))
      Ordering -> Ordering -> Ordering
forall a. Semigroup a => a -> a -> a
<> ByteString -> ByteString -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
        (PossessionProofDSIGN BLS12381MinSigDSIGN -> ByteString
forall a. FixedSizeCodec a => a -> ByteString
rawEncodeFixedSized (BlsKey -> PossessionProofDSIGN BLS12381MinSigDSIGN
blsPossessionProof BlsKey
a))
        (PossessionProofDSIGN BLS12381MinSigDSIGN -> ByteString
forall a. FixedSizeCodec a => a -> ByteString
rawEncodeFixedSized (BlsKey -> PossessionProofDSIGN BLS12381MinSigDSIGN
blsPossessionProof BlsKey
b))

instance ToJSON BlsKey where
  toJSON :: BlsKey -> Value
toJSON BlsKey
blsKey =
    [Pair] -> Value
Aeson.object
      [ Key
"blsPubKey"
          Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ByteString -> Text
Text.decodeLatin1 (ByteString -> ByteString
B16.encode (VerKeyDSIGN BLS12381MinSigDSIGN -> ByteString
forall a. FixedSizeCodec a => a -> ByteString
rawEncodeFixedSized (VerKeyDSIGN BLS12381MinSigDSIGN -> ByteString)
-> VerKeyDSIGN BLS12381MinSigDSIGN -> ByteString
forall a b. (a -> b) -> a -> b
$ BlsKey -> VerKeyDSIGN BLS12381MinSigDSIGN
blsPubKey BlsKey
blsKey))
      , Key
"blsPossessionProof"
          Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= ByteString -> Text
Text.decodeLatin1
            ( ByteString -> ByteString
B16.encode
                (PossessionProofDSIGN BLS12381MinSigDSIGN -> ByteString
forall a. FixedSizeCodec a => a -> ByteString
rawEncodeFixedSized (PossessionProofDSIGN BLS12381MinSigDSIGN -> ByteString)
-> PossessionProofDSIGN BLS12381MinSigDSIGN -> ByteString
forall a b. (a -> b) -> a -> b
$ BlsKey -> PossessionProofDSIGN BLS12381MinSigDSIGN
blsPossessionProof BlsKey
blsKey)
            )
      ]

instance FromJSON BlsKey where
  parseJSON :: Value -> Parser BlsKey
parseJSON = String -> (Object -> Parser BlsKey) -> Value -> Parser BlsKey
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"BlsKey" ((Object -> Parser BlsKey) -> Value -> Parser BlsKey)
-> (Object -> Parser BlsKey) -> Value -> Parser BlsKey
forall a b. (a -> b) -> a -> b
$ \Object
obj -> do
    pubKeyHex <- Text -> ByteString
Text.encodeUtf8 (Text -> ByteString) -> Parser Text -> Parser ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"blsPubKey"
    blsPossessionProofHex <- Text.encodeUtf8 <$> obj .: "blsPossessionProof"
    blsPubKey <-
      case rawDecodeFixedSized =<< either (const Nothing) Just (B16.decode pubKeyHex) of
        Maybe (VerKeyDSIGN BLS12381MinSigDSIGN)
Nothing -> String -> Parser (VerKeyDSIGN BLS12381MinSigDSIGN)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid hex for BlsPubKey"
        Just VerKeyDSIGN BLS12381MinSigDSIGN
vk -> VerKeyDSIGN BLS12381MinSigDSIGN
-> Parser (VerKeyDSIGN BLS12381MinSigDSIGN)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure VerKeyDSIGN BLS12381MinSigDSIGN
vk
    blsPossessionProof <-
      case rawDecodeFixedSized
        =<< either (const Nothing) Just (B16.decode blsPossessionProofHex) of
        Maybe (PossessionProofDSIGN BLS12381MinSigDSIGN)
Nothing -> String -> Parser (PossessionProofDSIGN BLS12381MinSigDSIGN)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid hex for PossessionProof"
        Just PossessionProofDSIGN BLS12381MinSigDSIGN
p -> PossessionProofDSIGN BLS12381MinSigDSIGN
-> Parser (PossessionProofDSIGN BLS12381MinSigDSIGN)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PossessionProofDSIGN BLS12381MinSigDSIGN
p
    pure $ BlsKey {blsPubKey, blsPossessionProof}

instance EncCBOR BlsKey where
  encCBOR :: BlsKey -> Encoding
encCBOR BlsKey
lk =
    Word -> Encoding
encodeListLen Word
2
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> VerKeyDSIGN BLS12381MinSigDSIGN -> Encoding
forall a. FixedSizeCodec a => a -> Encoding
encodeFixedSized (BlsKey -> VerKeyDSIGN BLS12381MinSigDSIGN
blsPubKey BlsKey
lk)
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> PossessionProofDSIGN BLS12381MinSigDSIGN -> Encoding
forall a. FixedSizeCodec a => a -> Encoding
encodeFixedSized (BlsKey -> PossessionProofDSIGN BLS12381MinSigDSIGN
blsPossessionProof BlsKey
lk)

instance DecCBOR BlsKey where
  decCBOR :: forall s. Decoder s BlsKey
decCBOR = Text -> (BlsKey -> Int) -> Decoder s BlsKey -> Decoder s BlsKey
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"BlsKey" (Int -> BlsKey -> Int
forall a b. a -> b -> a
const Int
2) (Decoder s BlsKey -> Decoder s BlsKey)
-> Decoder s BlsKey -> Decoder s BlsKey
forall a b. (a -> b) -> a -> b
$ do
    blsPubKey <- Decoder s (VerKeyDSIGN BLS12381MinSigDSIGN)
forall a s. FixedSizeCodec a => Decoder s a
decodeFixedSized
    blsPossessionProof <- decodeFixedSized
    pure BlsKey {blsPubKey, blsPossessionProof}

-- | A registered voting key, together with the epoch its registration took
-- effect in. The key stops being honoured @maxKeyAgeEpochs@ epochs later, at
-- which point the pool's committee seat is keyless until it registers again.
data BlsKeyState = BlsKeyState
  { BlsKeyState -> BlsKey
bksKey :: !BlsKey
  , BlsKeyState -> EpochNo
bksRegisteredIn :: !EpochNo
  }
  deriving (Int -> BlsKeyState -> ShowS
[BlsKeyState] -> ShowS
BlsKeyState -> String
(Int -> BlsKeyState -> ShowS)
-> (BlsKeyState -> String)
-> ([BlsKeyState] -> ShowS)
-> Show BlsKeyState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BlsKeyState -> ShowS
showsPrec :: Int -> BlsKeyState -> ShowS
$cshow :: BlsKeyState -> String
show :: BlsKeyState -> String
$cshowList :: [BlsKeyState] -> ShowS
showList :: [BlsKeyState] -> ShowS
Show, (forall x. BlsKeyState -> Rep BlsKeyState x)
-> (forall x. Rep BlsKeyState x -> BlsKeyState)
-> Generic BlsKeyState
forall x. Rep BlsKeyState x -> BlsKeyState
forall x. BlsKeyState -> Rep BlsKeyState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BlsKeyState -> Rep BlsKeyState x
from :: forall x. BlsKeyState -> Rep BlsKeyState x
$cto :: forall x. Rep BlsKeyState x -> BlsKeyState
to :: forall x. Rep BlsKeyState x -> BlsKeyState
Generic, BlsKeyState -> BlsKeyState -> Bool
(BlsKeyState -> BlsKeyState -> Bool)
-> (BlsKeyState -> BlsKeyState -> Bool) -> Eq BlsKeyState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlsKeyState -> BlsKeyState -> Bool
== :: BlsKeyState -> BlsKeyState -> Bool
$c/= :: BlsKeyState -> BlsKeyState -> Bool
/= :: BlsKeyState -> BlsKeyState -> Bool
Eq, Eq BlsKeyState
Eq BlsKeyState =>
(BlsKeyState -> BlsKeyState -> Ordering)
-> (BlsKeyState -> BlsKeyState -> Bool)
-> (BlsKeyState -> BlsKeyState -> Bool)
-> (BlsKeyState -> BlsKeyState -> Bool)
-> (BlsKeyState -> BlsKeyState -> Bool)
-> (BlsKeyState -> BlsKeyState -> BlsKeyState)
-> (BlsKeyState -> BlsKeyState -> BlsKeyState)
-> Ord BlsKeyState
BlsKeyState -> BlsKeyState -> Bool
BlsKeyState -> BlsKeyState -> Ordering
BlsKeyState -> BlsKeyState -> BlsKeyState
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 :: BlsKeyState -> BlsKeyState -> Ordering
compare :: BlsKeyState -> BlsKeyState -> Ordering
$c< :: BlsKeyState -> BlsKeyState -> Bool
< :: BlsKeyState -> BlsKeyState -> Bool
$c<= :: BlsKeyState -> BlsKeyState -> Bool
<= :: BlsKeyState -> BlsKeyState -> Bool
$c> :: BlsKeyState -> BlsKeyState -> Bool
> :: BlsKeyState -> BlsKeyState -> Bool
$c>= :: BlsKeyState -> BlsKeyState -> Bool
>= :: BlsKeyState -> BlsKeyState -> Bool
$cmax :: BlsKeyState -> BlsKeyState -> BlsKeyState
max :: BlsKeyState -> BlsKeyState -> BlsKeyState
$cmin :: BlsKeyState -> BlsKeyState -> BlsKeyState
min :: BlsKeyState -> BlsKeyState -> BlsKeyState
Ord, Context -> BlsKeyState -> IO (Maybe ThunkInfo)
Proxy BlsKeyState -> String
(Context -> BlsKeyState -> IO (Maybe ThunkInfo))
-> (Context -> BlsKeyState -> IO (Maybe ThunkInfo))
-> (Proxy BlsKeyState -> String)
-> NoThunks BlsKeyState
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> BlsKeyState -> IO (Maybe ThunkInfo)
noThunks :: Context -> BlsKeyState -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> BlsKeyState -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> BlsKeyState -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy BlsKeyState -> String
showTypeOf :: Proxy BlsKeyState -> String
NoThunks, BlsKeyState -> ()
(BlsKeyState -> ()) -> NFData BlsKeyState
forall a. (a -> ()) -> NFData a
$crnf :: BlsKeyState -> ()
rnf :: BlsKeyState -> ()
NFData, [BlsKeyState] -> Value
[BlsKeyState] -> Encoding
BlsKeyState -> Bool
BlsKeyState -> Value
BlsKeyState -> Encoding
(BlsKeyState -> Value)
-> (BlsKeyState -> Encoding)
-> ([BlsKeyState] -> Value)
-> ([BlsKeyState] -> Encoding)
-> (BlsKeyState -> Bool)
-> ToJSON BlsKeyState
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: BlsKeyState -> Value
toJSON :: BlsKeyState -> Value
$ctoEncoding :: BlsKeyState -> Encoding
toEncoding :: BlsKeyState -> Encoding
$ctoJSONList :: [BlsKeyState] -> Value
toJSONList :: [BlsKeyState] -> Value
$ctoEncodingList :: [BlsKeyState] -> Encoding
toEncodingList :: [BlsKeyState] -> Encoding
$comitField :: BlsKeyState -> Bool
omitField :: BlsKeyState -> Bool
ToJSON, Maybe BlsKeyState
Value -> Parser [BlsKeyState]
Value -> Parser BlsKeyState
(Value -> Parser BlsKeyState)
-> (Value -> Parser [BlsKeyState])
-> Maybe BlsKeyState
-> FromJSON BlsKeyState
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser BlsKeyState
parseJSON :: Value -> Parser BlsKeyState
$cparseJSONList :: Value -> Parser [BlsKeyState]
parseJSONList :: Value -> Parser [BlsKeyState]
$comittedField :: Maybe BlsKeyState
omittedField :: Maybe BlsKeyState
FromJSON)

bksKeyL :: Lens' BlsKeyState BlsKey
bksKeyL :: Lens' BlsKeyState BlsKey
bksKeyL = (BlsKeyState -> BlsKey)
-> (BlsKeyState -> BlsKey -> BlsKeyState)
-> Lens' BlsKeyState BlsKey
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens BlsKeyState -> BlsKey
bksKey ((BlsKeyState -> BlsKey -> BlsKeyState)
 -> Lens' BlsKeyState BlsKey)
-> (BlsKeyState -> BlsKey -> BlsKeyState)
-> Lens' BlsKeyState BlsKey
forall a b. (a -> b) -> a -> b
$ \BlsKeyState
bks BlsKey
k -> BlsKeyState
bks {bksKey = k}

bksRegisteredInL :: Lens' BlsKeyState EpochNo
bksRegisteredInL :: Lens' BlsKeyState EpochNo
bksRegisteredInL = (BlsKeyState -> EpochNo)
-> (BlsKeyState -> EpochNo -> BlsKeyState)
-> Lens' BlsKeyState EpochNo
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens BlsKeyState -> EpochNo
bksRegisteredIn ((BlsKeyState -> EpochNo -> BlsKeyState)
 -> Lens' BlsKeyState EpochNo)
-> (BlsKeyState -> EpochNo -> BlsKeyState)
-> Lens' BlsKeyState EpochNo
forall a b. (a -> b) -> a -> b
$ \BlsKeyState
bks EpochNo
e -> BlsKeyState
bks {bksRegisteredIn = e}

instance EncCBOR BlsKeyState where
  encCBOR :: BlsKeyState -> Encoding
encCBOR BlsKeyState
bks =
    Encode (Closed Dense) BlsKeyState -> Encoding
forall (w :: Wrapped) t. Encode w t -> Encoding
encode (Encode (Closed Dense) BlsKeyState -> Encoding)
-> Encode (Closed Dense) BlsKeyState -> Encoding
forall a b. (a -> b) -> a -> b
$
      (BlsKey -> EpochNo -> BlsKeyState)
-> Encode (Closed Dense) (BlsKey -> EpochNo -> BlsKeyState)
forall t. t -> Encode (Closed Dense) t
Rec BlsKey -> EpochNo -> BlsKeyState
BlsKeyState
        Encode (Closed Dense) (BlsKey -> EpochNo -> BlsKeyState)
-> Encode (Closed Dense) BlsKey
-> Encode (Closed Dense) (EpochNo -> BlsKeyState)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> BlsKey -> Encode (Closed Dense) BlsKey
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (BlsKeyState -> BlsKey
bksKey BlsKeyState
bks)
        Encode (Closed Dense) (EpochNo -> BlsKeyState)
-> Encode (Closed Dense) EpochNo
-> Encode (Closed Dense) BlsKeyState
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> EpochNo -> Encode (Closed Dense) EpochNo
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To (BlsKeyState -> EpochNo
bksRegisteredIn BlsKeyState
bks)

instance DecCBOR BlsKeyState where
  decCBOR :: forall s. Decoder s BlsKeyState
decCBOR =
    Decode (Closed Dense) BlsKeyState -> Decoder s BlsKeyState
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode (Decode (Closed Dense) BlsKeyState -> Decoder s BlsKeyState)
-> Decode (Closed Dense) BlsKeyState -> Decoder s BlsKeyState
forall a b. (a -> b) -> a -> b
$
      (BlsKey -> EpochNo -> BlsKeyState)
-> Decode (Closed Dense) (BlsKey -> EpochNo -> BlsKeyState)
forall t. t -> Decode (Closed Dense) t
RecD BlsKey -> EpochNo -> BlsKeyState
BlsKeyState
        Decode (Closed Dense) (BlsKey -> EpochNo -> BlsKeyState)
-> Decode (Closed (ZonkAny 12)) BlsKey
-> Decode (Closed Dense) (EpochNo -> BlsKeyState)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 12)) BlsKey
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
        Decode (Closed Dense) (EpochNo -> BlsKeyState)
-> Decode (Closed (ZonkAny 11)) EpochNo
-> Decode (Closed Dense) BlsKeyState
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 11)) EpochNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From

sppVrfL :: Lens' (StakePoolParams era) (VRFVerKeyHash StakePoolVRF)
sppVrfL :: forall era (f :: * -> *).
Functor f =>
(VRFVerKeyHash StakePoolVRF -> f (VRFVerKeyHash StakePoolVRF))
-> StakePoolParams era -> f (StakePoolParams era)
sppVrfL = (StakePoolParams era -> VRFVerKeyHash StakePoolVRF)
-> (StakePoolParams era
    -> VRFVerKeyHash StakePoolVRF -> StakePoolParams era)
-> Lens
     (StakePoolParams era)
     (StakePoolParams era)
     (VRFVerKeyHash StakePoolVRF)
     (VRFVerKeyHash StakePoolVRF)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolParams era -> VRFVerKeyHash StakePoolVRF
forall era. StakePoolParams era -> VRFVerKeyHash StakePoolVRF
sppVrf (\StakePoolParams era
spp VRFVerKeyHash StakePoolVRF
u -> StakePoolParams era
spp {sppVrf = u})

sppCostL :: Lens' (StakePoolParams era) Coin
sppCostL :: forall era (f :: * -> *).
Functor f =>
(Coin -> f Coin) -> StakePoolParams era -> f (StakePoolParams era)
sppCostL = (StakePoolParams era -> Coin)
-> (StakePoolParams era -> Coin -> StakePoolParams era)
-> Lens (StakePoolParams era) (StakePoolParams era) Coin Coin
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolParams era -> Coin
forall era. StakePoolParams era -> Coin
sppCost (\StakePoolParams era
spp Coin
u -> StakePoolParams era
spp {sppCost = u})

sppMetadataL :: Lens' (StakePoolParams era) (StrictMaybe PoolMetadata)
sppMetadataL :: forall era (f :: * -> *).
Functor f =>
(StrictMaybe PoolMetadata -> f (StrictMaybe PoolMetadata))
-> StakePoolParams era -> f (StakePoolParams era)
sppMetadataL = (StakePoolParams era -> StrictMaybe PoolMetadata)
-> (StakePoolParams era
    -> StrictMaybe PoolMetadata -> StakePoolParams era)
-> Lens
     (StakePoolParams era)
     (StakePoolParams era)
     (StrictMaybe PoolMetadata)
     (StrictMaybe PoolMetadata)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens StakePoolParams era -> StrictMaybe PoolMetadata
forall era. StakePoolParams era -> StrictMaybe PoolMetadata
sppMetadata (\StakePoolParams era
spp StrictMaybe PoolMetadata
u -> StakePoolParams era
spp {sppMetadata = u})

instance Default (StakePoolParams era) where
  def :: StakePoolParams era
def = KeyHash StakePool
-> VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKey
-> Coin
-> Coin
-> UnitInterval
-> AccountAddress
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> StakePoolParams era
forall era.
KeyHash StakePool
-> VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKey
-> Coin
-> Coin
-> UnitInterval
-> AccountAddress
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> StakePoolParams era
StakePoolParams KeyHash StakePool
forall a. Default a => a
def VRFVerKeyHash StakePoolVRF
forall a. Default a => a
def StrictMaybe BlsKey
forall a. Default a => a
def (Integer -> Coin
Coin Integer
0) (Integer -> Coin
Coin Integer
0) UnitInterval
forall a. Default a => a
def AccountAddress
forall a. Default a => a
def Set (KeyHash Staking)
forall a. Default a => a
def StrictSeq StakePoolRelay
forall a. Default a => a
def StrictMaybe PoolMetadata
forall a. Default a => a
def

instance NoThunks (StakePoolParams era)

deriving instance NFData (StakePoolParams era)

instance ToJSON (StakePoolParams era) where
  toJSON :: StakePoolParams era -> Value
toJSON StakePoolParams era
spp =
    [Pair] -> Value
Aeson.object
      [ Key
"poolId" Key -> KeyHash StakePool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> KeyHash StakePool
forall era. StakePoolParams era -> KeyHash StakePool
sppId StakePoolParams era
spp
      , Key
"vrf" Key -> VRFVerKeyHash StakePoolVRF -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> VRFVerKeyHash StakePoolVRF
forall era. StakePoolParams era -> VRFVerKeyHash StakePoolVRF
sppVrf StakePoolParams era
spp
      , Key
"blsKey" Key -> StrictMaybe BlsKey -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> StrictMaybe BlsKey
forall era. StakePoolParams era -> StrictMaybe BlsKey
sppBlsKey StakePoolParams era
spp
      , Key
"pledge" Key -> Coin -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> Coin
forall era. StakePoolParams era -> Coin
sppPledge StakePoolParams era
spp
      , Key
"cost" Key -> Coin -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> Coin
forall era. StakePoolParams era -> Coin
sppCost StakePoolParams era
spp
      , Key
"margin" Key -> UnitInterval -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> UnitInterval
forall era. StakePoolParams era -> UnitInterval
sppMargin StakePoolParams era
spp
      , Key
"accountAddress" Key -> AccountAddress -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> AccountAddress
forall era. StakePoolParams era -> AccountAddress
sppAccountAddress StakePoolParams era
spp
      , Key
"owners" Key -> Set (KeyHash Staking) -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> Set (KeyHash Staking)
forall era. StakePoolParams era -> Set (KeyHash Staking)
sppOwners StakePoolParams era
spp
      , Key
"relays" Key -> StrictSeq StakePoolRelay -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> StrictSeq StakePoolRelay
forall era. StakePoolParams era -> StrictSeq StakePoolRelay
sppRelays StakePoolParams era
spp
      , Key
"metadata" Key -> StrictMaybe PoolMetadata -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= StakePoolParams era -> StrictMaybe PoolMetadata
forall era. StakePoolParams era -> StrictMaybe PoolMetadata
sppMetadata StakePoolParams era
spp
      ]

instance FromJSON (StakePoolParams era) where
  parseJSON :: Value -> Parser (StakePoolParams era)
parseJSON =
    String
-> (Object -> Parser (StakePoolParams era))
-> Value
-> Parser (StakePoolParams era)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"StakePoolParams" ((Object -> Parser (StakePoolParams era))
 -> Value -> Parser (StakePoolParams era))
-> (Object -> Parser (StakePoolParams era))
-> Value
-> Parser (StakePoolParams era)
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
      -- Preserved for backward-compatibility,
      -- "publicKey" and "rewardAccount" are old misnomers.
      KeyHash StakePool
-> VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKey
-> Coin
-> Coin
-> UnitInterval
-> AccountAddress
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> StakePoolParams era
forall era.
KeyHash StakePool
-> VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKey
-> Coin
-> Coin
-> UnitInterval
-> AccountAddress
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> StakePoolParams era
StakePoolParams
        (KeyHash StakePool
 -> VRFVerKeyHash StakePoolVRF
 -> StrictMaybe BlsKey
 -> Coin
 -> Coin
 -> UnitInterval
 -> AccountAddress
 -> Set (KeyHash Staking)
 -> StrictSeq StakePoolRelay
 -> StrictMaybe PoolMetadata
 -> StakePoolParams era)
-> Parser (KeyHash StakePool)
-> Parser
     (VRFVerKeyHash StakePoolVRF
      -> StrictMaybe BlsKey
      -> Coin
      -> Coin
      -> UnitInterval
      -> AccountAddress
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> StakePoolParams era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Object
obj Object -> Key -> Parser (KeyHash StakePool)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"poolId") Parser (KeyHash StakePool)
-> Parser (KeyHash StakePool) -> Parser (KeyHash StakePool)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Object
obj Object -> Key -> Parser (KeyHash StakePool)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"publicKey"))
        Parser
  (VRFVerKeyHash StakePoolVRF
   -> StrictMaybe BlsKey
   -> Coin
   -> Coin
   -> UnitInterval
   -> AccountAddress
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> StakePoolParams era)
-> Parser (VRFVerKeyHash StakePoolVRF)
-> Parser
     (StrictMaybe BlsKey
      -> Coin
      -> Coin
      -> UnitInterval
      -> AccountAddress
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (VRFVerKeyHash StakePoolVRF)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"vrf"
        Parser
  (StrictMaybe BlsKey
   -> Coin
   -> Coin
   -> UnitInterval
   -> AccountAddress
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> StakePoolParams era)
-> Parser (StrictMaybe BlsKey)
-> Parser
     (Coin
      -> Coin
      -> UnitInterval
      -> AccountAddress
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Maybe (StrictMaybe BlsKey))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"blsKey" Parser (Maybe (StrictMaybe BlsKey))
-> StrictMaybe BlsKey -> Parser (StrictMaybe BlsKey)
forall a. Parser (Maybe a) -> a -> Parser a
.!= StrictMaybe BlsKey
forall a. StrictMaybe a
SNothing
        Parser
  (Coin
   -> Coin
   -> UnitInterval
   -> AccountAddress
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> StakePoolParams era)
-> Parser Coin
-> Parser
     (Coin
      -> UnitInterval
      -> AccountAddress
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser Coin
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"pledge"
        Parser
  (Coin
   -> UnitInterval
   -> AccountAddress
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> StakePoolParams era)
-> Parser Coin
-> Parser
     (UnitInterval
      -> AccountAddress
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser Coin
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"cost"
        Parser
  (UnitInterval
   -> AccountAddress
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> StakePoolParams era)
-> Parser UnitInterval
-> Parser
     (AccountAddress
      -> Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser UnitInterval
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"margin"
        Parser
  (AccountAddress
   -> Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> StakePoolParams era)
-> Parser AccountAddress
-> Parser
     (Set (KeyHash Staking)
      -> StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata
      -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Object
obj Object -> Key -> Parser AccountAddress
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"accountAddress") Parser AccountAddress
-> Parser AccountAddress -> Parser AccountAddress
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Object
obj Object -> Key -> Parser AccountAddress
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"rewardAccount"))
        Parser
  (Set (KeyHash Staking)
   -> StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata
   -> StakePoolParams era)
-> Parser (Set (KeyHash Staking))
-> Parser
     (StrictSeq StakePoolRelay
      -> StrictMaybe PoolMetadata -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Set (KeyHash Staking))
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"owners"
        Parser
  (StrictSeq StakePoolRelay
   -> StrictMaybe PoolMetadata -> StakePoolParams era)
-> Parser (StrictSeq StakePoolRelay)
-> Parser (StrictMaybe PoolMetadata -> StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (StrictSeq StakePoolRelay)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"relays"
        Parser (StrictMaybe PoolMetadata -> StakePoolParams era)
-> Parser (StrictMaybe PoolMetadata)
-> Parser (StakePoolParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (StrictMaybe PoolMetadata)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"metadata"

type PoolParams = StakePoolParams

pattern PoolParams ::
  KeyHash StakePool ->
  VRFVerKeyHash StakePoolVRF ->
  StrictMaybe BlsKey ->
  Coin ->
  Coin ->
  UnitInterval ->
  AccountAddress ->
  Set (KeyHash Staking) ->
  StrictSeq StakePoolRelay ->
  StrictMaybe PoolMetadata ->
  PoolParams era
pattern $mPoolParams :: forall {r} {era}.
PoolParams era
-> (KeyHash StakePool
    -> VRFVerKeyHash StakePoolVRF
    -> StrictMaybe BlsKey
    -> Coin
    -> Coin
    -> UnitInterval
    -> AccountAddress
    -> Set (KeyHash Staking)
    -> StrictSeq StakePoolRelay
    -> StrictMaybe PoolMetadata
    -> r)
-> ((# #) -> r)
-> r
$bPoolParams :: forall era.
KeyHash StakePool
-> VRFVerKeyHash StakePoolVRF
-> StrictMaybe BlsKey
-> Coin
-> Coin
-> UnitInterval
-> AccountAddress
-> Set (KeyHash Staking)
-> StrictSeq StakePoolRelay
-> StrictMaybe PoolMetadata
-> StakePoolParams era
PoolParams
  { forall era. StakePoolParams era -> KeyHash StakePool
ppId
  , forall era. StakePoolParams era -> VRFVerKeyHash StakePoolVRF
ppVrf
  , forall era. StakePoolParams era -> StrictMaybe BlsKey
ppBlsKey
  , forall era. StakePoolParams era -> Coin
ppPledge
  , forall era. StakePoolParams era -> Coin
ppCost
  , forall era. StakePoolParams era -> UnitInterval
ppMargin
  , forall era. StakePoolParams era -> AccountAddress
ppAccountAddress
  , forall era. StakePoolParams era -> Set (KeyHash Staking)
ppOwners
  , forall era. StakePoolParams era -> StrictSeq StakePoolRelay
ppRelays
  , forall era. StakePoolParams era -> StrictMaybe PoolMetadata
ppMetadata
  } =
  StakePoolParams
    ppId
    ppVrf
    ppBlsKey
    ppPledge
    ppCost
    ppMargin
    ppAccountAddress
    ppOwners
    ppRelays
    ppMetadata

{-# COMPLETE PoolParams #-}

{-# DEPRECATED PoolParams "In favor of `StakePoolParams`" #-}

{-# DEPRECATED
  ppId
  , ppVrf
  , ppBlsKey
  , ppPledge
  , ppCost
  , ppMargin
  , ppAccountAddress
  , ppOwners
  , ppRelays
  , ppMetadata
  "In favor of fields with `spp*` prefix"
  #-}

instance EncCBOR PoolMetadata where
  encCBOR :: PoolMetadata -> Encoding
encCBOR (PoolMetadata Url
u ByteArray
h) =
    Word -> Encoding
encodeListLen Word
2
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Url -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Url
u
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ByteArray -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR ByteArray
h

instance DecCBOR PoolMetadata where
  decCBOR :: forall s. Decoder s PoolMetadata
decCBOR = do
    Text
-> (PoolMetadata -> Int)
-> Decoder s PoolMetadata
-> Decoder s PoolMetadata
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"PoolMetadata" (Int -> PoolMetadata -> Int
forall a b. a -> b -> a
const Int
2) (Url -> ByteArray -> PoolMetadata
PoolMetadata (Url -> ByteArray -> PoolMetadata)
-> Decoder s Url -> Decoder s (ByteArray -> PoolMetadata)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Url
forall s. Decoder s Url
forall a s. DecCBOR a => Decoder s a
decCBOR Decoder s (ByteArray -> PoolMetadata)
-> Decoder s ByteArray -> Decoder s PoolMetadata
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s ByteArray
forall s. Decoder s ByteArray
forall a s. DecCBOR a => Decoder s a
decCBOR)

-- | The size of the 'sppOwners' 'Set'.  Only used to compute size of encoded
-- 'StakePoolParams'.
data SizeOfPoolOwners = SizeOfPoolOwners

instance EncCBOR SizeOfPoolOwners where
  encCBOR :: SizeOfPoolOwners -> Encoding
encCBOR = String -> SizeOfPoolOwners -> Encoding
forall a. HasCallStack => String -> a
error String
"The `SizeOfPoolOwners` type cannot be encoded!"

-- | The size of the 'sppRelays' 'Set'.  Only used to compute size of encoded
-- 'StakePoolParams'.
data SizeOfPoolRelays = SizeOfPoolRelays

instance EncCBOR SizeOfPoolRelays where
  encCBOR :: SizeOfPoolRelays -> Encoding
encCBOR = String -> SizeOfPoolRelays -> Encoding
forall a. HasCallStack => String -> a
error String
"The `SizeOfPoolRelays` type cannot be encoded!"

instance EncCBOR (StakePoolParams era) where
  encCBOR :: StakePoolParams era -> Encoding
encCBOR StakePoolParams era
poolParams =
    StakePoolParams era -> (Int -> Encoding -> Encoding) -> Encoding
forall era.
StakePoolParams era -> (Int -> Encoding -> Encoding) -> Encoding
withStakePoolParamsFlatEncoding StakePoolParams era
poolParams ((Int -> Encoding -> Encoding) -> Encoding)
-> (Int -> Encoding -> Encoding) -> Encoding
forall a b. (a -> b) -> a -> b
$ \Int
stakePoolParamsListLen Encoding
stakePoolParamsEncoding ->
      Word -> Encoding
encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
stakePoolParamsListLen)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding
stakePoolParamsEncoding

-- | Returns the 'StakePoolParams' in a flat structure such as `[operator, vrf,
-- pledge, ...]`. Useful for combining with other encoding functions like
-- 'encodePoolCert' so that those functions end up with a flat list encoding
-- instead of a nested list.
--
-- We could have used 'EncCBORGroup' to achieve something similar. However, the
-- `listLen` function is static and can't depend on the Encoding version.
-- Instead, we want `StakePoolParams` to have a dynamic list length based on the
-- protocol version.
withStakePoolParamsFlatEncoding ::
  StakePoolParams era ->
  -- | Function with stake pool params flat encoded list length and actual flat
  -- encoded stake pool params
  (Int -> Encoding -> Encoding) ->
  Encoding
withStakePoolParamsFlatEncoding :: forall era.
StakePoolParams era -> (Int -> Encoding -> Encoding) -> Encoding
withStakePoolParamsFlatEncoding StakePoolParams era
poolParams Int -> Encoding -> Encoding
f =
  (Version -> Encoding) -> Encoding
withCurrentEncodingVersion ((Version -> Encoding) -> Encoding)
-> (Version -> Encoding) -> Encoding
forall a b. (a -> b) -> a -> b
$ \Version
v -> do
    let (Int
extraLen, Encoding
blsKeyEncoding)
          | Version
v Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
>= forall (v :: Natural).
(KnownNat v, 0 <= v, v <= MaxVersion) =>
Version
natVersion @12 =
              case StakePoolParams era -> StrictMaybe BlsKey
forall era. StakePoolParams era -> StrictMaybe BlsKey
sppBlsKey StakePoolParams era
poolParams of
                SJust BlsKey
lk -> (Int
1, BlsKey -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR BlsKey
lk)
                StrictMaybe BlsKey
SNothing -> (Int
0, Encoding
forall a. Monoid a => a
mempty)
          | Bool
otherwise = (Int
0, Encoding
forall a. Monoid a => a
mempty)
    Int -> Encoding -> Encoding
f (Int
9 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
extraLen) (Encoding -> Encoding) -> Encoding -> Encoding
forall a b. (a -> b) -> a -> b
$
      KeyHash StakePool -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> KeyHash StakePool
forall era. StakePoolParams era -> KeyHash StakePool
sppId StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> VRFVerKeyHash StakePoolVRF -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> VRFVerKeyHash StakePoolVRF
forall era. StakePoolParams era -> VRFVerKeyHash StakePoolVRF
sppVrf StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding
blsKeyEncoding
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Coin -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> Coin
forall era. StakePoolParams era -> Coin
sppPledge StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Coin -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> Coin
forall era. StakePoolParams era -> Coin
sppCost StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> UnitInterval -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> UnitInterval
forall era. StakePoolParams era -> UnitInterval
sppMargin StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> AccountAddress -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> AccountAddress
forall era. StakePoolParams era -> AccountAddress
sppAccountAddress StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Set (KeyHash Staking) -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> Set (KeyHash Staking)
forall era. StakePoolParams era -> Set (KeyHash Staking)
sppOwners StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> StrictSeq StakePoolRelay -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> StrictSeq StakePoolRelay
forall era. StakePoolParams era -> StrictSeq StakePoolRelay
sppRelays StakePoolParams era
poolParams)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (PoolMetadata -> Encoding) -> StrictMaybe PoolMetadata -> Encoding
forall a. (a -> Encoding) -> StrictMaybe a -> Encoding
encodeNullStrictMaybe PoolMetadata -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (StakePoolParams era -> StrictMaybe PoolMetadata
forall era. StakePoolParams era -> StrictMaybe PoolMetadata
sppMetadata StakePoolParams era
poolParams)

instance Era era => DecCBOR (StakePoolParams era) where
  decCBOR :: forall s. Decoder s (StakePoolParams era)
decCBOR = do
    (Int, StakePoolParams era) -> StakePoolParams era
forall a b. (a, b) -> b
snd ((Int, StakePoolParams era) -> StakePoolParams era)
-> Decoder s (Int, StakePoolParams era)
-> Decoder s (StakePoolParams era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ((Int, StakePoolParams era) -> Int)
-> Decoder s (Int, StakePoolParams era)
-> Decoder s (Int, StakePoolParams era)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"StakePoolParams" (Int, StakePoolParams era) -> Int
forall a b. (a, b) -> a
fst Decoder s (Int, StakePoolParams era)
forall s era. Decoder s (Int, StakePoolParams era)
decodeStakePoolParamsFlat

decodeStakePoolParamsFlat :: Decoder s (Int, StakePoolParams era)
decodeStakePoolParamsFlat :: forall s era. Decoder s (Int, StakePoolParams era)
decodeStakePoolParamsFlat = do
  sppId <- Decoder s (KeyHash StakePool)
forall s. Decoder s (KeyHash StakePool)
forall a s. DecCBOR a => Decoder s a
decCBOR
  sppVrf <- decCBOR
  (extraBlsKeyLen, sppBlsKey) <-
    ifDecoderVersionAtLeast
      (natVersion @12)
      decodeBlsKeyBackwardsCompatible
      (pure (0, SNothing))
  sppPledge <- decCBOR
  sppCost <- decCBOR
  sppMargin <- decCBOR
  sppAccountAddress <- decCBOR
  sppOwners <- decCBOR
  sppRelays <- decCBOR
  sppMetadata <- decodeNullStrictMaybe decCBOR
  pure (9 + extraBlsKeyLen, StakePoolParams {..})
  where
    decodeBlsKeyBackwardsCompatible :: Decoder s (Int, StrictMaybe BlsKey)
decodeBlsKeyBackwardsCompatible = do
      Decoder s TokenType
forall s. Decoder s TokenType
peekTokenType Decoder s TokenType
-> (TokenType -> Decoder s (Int, StrictMaybe BlsKey))
-> Decoder s (Int, StrictMaybe BlsKey)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        TokenType
TypeListLen -> (\BlsKey
lk -> (Int
1, BlsKey -> StrictMaybe BlsKey
forall a. a -> StrictMaybe a
SJust BlsKey
lk)) (BlsKey -> (Int, StrictMaybe BlsKey))
-> Decoder s BlsKey -> Decoder s (Int, StrictMaybe BlsKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s BlsKey
forall s. Decoder s BlsKey
forall a s. DecCBOR a => Decoder s a
decCBOR
        TokenType
TypeListLen64 -> (\BlsKey
lk -> (Int
1, BlsKey -> StrictMaybe BlsKey
forall a. a -> StrictMaybe a
SJust BlsKey
lk)) (BlsKey -> (Int, StrictMaybe BlsKey))
-> Decoder s BlsKey -> Decoder s (Int, StrictMaybe BlsKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s BlsKey
forall s. Decoder s BlsKey
forall a s. DecCBOR a => Decoder s a
decCBOR
        TokenType
TypeListLenIndef -> (\BlsKey
lk -> (Int
1, BlsKey -> StrictMaybe BlsKey
forall a. a -> StrictMaybe a
SJust BlsKey
lk)) (BlsKey -> (Int, StrictMaybe BlsKey))
-> Decoder s BlsKey -> Decoder s (Int, StrictMaybe BlsKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s BlsKey
forall s. Decoder s BlsKey
forall a s. DecCBOR a => Decoder s a
decCBOR
        TokenType
TypeNull -> do
          Decoder s ()
forall s. Decoder s ()
decodeNull
          (Int, StrictMaybe BlsKey) -> Decoder s (Int, StrictMaybe BlsKey)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
1, StrictMaybe BlsKey
forall a. StrictMaybe a
SNothing)
        TokenType
_ -> (Int, StrictMaybe BlsKey) -> Decoder s (Int, StrictMaybe BlsKey)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
0, StrictMaybe BlsKey
forall a. StrictMaybe a
SNothing)