{-# LANGUAGE TypeFamilies #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Ouroboros.Consensus.Byron.Ledger.NetworkProtocolVersion (
    ByronNodeToClientVersion (..)
  , ByronNodeToNodeVersion (..)
  ) where

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

data ByronNodeToNodeVersion =
    -- | We send headers without a size hint
    ByronNodeToNodeVersion1

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

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

instance HasNetworkProtocolVersion ByronBlock where
  type BlockNodeToNodeVersion   ByronBlock = ByronNodeToNodeVersion
  type BlockNodeToClientVersion ByronBlock = ByronNodeToClientVersion

-- | This instance isn't used apart from tests; we therefore make our life easy
-- below.
instance SupportedNetworkProtocolVersion ByronBlock where
  supportedNodeToNodeVersions :: Proxy ByronBlock
-> Map NodeToNodeVersion (BlockNodeToNodeVersion ByronBlock)
supportedNodeToNodeVersions   Proxy ByronBlock
_ = [(NodeToNodeVersion, ByronNodeToNodeVersion)]
-> Map NodeToNodeVersion ByronNodeToNodeVersion
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
      [ (NodeToNodeVersion
v, ByronNodeToNodeVersion
ByronNodeToNodeVersion2)
      | NodeToNodeVersion
v <- [NodeToNodeVersion
forall a. Bounded a => a
minBound .. NodeToNodeVersion
forall a. Bounded a => a
maxBound]
      ]

  supportedNodeToClientVersions :: Proxy ByronBlock
-> Map NodeToClientVersion (BlockNodeToClientVersion ByronBlock)
supportedNodeToClientVersions Proxy ByronBlock
_ = [(NodeToClientVersion, ByronNodeToClientVersion)]
-> Map NodeToClientVersion ByronNodeToClientVersion
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
      [ (NodeToClientVersion
v, ByronNodeToClientVersion
ByronNodeToClientVersion1)
      | NodeToClientVersion
v <- [NodeToClientVersion
forall a. Bounded a => a
minBound .. NodeToClientVersion
forall a. Bounded a => a
maxBound]
      ]

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