{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.CanonicalState.Namespace.EntitiesStakePools.VRFKeyHashes.V0 (
  EntitiesStakePoolsVRFKeyHashesIn (..),
  EntitiesStakePoolsVRFKeyHashesOut (..),
) where

import Cardano.Ledger.BaseTypes (NonZero)
import Cardano.Ledger.CanonicalState.Namespace (Era, NamespaceEra)
import Cardano.Ledger.Core (
  KeyRoleVRF (StakePoolVRF),
  VRFVerKeyHash,
  fromVRFVerKeyHash,
  toVRFVerKeyHash,
 )
import Cardano.SCLS.CBOR.Canonical.Decoder (FromCanonicalCBOR (..))
import Cardano.SCLS.CBOR.Canonical.Encoder (ToCanonicalCBOR (..))
import Cardano.SCLS.Entry.IsKey (IsKey (..))
import Cardano.SCLS.NamespaceCodec (
  CanonicalCBOREntryDecoder (..),
  CanonicalCBOREntryEncoder (..),
  KnownNamespace (..),
  NamespaceKeySize,
  namespaceKeySize,
 )
import Cardano.SCLS.Versioned (Versioned (..))
import Data.MemPack (MemPack (packM, unpackM))
import Data.Proxy (Proxy (..))
import Data.Word (Word64)
import GHC.Generics (Generic)

instance
  ( Era era
  , NamespaceEra "entities/stake_pools/vrf_key_hashes/v0" ~ era
  , ToCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut
  , FromCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut
  ) =>
  KnownNamespace "entities/stake_pools/vrf_key_hashes/v0"
  where
  type NamespaceKey "entities/stake_pools/vrf_key_hashes/v0" = EntitiesStakePoolsVRFKeyHashesIn
  type NamespaceEntry "entities/stake_pools/vrf_key_hashes/v0" = EntitiesStakePoolsVRFKeyHashesOut

instance
  ( Era era
  , NamespaceEra "entities/stake_pools/vrf_key_hashes/v0" ~ era
  , ToCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut
  ) =>
  CanonicalCBOREntryEncoder "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut
  where
  encodeEntry :: EntitiesStakePoolsVRFKeyHashesOut -> CanonicalEncoding
encodeEntry = Proxy "entities/stake_pools/vrf_key_hashes/v0"
-> EntitiesStakePoolsVRFKeyHashesOut -> CanonicalEncoding
forall (v :: Symbol) a (proxy :: Symbol -> *).
ToCanonicalCBOR v a =>
proxy v -> a -> CanonicalEncoding
forall (proxy :: Symbol -> *).
proxy "entities/stake_pools/vrf_key_hashes/v0"
-> EntitiesStakePoolsVRFKeyHashesOut -> CanonicalEncoding
toCanonicalCBOR (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @"entities/stake_pools/vrf_key_hashes/v0")

instance
  ( Era era
  , NamespaceEra "entities/stake_pools/vrf_key_hashes/v0" ~ era
  , FromCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut
  ) =>
  CanonicalCBOREntryDecoder "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut
  where
  decodeEntry :: forall s.
CanonicalDecoder
  s
  (Versioned
     "entities/stake_pools/vrf_key_hashes/v0"
     EntitiesStakePoolsVRFKeyHashesOut)
decodeEntry = CanonicalDecoder
  s
  (Versioned
     "entities/stake_pools/vrf_key_hashes/v0"
     EntitiesStakePoolsVRFKeyHashesOut)
forall s.
CanonicalDecoder
  s
  (Versioned
     "entities/stake_pools/vrf_key_hashes/v0"
     EntitiesStakePoolsVRFKeyHashesOut)
forall (v :: Symbol) a s.
FromCanonicalCBOR v a =>
CanonicalDecoder s (Versioned v a)
fromCanonicalCBOR

newtype EntitiesStakePoolsVRFKeyHashesIn = EntitiesStakePoolsVRFKeyHashesIn (VRFVerKeyHash StakePoolVRF)
  deriving (EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
(EntitiesStakePoolsVRFKeyHashesIn
 -> EntitiesStakePoolsVRFKeyHashesIn -> Bool)
-> (EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn -> Bool)
-> Eq EntitiesStakePoolsVRFKeyHashesIn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
== :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
$c/= :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
/= :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
Eq, Eq EntitiesStakePoolsVRFKeyHashesIn
Eq EntitiesStakePoolsVRFKeyHashesIn =>
(EntitiesStakePoolsVRFKeyHashesIn
 -> EntitiesStakePoolsVRFKeyHashesIn -> Ordering)
-> (EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn -> Bool)
-> (EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn -> Bool)
-> (EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn -> Bool)
-> (EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn -> Bool)
-> (EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn)
-> (EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn
    -> EntitiesStakePoolsVRFKeyHashesIn)
-> Ord EntitiesStakePoolsVRFKeyHashesIn
EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Ordering
EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
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 :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Ordering
compare :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Ordering
$c< :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
< :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
$c<= :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
<= :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
$c> :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
> :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
$c>= :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
>= :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn -> Bool
$cmax :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
max :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
$cmin :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
min :: EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
-> EntitiesStakePoolsVRFKeyHashesIn
Ord, Int -> EntitiesStakePoolsVRFKeyHashesIn -> ShowS
[EntitiesStakePoolsVRFKeyHashesIn] -> ShowS
EntitiesStakePoolsVRFKeyHashesIn -> String
(Int -> EntitiesStakePoolsVRFKeyHashesIn -> ShowS)
-> (EntitiesStakePoolsVRFKeyHashesIn -> String)
-> ([EntitiesStakePoolsVRFKeyHashesIn] -> ShowS)
-> Show EntitiesStakePoolsVRFKeyHashesIn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EntitiesStakePoolsVRFKeyHashesIn -> ShowS
showsPrec :: Int -> EntitiesStakePoolsVRFKeyHashesIn -> ShowS
$cshow :: EntitiesStakePoolsVRFKeyHashesIn -> String
show :: EntitiesStakePoolsVRFKeyHashesIn -> String
$cshowList :: [EntitiesStakePoolsVRFKeyHashesIn] -> ShowS
showList :: [EntitiesStakePoolsVRFKeyHashesIn] -> ShowS
Show)

type instance NamespaceKeySize "entities/stake_pools/vrf_key_hashes/v0" = 32

instance IsKey EntitiesStakePoolsVRFKeyHashesIn where
  keySize :: Int
keySize = forall (ns :: Symbol). KnownNat (NamespaceKeySize ns) => Int
namespaceKeySize @"entities/stake_pools/vrf_key_hashes/v0"
  packKeyM :: forall b. EntitiesStakePoolsVRFKeyHashesIn -> Pack b ()
packKeyM (EntitiesStakePoolsVRFKeyHashesIn VRFVerKeyHash StakePoolVRF
stakePoolVRF) =
    Hash HASH (VerKeyVRF (ZonkAny 0)) -> Pack b ()
forall s. Hash HASH (VerKeyVRF (ZonkAny 0)) -> Pack s ()
forall a s. MemPack a => a -> Pack s ()
packM (Hash HASH (VerKeyVRF (ZonkAny 0)) -> Pack b ())
-> Hash HASH (VerKeyVRF (ZonkAny 0)) -> Pack b ()
forall a b. (a -> b) -> a -> b
$ VRFVerKeyHash StakePoolVRF -> Hash HASH (VerKeyVRF (ZonkAny 0))
forall (r :: KeyRoleVRF) v.
VRFVerKeyHash r -> Hash HASH (VerKeyVRF v)
fromVRFVerKeyHash VRFVerKeyHash StakePoolVRF
stakePoolVRF
  unpackKeyM :: forall b s.
Buffer b =>
Unpack' s b EntitiesStakePoolsVRFKeyHashesIn
unpackKeyM =
    VRFVerKeyHash StakePoolVRF -> EntitiesStakePoolsVRFKeyHashesIn
EntitiesStakePoolsVRFKeyHashesIn (VRFVerKeyHash StakePoolVRF -> EntitiesStakePoolsVRFKeyHashesIn)
-> (Hash HASH (VerKeyVRF (ZonkAny 1))
    -> VRFVerKeyHash StakePoolVRF)
-> Hash HASH (VerKeyVRF (ZonkAny 1))
-> EntitiesStakePoolsVRFKeyHashesIn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash HASH (VerKeyVRF (ZonkAny 1)) -> VRFVerKeyHash StakePoolVRF
forall v (r :: KeyRoleVRF).
Hash HASH (VerKeyVRF v) -> VRFVerKeyHash r
toVRFVerKeyHash (Hash HASH (VerKeyVRF (ZonkAny 1))
 -> EntitiesStakePoolsVRFKeyHashesIn)
-> Unpack s b (Hash HASH (VerKeyVRF (ZonkAny 1)))
-> Unpack s b EntitiesStakePoolsVRFKeyHashesIn
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Unpack s b (Hash HASH (VerKeyVRF (ZonkAny 1)))
forall a b s. (MemPack a, Buffer b) => Unpack s b a
forall b s.
Buffer b =>
Unpack s b (Hash HASH (VerKeyVRF (ZonkAny 1)))
unpackM

newtype EntitiesStakePoolsVRFKeyHashesOut
  = EntitiesStakePoolsVRFKeyHashesOut (NonZero Word64)
  deriving (EntitiesStakePoolsVRFKeyHashesOut
-> EntitiesStakePoolsVRFKeyHashesOut -> Bool
(EntitiesStakePoolsVRFKeyHashesOut
 -> EntitiesStakePoolsVRFKeyHashesOut -> Bool)
-> (EntitiesStakePoolsVRFKeyHashesOut
    -> EntitiesStakePoolsVRFKeyHashesOut -> Bool)
-> Eq EntitiesStakePoolsVRFKeyHashesOut
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EntitiesStakePoolsVRFKeyHashesOut
-> EntitiesStakePoolsVRFKeyHashesOut -> Bool
== :: EntitiesStakePoolsVRFKeyHashesOut
-> EntitiesStakePoolsVRFKeyHashesOut -> Bool
$c/= :: EntitiesStakePoolsVRFKeyHashesOut
-> EntitiesStakePoolsVRFKeyHashesOut -> Bool
/= :: EntitiesStakePoolsVRFKeyHashesOut
-> EntitiesStakePoolsVRFKeyHashesOut -> Bool
Eq, Int -> EntitiesStakePoolsVRFKeyHashesOut -> ShowS
[EntitiesStakePoolsVRFKeyHashesOut] -> ShowS
EntitiesStakePoolsVRFKeyHashesOut -> String
(Int -> EntitiesStakePoolsVRFKeyHashesOut -> ShowS)
-> (EntitiesStakePoolsVRFKeyHashesOut -> String)
-> ([EntitiesStakePoolsVRFKeyHashesOut] -> ShowS)
-> Show EntitiesStakePoolsVRFKeyHashesOut
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EntitiesStakePoolsVRFKeyHashesOut -> ShowS
showsPrec :: Int -> EntitiesStakePoolsVRFKeyHashesOut -> ShowS
$cshow :: EntitiesStakePoolsVRFKeyHashesOut -> String
show :: EntitiesStakePoolsVRFKeyHashesOut -> String
$cshowList :: [EntitiesStakePoolsVRFKeyHashesOut] -> ShowS
showList :: [EntitiesStakePoolsVRFKeyHashesOut] -> ShowS
Show, (forall x.
 EntitiesStakePoolsVRFKeyHashesOut
 -> Rep EntitiesStakePoolsVRFKeyHashesOut x)
-> (forall x.
    Rep EntitiesStakePoolsVRFKeyHashesOut x
    -> EntitiesStakePoolsVRFKeyHashesOut)
-> Generic EntitiesStakePoolsVRFKeyHashesOut
forall x.
Rep EntitiesStakePoolsVRFKeyHashesOut x
-> EntitiesStakePoolsVRFKeyHashesOut
forall x.
EntitiesStakePoolsVRFKeyHashesOut
-> Rep EntitiesStakePoolsVRFKeyHashesOut x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
EntitiesStakePoolsVRFKeyHashesOut
-> Rep EntitiesStakePoolsVRFKeyHashesOut x
from :: forall x.
EntitiesStakePoolsVRFKeyHashesOut
-> Rep EntitiesStakePoolsVRFKeyHashesOut x
$cto :: forall x.
Rep EntitiesStakePoolsVRFKeyHashesOut x
-> EntitiesStakePoolsVRFKeyHashesOut
to :: forall x.
Rep EntitiesStakePoolsVRFKeyHashesOut x
-> EntitiesStakePoolsVRFKeyHashesOut
Generic)

deriving newtype instance
  ToCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" (NonZero Word64) =>
  ToCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut

deriving newtype instance
  FromCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" (NonZero Word64) =>
  FromCanonicalCBOR "entities/stake_pools/vrf_key_hashes/v0" EntitiesStakePoolsVRFKeyHashesOut