{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-missed-specialisations #-}

module Cardano.Chain.Genesis.AvvmBalances
  ( GenesisAvvmBalances (..),
  )
where

import Cardano.Binary
  ( FromCBOR (..),
    ToCBOR (..),
    encodeListLen,
    enforceSize,
  )
import Cardano.Chain.Common (Lovelace)
import Cardano.Crypto.Signing.Redeem (CompactRedeemVerificationKey)
import Cardano.Prelude
import NoThunks.Class (NoThunks (..))
import Text.JSON.Canonical (FromJSON (..), ToJSON (..))

-- | Predefined balances of AVVM (Ada Voucher Vending Machine) entries.
-- People who purchased Ada at a pre-sale were issued a certificate during
-- the pre-sale period. These certificates allow customers to redeem ADA.
newtype GenesisAvvmBalances = GenesisAvvmBalances
  { GenesisAvvmBalances -> Map CompactRedeemVerificationKey Lovelace
unGenesisAvvmBalances :: Map CompactRedeemVerificationKey Lovelace
  }
  deriving (Int -> GenesisAvvmBalances -> ShowS
[GenesisAvvmBalances] -> ShowS
GenesisAvvmBalances -> String
(Int -> GenesisAvvmBalances -> ShowS)
-> (GenesisAvvmBalances -> String)
-> ([GenesisAvvmBalances] -> ShowS)
-> Show GenesisAvvmBalances
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenesisAvvmBalances] -> ShowS
$cshowList :: [GenesisAvvmBalances] -> ShowS
show :: GenesisAvvmBalances -> String
$cshow :: GenesisAvvmBalances -> String
showsPrec :: Int -> GenesisAvvmBalances -> ShowS
$cshowsPrec :: Int -> GenesisAvvmBalances -> ShowS
Show, GenesisAvvmBalances -> GenesisAvvmBalances -> Bool
(GenesisAvvmBalances -> GenesisAvvmBalances -> Bool)
-> (GenesisAvvmBalances -> GenesisAvvmBalances -> Bool)
-> Eq GenesisAvvmBalances
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenesisAvvmBalances -> GenesisAvvmBalances -> Bool
$c/= :: GenesisAvvmBalances -> GenesisAvvmBalances -> Bool
== :: GenesisAvvmBalances -> GenesisAvvmBalances -> Bool
$c== :: GenesisAvvmBalances -> GenesisAvvmBalances -> Bool
Eq, b -> GenesisAvvmBalances -> GenesisAvvmBalances
NonEmpty GenesisAvvmBalances -> GenesisAvvmBalances
GenesisAvvmBalances -> GenesisAvvmBalances -> GenesisAvvmBalances
(GenesisAvvmBalances -> GenesisAvvmBalances -> GenesisAvvmBalances)
-> (NonEmpty GenesisAvvmBalances -> GenesisAvvmBalances)
-> (forall b.
    Integral b =>
    b -> GenesisAvvmBalances -> GenesisAvvmBalances)
-> Semigroup GenesisAvvmBalances
forall b.
Integral b =>
b -> GenesisAvvmBalances -> GenesisAvvmBalances
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> GenesisAvvmBalances -> GenesisAvvmBalances
$cstimes :: forall b.
Integral b =>
b -> GenesisAvvmBalances -> GenesisAvvmBalances
sconcat :: NonEmpty GenesisAvvmBalances -> GenesisAvvmBalances
$csconcat :: NonEmpty GenesisAvvmBalances -> GenesisAvvmBalances
<> :: GenesisAvvmBalances -> GenesisAvvmBalances -> GenesisAvvmBalances
$c<> :: GenesisAvvmBalances -> GenesisAvvmBalances -> GenesisAvvmBalances
Semigroup, Context -> GenesisAvvmBalances -> IO (Maybe ThunkInfo)
Proxy GenesisAvvmBalances -> String
(Context -> GenesisAvvmBalances -> IO (Maybe ThunkInfo))
-> (Context -> GenesisAvvmBalances -> IO (Maybe ThunkInfo))
-> (Proxy GenesisAvvmBalances -> String)
-> NoThunks GenesisAvvmBalances
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy GenesisAvvmBalances -> String
$cshowTypeOf :: Proxy GenesisAvvmBalances -> String
wNoThunks :: Context -> GenesisAvvmBalances -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> GenesisAvvmBalances -> IO (Maybe ThunkInfo)
noThunks :: Context -> GenesisAvvmBalances -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> GenesisAvvmBalances -> IO (Maybe ThunkInfo)
NoThunks)

instance Monad m => ToJSON m GenesisAvvmBalances where
  toJSON :: GenesisAvvmBalances -> m JSValue
toJSON = Map CompactRedeemVerificationKey Lovelace -> m JSValue
forall (m :: * -> *) a. ToJSON m a => a -> m JSValue
toJSON (Map CompactRedeemVerificationKey Lovelace -> m JSValue)
-> (GenesisAvvmBalances
    -> Map CompactRedeemVerificationKey Lovelace)
-> GenesisAvvmBalances
-> m JSValue
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. GenesisAvvmBalances -> Map CompactRedeemVerificationKey Lovelace
unGenesisAvvmBalances

instance MonadError SchemaError m => FromJSON m GenesisAvvmBalances where
  fromJSON :: JSValue -> m GenesisAvvmBalances
fromJSON = (Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances)
-> m (Map CompactRedeemVerificationKey Lovelace)
-> m GenesisAvvmBalances
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances
GenesisAvvmBalances (Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances)
-> (Map CompactRedeemVerificationKey Lovelace
    -> Map CompactRedeemVerificationKey Lovelace)
-> Map CompactRedeemVerificationKey Lovelace
-> GenesisAvvmBalances
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Map CompactRedeemVerificationKey Lovelace
-> Map CompactRedeemVerificationKey Lovelace
forall (t :: * -> *) a. Foldable t => t a -> t a
forceElemsToWHNF) (m (Map CompactRedeemVerificationKey Lovelace)
 -> m GenesisAvvmBalances)
-> (JSValue -> m (Map CompactRedeemVerificationKey Lovelace))
-> JSValue
-> m GenesisAvvmBalances
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. JSValue -> m (Map CompactRedeemVerificationKey Lovelace)
forall (m :: * -> *) a. FromJSON m a => JSValue -> m a
fromJSON

instance ToCBOR GenesisAvvmBalances where
  toCBOR :: GenesisAvvmBalances -> Encoding
toCBOR (GenesisAvvmBalances Map CompactRedeemVerificationKey Lovelace
gab) =
    Word -> Encoding
encodeListLen Word
1
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Map CompactRedeemVerificationKey Lovelace -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR @(Map CompactRedeemVerificationKey Lovelace) Map CompactRedeemVerificationKey Lovelace
gab

instance FromCBOR GenesisAvvmBalances where
  fromCBOR :: Decoder s GenesisAvvmBalances
fromCBOR = do
    Text -> Int -> Decoder s ()
forall s. Text -> Int -> Decoder s ()
enforceSize Text
"GenesisAvvmBalances" Int
1
    Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances
GenesisAvvmBalances (Map CompactRedeemVerificationKey Lovelace -> GenesisAvvmBalances)
-> Decoder s (Map CompactRedeemVerificationKey Lovelace)
-> Decoder s GenesisAvvmBalances
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s.
FromCBOR (Map CompactRedeemVerificationKey Lovelace) =>
Decoder s (Map CompactRedeemVerificationKey Lovelace)
forall a s. FromCBOR a => Decoder s a
fromCBOR @(Map CompactRedeemVerificationKey Lovelace)