{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric  #-}

module Ouroboros.Network.Point
  ( WithOrigin (..)
  , Block (..)
  , origin
  , at
  , block
  , fromWithOrigin
  , withOrigin
  , withOriginToMaybe
  , withOriginFromMaybe
  ) where

import Data.Aeson
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)

import Cardano.Slotting.Slot

data Block slot hash = Block
  { forall slot hash. Block slot hash -> slot
blockPointSlot :: !slot
  , forall slot hash. Block slot hash -> hash
blockPointHash :: !hash
  }
  deriving (Block slot hash -> Block slot hash -> Bool
(Block slot hash -> Block slot hash -> Bool)
-> (Block slot hash -> Block slot hash -> Bool)
-> Eq (Block slot hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall slot hash.
(Eq slot, Eq hash) =>
Block slot hash -> Block slot hash -> Bool
$c== :: forall slot hash.
(Eq slot, Eq hash) =>
Block slot hash -> Block slot hash -> Bool
== :: Block slot hash -> Block slot hash -> Bool
$c/= :: forall slot hash.
(Eq slot, Eq hash) =>
Block slot hash -> Block slot hash -> Bool
/= :: Block slot hash -> Block slot hash -> Bool
Eq, Eq (Block slot hash)
Eq (Block slot hash) =>
(Block slot hash -> Block slot hash -> Ordering)
-> (Block slot hash -> Block slot hash -> Bool)
-> (Block slot hash -> Block slot hash -> Bool)
-> (Block slot hash -> Block slot hash -> Bool)
-> (Block slot hash -> Block slot hash -> Bool)
-> (Block slot hash -> Block slot hash -> Block slot hash)
-> (Block slot hash -> Block slot hash -> Block slot hash)
-> Ord (Block slot hash)
Block slot hash -> Block slot hash -> Bool
Block slot hash -> Block slot hash -> Ordering
Block slot hash -> Block slot hash -> Block slot hash
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 slot hash. (Ord slot, Ord hash) => Eq (Block slot hash)
forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Bool
forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Ordering
forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Block slot hash
$ccompare :: forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Ordering
compare :: Block slot hash -> Block slot hash -> Ordering
$c< :: forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Bool
< :: Block slot hash -> Block slot hash -> Bool
$c<= :: forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Bool
<= :: Block slot hash -> Block slot hash -> Bool
$c> :: forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Bool
> :: Block slot hash -> Block slot hash -> Bool
$c>= :: forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Bool
>= :: Block slot hash -> Block slot hash -> Bool
$cmax :: forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Block slot hash
max :: Block slot hash -> Block slot hash -> Block slot hash
$cmin :: forall slot hash.
(Ord slot, Ord hash) =>
Block slot hash -> Block slot hash -> Block slot hash
min :: Block slot hash -> Block slot hash -> Block slot hash
Ord, Int -> Block slot hash -> ShowS
[Block slot hash] -> ShowS
Block slot hash -> String
(Int -> Block slot hash -> ShowS)
-> (Block slot hash -> String)
-> ([Block slot hash] -> ShowS)
-> Show (Block slot hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall slot hash.
(Show slot, Show hash) =>
Int -> Block slot hash -> ShowS
forall slot hash.
(Show slot, Show hash) =>
[Block slot hash] -> ShowS
forall slot hash.
(Show slot, Show hash) =>
Block slot hash -> String
$cshowsPrec :: forall slot hash.
(Show slot, Show hash) =>
Int -> Block slot hash -> ShowS
showsPrec :: Int -> Block slot hash -> ShowS
$cshow :: forall slot hash.
(Show slot, Show hash) =>
Block slot hash -> String
show :: Block slot hash -> String
$cshowList :: forall slot hash.
(Show slot, Show hash) =>
[Block slot hash] -> ShowS
showList :: [Block slot hash] -> ShowS
Show, [Block slot hash] -> Value
[Block slot hash] -> Encoding
Block slot hash -> Bool
Block slot hash -> Value
Block slot hash -> Encoding
(Block slot hash -> Value)
-> (Block slot hash -> Encoding)
-> ([Block slot hash] -> Value)
-> ([Block slot hash] -> Encoding)
-> (Block slot hash -> Bool)
-> ToJSON (Block slot hash)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
forall slot hash.
(ToJSON hash, ToJSON slot) =>
[Block slot hash] -> Value
forall slot hash.
(ToJSON hash, ToJSON slot) =>
[Block slot hash] -> Encoding
forall slot hash.
(ToJSON hash, ToJSON slot) =>
Block slot hash -> Bool
forall slot hash.
(ToJSON hash, ToJSON slot) =>
Block slot hash -> Value
forall slot hash.
(ToJSON hash, ToJSON slot) =>
Block slot hash -> Encoding
$ctoJSON :: forall slot hash.
(ToJSON hash, ToJSON slot) =>
Block slot hash -> Value
toJSON :: Block slot hash -> Value
$ctoEncoding :: forall slot hash.
(ToJSON hash, ToJSON slot) =>
Block slot hash -> Encoding
toEncoding :: Block slot hash -> Encoding
$ctoJSONList :: forall slot hash.
(ToJSON hash, ToJSON slot) =>
[Block slot hash] -> Value
toJSONList :: [Block slot hash] -> Value
$ctoEncodingList :: forall slot hash.
(ToJSON hash, ToJSON slot) =>
[Block slot hash] -> Encoding
toEncodingList :: [Block slot hash] -> Encoding
$comitField :: forall slot hash.
(ToJSON hash, ToJSON slot) =>
Block slot hash -> Bool
omitField :: Block slot hash -> Bool
ToJSON, Maybe (Block slot hash)
Value -> Parser [Block slot hash]
Value -> Parser (Block slot hash)
(Value -> Parser (Block slot hash))
-> (Value -> Parser [Block slot hash])
-> Maybe (Block slot hash)
-> FromJSON (Block slot hash)
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
forall slot hash.
(FromJSON slot, FromJSON hash) =>
Maybe (Block slot hash)
forall slot hash.
(FromJSON slot, FromJSON hash) =>
Value -> Parser [Block slot hash]
forall slot hash.
(FromJSON slot, FromJSON hash) =>
Value -> Parser (Block slot hash)
$cparseJSON :: forall slot hash.
(FromJSON slot, FromJSON hash) =>
Value -> Parser (Block slot hash)
parseJSON :: Value -> Parser (Block slot hash)
$cparseJSONList :: forall slot hash.
(FromJSON slot, FromJSON hash) =>
Value -> Parser [Block slot hash]
parseJSONList :: Value -> Parser [Block slot hash]
$comittedField :: forall slot hash.
(FromJSON slot, FromJSON hash) =>
Maybe (Block slot hash)
omittedField :: Maybe (Block slot hash)
FromJSON, (forall x. Block slot hash -> Rep (Block slot hash) x)
-> (forall x. Rep (Block slot hash) x -> Block slot hash)
-> Generic (Block slot hash)
forall x. Rep (Block slot hash) x -> Block slot hash
forall x. Block slot hash -> Rep (Block slot hash) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall slot hash x. Rep (Block slot hash) x -> Block slot hash
forall slot hash x. Block slot hash -> Rep (Block slot hash) x
$cfrom :: forall slot hash x. Block slot hash -> Rep (Block slot hash) x
from :: forall x. Block slot hash -> Rep (Block slot hash) x
$cto :: forall slot hash x. Rep (Block slot hash) x -> Block slot hash
to :: forall x. Rep (Block slot hash) x -> Block slot hash
Generic, Context -> Block slot hash -> IO (Maybe ThunkInfo)
Proxy (Block slot hash) -> String
(Context -> Block slot hash -> IO (Maybe ThunkInfo))
-> (Context -> Block slot hash -> IO (Maybe ThunkInfo))
-> (Proxy (Block slot hash) -> String)
-> NoThunks (Block slot hash)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall slot hash.
(NoThunks slot, NoThunks hash) =>
Context -> Block slot hash -> IO (Maybe ThunkInfo)
forall slot hash.
(NoThunks slot, NoThunks hash) =>
Proxy (Block slot hash) -> String
$cnoThunks :: forall slot hash.
(NoThunks slot, NoThunks hash) =>
Context -> Block slot hash -> IO (Maybe ThunkInfo)
noThunks :: Context -> Block slot hash -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall slot hash.
(NoThunks slot, NoThunks hash) =>
Context -> Block slot hash -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> Block slot hash -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall slot hash.
(NoThunks slot, NoThunks hash) =>
Proxy (Block slot hash) -> String
showTypeOf :: Proxy (Block slot hash) -> String
NoThunks)

block :: slot -> hash -> WithOrigin (Block slot hash)
block :: forall slot hash. slot -> hash -> WithOrigin (Block slot hash)
block slot
slot hash
hash = Block slot hash -> WithOrigin (Block slot hash)
forall t. t -> WithOrigin t
at (slot -> hash -> Block slot hash
forall slot hash. slot -> hash -> Block slot hash
Block slot
slot hash
hash)