module Ouroboros.Consensus.Ledger.Query.Version (
    QueryVersion (..)
  , nodeToClientVersionToQueryVersion
  ) where

import           Ouroboros.Network.NodeToClient.Version

-- | Version of the `Query blk` type.
--
-- Multiple top level queries are now supported. The encoding now has
-- constructor tags for the different top level queries for QueryVersion1 onwards.
data QueryVersion
  -- Adds support for 'GetSystemStart'.
  = QueryVersion1

  -- Adds support for 'GetChainBlockNo' and 'GetChainPoint'.
  | QueryVersion2
  deriving (QueryVersion -> QueryVersion -> Bool
(QueryVersion -> QueryVersion -> Bool)
-> (QueryVersion -> QueryVersion -> Bool) -> Eq QueryVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryVersion -> QueryVersion -> Bool
$c/= :: QueryVersion -> QueryVersion -> Bool
== :: QueryVersion -> QueryVersion -> Bool
$c== :: QueryVersion -> QueryVersion -> Bool
Eq, Eq QueryVersion
Eq QueryVersion
-> (QueryVersion -> QueryVersion -> Ordering)
-> (QueryVersion -> QueryVersion -> Bool)
-> (QueryVersion -> QueryVersion -> Bool)
-> (QueryVersion -> QueryVersion -> Bool)
-> (QueryVersion -> QueryVersion -> Bool)
-> (QueryVersion -> QueryVersion -> QueryVersion)
-> (QueryVersion -> QueryVersion -> QueryVersion)
-> Ord QueryVersion
QueryVersion -> QueryVersion -> Bool
QueryVersion -> QueryVersion -> Ordering
QueryVersion -> QueryVersion -> QueryVersion
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 :: QueryVersion -> QueryVersion -> QueryVersion
$cmin :: QueryVersion -> QueryVersion -> QueryVersion
max :: QueryVersion -> QueryVersion -> QueryVersion
$cmax :: QueryVersion -> QueryVersion -> QueryVersion
>= :: QueryVersion -> QueryVersion -> Bool
$c>= :: QueryVersion -> QueryVersion -> Bool
> :: QueryVersion -> QueryVersion -> Bool
$c> :: QueryVersion -> QueryVersion -> Bool
<= :: QueryVersion -> QueryVersion -> Bool
$c<= :: QueryVersion -> QueryVersion -> Bool
< :: QueryVersion -> QueryVersion -> Bool
$c< :: QueryVersion -> QueryVersion -> Bool
compare :: QueryVersion -> QueryVersion -> Ordering
$ccompare :: QueryVersion -> QueryVersion -> Ordering
$cp1Ord :: Eq QueryVersion
Ord, Int -> QueryVersion
QueryVersion -> Int
QueryVersion -> [QueryVersion]
QueryVersion -> QueryVersion
QueryVersion -> QueryVersion -> [QueryVersion]
QueryVersion -> QueryVersion -> QueryVersion -> [QueryVersion]
(QueryVersion -> QueryVersion)
-> (QueryVersion -> QueryVersion)
-> (Int -> QueryVersion)
-> (QueryVersion -> Int)
-> (QueryVersion -> [QueryVersion])
-> (QueryVersion -> QueryVersion -> [QueryVersion])
-> (QueryVersion -> QueryVersion -> [QueryVersion])
-> (QueryVersion -> QueryVersion -> QueryVersion -> [QueryVersion])
-> Enum QueryVersion
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 :: QueryVersion -> QueryVersion -> QueryVersion -> [QueryVersion]
$cenumFromThenTo :: QueryVersion -> QueryVersion -> QueryVersion -> [QueryVersion]
enumFromTo :: QueryVersion -> QueryVersion -> [QueryVersion]
$cenumFromTo :: QueryVersion -> QueryVersion -> [QueryVersion]
enumFromThen :: QueryVersion -> QueryVersion -> [QueryVersion]
$cenumFromThen :: QueryVersion -> QueryVersion -> [QueryVersion]
enumFrom :: QueryVersion -> [QueryVersion]
$cenumFrom :: QueryVersion -> [QueryVersion]
fromEnum :: QueryVersion -> Int
$cfromEnum :: QueryVersion -> Int
toEnum :: Int -> QueryVersion
$ctoEnum :: Int -> QueryVersion
pred :: QueryVersion -> QueryVersion
$cpred :: QueryVersion -> QueryVersion
succ :: QueryVersion -> QueryVersion
$csucc :: QueryVersion -> QueryVersion
Enum, QueryVersion
QueryVersion -> QueryVersion -> Bounded QueryVersion
forall a. a -> a -> Bounded a
maxBound :: QueryVersion
$cmaxBound :: QueryVersion
minBound :: QueryVersion
$cminBound :: QueryVersion
Bounded, Int -> QueryVersion -> ShowS
[QueryVersion] -> ShowS
QueryVersion -> String
(Int -> QueryVersion -> ShowS)
-> (QueryVersion -> String)
-> ([QueryVersion] -> ShowS)
-> Show QueryVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryVersion] -> ShowS
$cshowList :: [QueryVersion] -> ShowS
show :: QueryVersion -> String
$cshow :: QueryVersion -> String
showsPrec :: Int -> QueryVersion -> ShowS
$cshowsPrec :: Int -> QueryVersion -> ShowS
Show)

-- | Get the @QueryVersion@ supported by this @NodeToClientVersion@.
nodeToClientVersionToQueryVersion :: NodeToClientVersion -> QueryVersion
nodeToClientVersionToQueryVersion :: NodeToClientVersion -> QueryVersion
nodeToClientVersionToQueryVersion NodeToClientVersion
x = case NodeToClientVersion
x of
  NodeToClientVersion
NodeToClientV_9  -> QueryVersion
QueryVersion1
  NodeToClientVersion
NodeToClientV_10 -> QueryVersion
QueryVersion2
  NodeToClientVersion
NodeToClientV_11 -> QueryVersion
QueryVersion2
  NodeToClientVersion
NodeToClientV_12 -> QueryVersion
QueryVersion2
  NodeToClientVersion
NodeToClientV_13 -> QueryVersion
QueryVersion2