{-# LANGUAGE TypeFamilies #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion (
    ShelleyNodeToClientVersion (..)
  , ShelleyNodeToNodeVersion (..)
  ) where

import qualified Data.Map.Strict as Map
import           Ouroboros.Consensus.Node.NetworkProtocolVersion
import           Ouroboros.Consensus.Shelley.Ledger.Block

data ShelleyNodeToNodeVersion = ShelleyNodeToNodeVersion1
  deriving (Int -> ShelleyNodeToNodeVersion -> ShowS
[ShelleyNodeToNodeVersion] -> ShowS
ShelleyNodeToNodeVersion -> String
(Int -> ShelleyNodeToNodeVersion -> ShowS)
-> (ShelleyNodeToNodeVersion -> String)
-> ([ShelleyNodeToNodeVersion] -> ShowS)
-> Show ShelleyNodeToNodeVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShelleyNodeToNodeVersion -> ShowS
showsPrec :: Int -> ShelleyNodeToNodeVersion -> ShowS
$cshow :: ShelleyNodeToNodeVersion -> String
show :: ShelleyNodeToNodeVersion -> String
$cshowList :: [ShelleyNodeToNodeVersion] -> ShowS
showList :: [ShelleyNodeToNodeVersion] -> ShowS
Show, ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
(ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool)
-> (ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool)
-> Eq ShelleyNodeToNodeVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
== :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
$c/= :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
/= :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
Eq, Eq ShelleyNodeToNodeVersion
Eq ShelleyNodeToNodeVersion =>
(ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Ordering)
-> (ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool)
-> (ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool)
-> (ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool)
-> (ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool)
-> (ShelleyNodeToNodeVersion
    -> ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion)
-> (ShelleyNodeToNodeVersion
    -> ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion)
-> Ord ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Ordering
ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
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 :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Ordering
compare :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Ordering
$c< :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
< :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
$c<= :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
<= :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
$c> :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
> :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
$c>= :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
>= :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion -> Bool
$cmax :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
max :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
$cmin :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
min :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
Ord, Int -> ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion -> Int
ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion
-> [ShelleyNodeToNodeVersion]
(ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion)
-> (ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion)
-> (Int -> ShelleyNodeToNodeVersion)
-> (ShelleyNodeToNodeVersion -> Int)
-> (ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion])
-> (ShelleyNodeToNodeVersion
    -> ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion])
-> (ShelleyNodeToNodeVersion
    -> ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion])
-> (ShelleyNodeToNodeVersion
    -> ShelleyNodeToNodeVersion
    -> ShelleyNodeToNodeVersion
    -> [ShelleyNodeToNodeVersion])
-> Enum ShelleyNodeToNodeVersion
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
succ :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
$cpred :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
pred :: ShelleyNodeToNodeVersion -> ShelleyNodeToNodeVersion
$ctoEnum :: Int -> ShelleyNodeToNodeVersion
toEnum :: Int -> ShelleyNodeToNodeVersion
$cfromEnum :: ShelleyNodeToNodeVersion -> Int
fromEnum :: ShelleyNodeToNodeVersion -> Int
$cenumFrom :: ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
enumFrom :: ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
$cenumFromThen :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
enumFromThen :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
$cenumFromTo :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
enumFromTo :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> [ShelleyNodeToNodeVersion]
$cenumFromThenTo :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion
-> [ShelleyNodeToNodeVersion]
enumFromThenTo :: ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion
-> [ShelleyNodeToNodeVersion]
Enum, ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion
-> ShelleyNodeToNodeVersion -> Bounded ShelleyNodeToNodeVersion
forall a. a -> a -> Bounded a
$cminBound :: ShelleyNodeToNodeVersion
minBound :: ShelleyNodeToNodeVersion
$cmaxBound :: ShelleyNodeToNodeVersion
maxBound :: ShelleyNodeToNodeVersion
Bounded)

data ShelleyNodeToClientVersion =
    ShelleyNodeToClientVersion1

    -- | New queries introduced
  | ShelleyNodeToClientVersion2

    -- | New query introduced
  | ShelleyNodeToClientVersion3

    -- | New queries introduced
  | ShelleyNodeToClientVersion4

    -- | New queries introduced: GetRewardInfoPools
  | ShelleyNodeToClientVersion5

    -- | New queries introduced: GetPoolDistr, GetPoolState, GetStakeSnapshots
  | ShelleyNodeToClientVersion6

    -- | New queries introduced: GetStakeDelegDeposits
  | ShelleyNodeToClientVersion7

    -- | New queries introduced: GetConstitutionHash, GetFilteredVoteDelegatees
  | ShelleyNodeToClientVersion8

    -- | New queries introduced: GetProposals, GetRatifyState
  | ShelleyNodeToClientVersion9
  deriving (Int -> ShelleyNodeToClientVersion -> ShowS
[ShelleyNodeToClientVersion] -> ShowS
ShelleyNodeToClientVersion -> String
(Int -> ShelleyNodeToClientVersion -> ShowS)
-> (ShelleyNodeToClientVersion -> String)
-> ([ShelleyNodeToClientVersion] -> ShowS)
-> Show ShelleyNodeToClientVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShelleyNodeToClientVersion -> ShowS
showsPrec :: Int -> ShelleyNodeToClientVersion -> ShowS
$cshow :: ShelleyNodeToClientVersion -> String
show :: ShelleyNodeToClientVersion -> String
$cshowList :: [ShelleyNodeToClientVersion] -> ShowS
showList :: [ShelleyNodeToClientVersion] -> ShowS
Show, ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
(ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool)
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> Bool)
-> Eq ShelleyNodeToClientVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
== :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
$c/= :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
/= :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
Eq, Eq ShelleyNodeToClientVersion
Eq ShelleyNodeToClientVersion =>
(ShelleyNodeToClientVersion
 -> ShelleyNodeToClientVersion -> Ordering)
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> Bool)
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> Bool)
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> Bool)
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> Bool)
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion)
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion)
-> Ord ShelleyNodeToClientVersion
ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> Ordering
ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
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 :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> Ordering
compare :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> Ordering
$c< :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
< :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
$c<= :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
<= :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
$c> :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
> :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
$c>= :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
>= :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion -> Bool
$cmax :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
max :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
$cmin :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
min :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
Ord, Int -> ShelleyNodeToClientVersion
ShelleyNodeToClientVersion -> Int
ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion
-> [ShelleyNodeToClientVersion]
(ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion)
-> (ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion)
-> (Int -> ShelleyNodeToClientVersion)
-> (ShelleyNodeToClientVersion -> Int)
-> (ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion])
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion])
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion])
-> (ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion
    -> ShelleyNodeToClientVersion
    -> [ShelleyNodeToClientVersion])
-> Enum ShelleyNodeToClientVersion
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
succ :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
$cpred :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
pred :: ShelleyNodeToClientVersion -> ShelleyNodeToClientVersion
$ctoEnum :: Int -> ShelleyNodeToClientVersion
toEnum :: Int -> ShelleyNodeToClientVersion
$cfromEnum :: ShelleyNodeToClientVersion -> Int
fromEnum :: ShelleyNodeToClientVersion -> Int
$cenumFrom :: ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
enumFrom :: ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
$cenumFromThen :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
enumFromThen :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
$cenumFromTo :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
enumFromTo :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> [ShelleyNodeToClientVersion]
$cenumFromThenTo :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion
-> [ShelleyNodeToClientVersion]
enumFromThenTo :: ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion
-> [ShelleyNodeToClientVersion]
Enum, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion
-> ShelleyNodeToClientVersion -> Bounded ShelleyNodeToClientVersion
forall a. a -> a -> Bounded a
$cminBound :: ShelleyNodeToClientVersion
minBound :: ShelleyNodeToClientVersion
$cmaxBound :: ShelleyNodeToClientVersion
maxBound :: ShelleyNodeToClientVersion
Bounded)

instance HasNetworkProtocolVersion (ShelleyBlock proto era) where
  type BlockNodeToNodeVersion   (ShelleyBlock proto era) = ShelleyNodeToNodeVersion
  type BlockNodeToClientVersion (ShelleyBlock proto era) = ShelleyNodeToClientVersion

-- TODO #2668 make this era-specific
instance SupportedNetworkProtocolVersion (ShelleyBlock proto era) where
  supportedNodeToNodeVersions :: Proxy (ShelleyBlock proto era)
-> Map
     NodeToNodeVersion (BlockNodeToNodeVersion (ShelleyBlock proto era))
supportedNodeToNodeVersions   Proxy (ShelleyBlock proto era)
_ = [(NodeToNodeVersion, ShelleyNodeToNodeVersion)]
-> Map NodeToNodeVersion ShelleyNodeToNodeVersion
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [
        (NodeToNodeVersion
NodeToNodeV_7,  ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion1)
      , (NodeToNodeVersion
NodeToNodeV_8,  ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion1)
      , (NodeToNodeVersion
NodeToNodeV_9,  ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion1)
      , (NodeToNodeVersion
NodeToNodeV_10, ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion1)
      , (NodeToNodeVersion
NodeToNodeV_11, ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion1)
      , (NodeToNodeVersion
NodeToNodeV_12, ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion1)
      , (NodeToNodeVersion
NodeToNodeV_13, ShelleyNodeToNodeVersion
ShelleyNodeToNodeVersion1)
      ]
  supportedNodeToClientVersions :: Proxy (ShelleyBlock proto era)
-> Map
     NodeToClientVersion
     (BlockNodeToClientVersion (ShelleyBlock proto era))
supportedNodeToClientVersions Proxy (ShelleyBlock proto era)
_ = [(NodeToClientVersion, ShelleyNodeToClientVersion)]
-> Map NodeToClientVersion ShelleyNodeToClientVersion
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [
        (NodeToClientVersion
NodeToClientV_9,  ShelleyNodeToClientVersion
ShelleyNodeToClientVersion5)
      , (NodeToClientVersion
NodeToClientV_10, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion5)
      , (NodeToClientVersion
NodeToClientV_11, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion5)
      , (NodeToClientVersion
NodeToClientV_12, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion5)
      , (NodeToClientVersion
NodeToClientV_13, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion5)
      , (NodeToClientVersion
NodeToClientV_14, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion6)
      , (NodeToClientVersion
NodeToClientV_15, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion7)
      , (NodeToClientVersion
NodeToClientV_16, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion8)
      , (NodeToClientVersion
NodeToClientV_17, ShelleyNodeToClientVersion
ShelleyNodeToClientVersion9)
      ]

  latestReleasedNodeVersion :: Proxy (ShelleyBlock proto era)
-> (Maybe NodeToNodeVersion, Maybe NodeToClientVersion)
latestReleasedNodeVersion = Proxy (ShelleyBlock proto era)
-> (Maybe NodeToNodeVersion, Maybe NodeToClientVersion)
forall blk.
SupportedNetworkProtocolVersion blk =>
Proxy blk -> (Maybe NodeToNodeVersion, Maybe NodeToClientVersion)
latestReleasedNodeVersionDefault