{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}

module Cardano.Ledger.AuxiliaryData
  ( AuxiliaryDataHash (..),
    ValidateAuxiliaryData (..),
  )
where

import Cardano.Binary (FromCBOR, ToCBOR)
import Cardano.Ledger.BaseTypes (ProtVer)
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as CC (Crypto)
import Cardano.Ledger.Hashes (EraIndependentAuxiliaryData)
import Cardano.Ledger.SafeHash (SafeHash)
import Control.DeepSeq (NFData (..))
import NoThunks.Class (NoThunks (..))

newtype AuxiliaryDataHash crypto = AuxiliaryDataHash
  { AuxiliaryDataHash crypto
-> SafeHash crypto EraIndependentAuxiliaryData
unsafeAuxiliaryDataHash :: SafeHash crypto EraIndependentAuxiliaryData
  }
  deriving (Int -> AuxiliaryDataHash crypto -> ShowS
[AuxiliaryDataHash crypto] -> ShowS
AuxiliaryDataHash crypto -> String
(Int -> AuxiliaryDataHash crypto -> ShowS)
-> (AuxiliaryDataHash crypto -> String)
-> ([AuxiliaryDataHash crypto] -> ShowS)
-> Show (AuxiliaryDataHash crypto)
forall crypto. Int -> AuxiliaryDataHash crypto -> ShowS
forall crypto. [AuxiliaryDataHash crypto] -> ShowS
forall crypto. AuxiliaryDataHash crypto -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuxiliaryDataHash crypto] -> ShowS
$cshowList :: forall crypto. [AuxiliaryDataHash crypto] -> ShowS
show :: AuxiliaryDataHash crypto -> String
$cshow :: forall crypto. AuxiliaryDataHash crypto -> String
showsPrec :: Int -> AuxiliaryDataHash crypto -> ShowS
$cshowsPrec :: forall crypto. Int -> AuxiliaryDataHash crypto -> ShowS
Show, AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
(AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool)
-> (AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool)
-> Eq (AuxiliaryDataHash crypto)
forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
$c/= :: forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
== :: AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
$c== :: forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
Eq, Eq (AuxiliaryDataHash crypto)
Eq (AuxiliaryDataHash crypto)
-> (AuxiliaryDataHash crypto
    -> AuxiliaryDataHash crypto -> Ordering)
-> (AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool)
-> (AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool)
-> (AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool)
-> (AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool)
-> (AuxiliaryDataHash crypto
    -> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto)
-> (AuxiliaryDataHash crypto
    -> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto)
-> Ord (AuxiliaryDataHash crypto)
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Ordering
AuxiliaryDataHash crypto
-> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto
forall crypto. Eq (AuxiliaryDataHash crypto)
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 crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Ordering
forall crypto.
AuxiliaryDataHash crypto
-> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto
min :: AuxiliaryDataHash crypto
-> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto
$cmin :: forall crypto.
AuxiliaryDataHash crypto
-> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto
max :: AuxiliaryDataHash crypto
-> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto
$cmax :: forall crypto.
AuxiliaryDataHash crypto
-> AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto
>= :: AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
$c>= :: forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
> :: AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
$c> :: forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
<= :: AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
$c<= :: forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
< :: AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
$c< :: forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Bool
compare :: AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Ordering
$ccompare :: forall crypto.
AuxiliaryDataHash crypto -> AuxiliaryDataHash crypto -> Ordering
$cp1Ord :: forall crypto. Eq (AuxiliaryDataHash crypto)
Ord, Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo)
Proxy (AuxiliaryDataHash crypto) -> String
(Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo))
-> (Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo))
-> (Proxy (AuxiliaryDataHash crypto) -> String)
-> NoThunks (AuxiliaryDataHash crypto)
forall crypto.
Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo)
forall crypto. Proxy (AuxiliaryDataHash crypto) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (AuxiliaryDataHash crypto) -> String
$cshowTypeOf :: forall crypto. Proxy (AuxiliaryDataHash crypto) -> String
wNoThunks :: Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall crypto.
Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo)
noThunks :: Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo)
$cnoThunks :: forall crypto.
Context -> AuxiliaryDataHash crypto -> IO (Maybe ThunkInfo)
NoThunks, AuxiliaryDataHash crypto -> ()
(AuxiliaryDataHash crypto -> ())
-> NFData (AuxiliaryDataHash crypto)
forall crypto. AuxiliaryDataHash crypto -> ()
forall a. (a -> ()) -> NFData a
rnf :: AuxiliaryDataHash crypto -> ()
$crnf :: forall crypto. AuxiliaryDataHash crypto -> ()
NFData)

deriving instance
  CC.Crypto crypto =>
  ToCBOR (AuxiliaryDataHash crypto)

deriving instance
  CC.Crypto crypto =>
  FromCBOR (AuxiliaryDataHash crypto)

class ValidateAuxiliaryData era c | era -> c where
  hashAuxiliaryData :: Core.AuxiliaryData era -> AuxiliaryDataHash c
  validateAuxiliaryData :: ProtVer -> Core.AuxiliaryData era -> Bool