{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Test.Cardano.Chain.Config (
readMainetCfg,
)
where
import qualified Cardano.Chain.Genesis as Genesis
import Cardano.Crypto.Hashing (Hash, decodeHash)
import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic (..))
import Cardano.Crypto.Raw (Raw)
import Cardano.Prelude
#ifdef CARDANO_LEDGER_BYRON_TEST
import Paths_cardano_ledger_byron_test (getDataFileName)
#else
import Paths_cardano_ledger_byron (getDataFileName)
#endif
readMainetCfg :: MonadIO m => m Genesis.Config
readMainetCfg :: forall (m :: * -> *). MonadIO m => m Config
readMainetCfg = do
String
mainnetGenesisJson <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ String -> IO String
getDataFileName String
"mainnet-genesis.json"
let genHash :: Hash Raw
genHash =
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
(forall a. HasCallStack => Text -> a
panic forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Show a, ConvertText String b) => a -> b
show forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> ConfigurationError
Genesis.GenesisHashDecodeError)
forall (cat :: * -> * -> *) a. Category cat => cat a a
identity
( forall a. Text -> Either Text (Hash a)
decodeHash
Text
"5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb"
) ::
Hash Raw
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => Text -> a
panic forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. (Show a, ConvertText String b) => a -> b
show) forall (cat :: * -> * -> *) a. Category cat => cat a a
identity
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT
(forall (m :: * -> *).
(MonadError ConfigurationError m, MonadIO m) =>
RequiresNetworkMagic -> String -> Hash Raw -> m Config
Genesis.mkConfigFromFile RequiresNetworkMagic
RequiresNoMagic String
mainnetGenesisJson Hash Raw
genHash)