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

  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