From 022a6e913666ed7158f53b42d32f9d492be7a484 Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Fri, 12 Jul 2024 17:35:07 +0200 Subject: [PATCH] more eon --- .../src/Cardano/CLI/EraBased/Commands/Genesis.hs | 7 ++++--- .../src/Cardano/CLI/EraBased/Options/Genesis.hs | 8 ++++---- .../src/Cardano/CLI/EraBased/Run/Genesis.hs | 7 ++++--- .../Cardano/CLI/EraBased/Run/Genesis/Common.hs | 16 ++++++---------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs index 7cb2efac9f..3c70cbf561 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs @@ -26,7 +26,7 @@ import Cardano.CLI.Types.Common import Data.Text (Text) data GenesisCmds era - = GenesisCreate !GenesisCreateCmdArgs + = GenesisCreate !(GenesisCreateCmdArgs era) | GenesisCreateCardano !GenesisCreateCardanoCmdArgs | GenesisCreateStaked !(GenesisCreateStakedCmdArgs era) | GenesisCreateTestNetData !(GenesisCreateTestNetDataCmdArgs era) @@ -40,8 +40,9 @@ data GenesisCmds era | GenesisHashFile !GenesisFile deriving Show -data GenesisCreateCmdArgs = GenesisCreateCmdArgs - { keyOutputFormat :: !KeyOutputFormat +data GenesisCreateCmdArgs era = GenesisCreateCmdArgs + { eon :: !(CardanoEra era) + , keyOutputFormat :: !KeyOutputFormat , genesisDir :: !GenesisDir , numGenesisKeys :: !Word , numUTxOKeys :: !Word diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs index 9324e88a23..28cbf2d3b4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs @@ -72,7 +72,7 @@ pGenesisCmds era envCli = ] , Just $ subParser "create" - $ Opt.info (pGenesisCreate envCli) + $ Opt.info (pGenesisCreate era envCli) $ Opt.progDesc $ mconcat [ "Create a Shelley genesis file from a genesis " @@ -169,9 +169,9 @@ pGenesisCreateCardano envCli = "JSON file with genesis defaults for conway." <*> pNodeConfigTemplate -pGenesisCreate :: EnvCli -> Parser (GenesisCmds era) -pGenesisCreate envCli = - fmap GenesisCreate $ GenesisCreateCmdArgs +pGenesisCreate :: CardanoEra era -> EnvCli -> Parser (GenesisCmds era) +pGenesisCreate era envCli = + fmap GenesisCreate $ GenesisCreateCmdArgs era <$> pKeyOutputFormat <*> pGenesisDir <*> pGenesisNumGenesisKeys diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs index 2b9491654b..e25deef61d 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs @@ -228,11 +228,12 @@ writeOutput Nothing = Text.putStrLn -- runGenesisCreateCmd - :: GenesisCreateCmdArgs + :: GenesisCreateCmdArgs era -> ExceptT GenesisCmdError IO () runGenesisCreateCmd Cmd.GenesisCreateCmdArgs - { Cmd.keyOutputFormat + { Cmd.eon + , Cmd.keyOutputFormat , Cmd.genesisDir , Cmd.numGenesisKeys , Cmd.numUTxOKeys @@ -251,7 +252,7 @@ runGenesisCreateCmd createDirectoryIfMissing False utxodir template <- readShelleyGenesisWithDefault (rootdir "genesis.spec.json") adjustTemplate - alonzoGenesis <- decodeAlonzoGenesisFile undefined $ rootdir "genesis.alonzo.spec.json" -- FIXME!!! + alonzoGenesis <- decodeAlonzoGenesisFile (Just eon) $ rootdir "genesis.alonzo.spec.json" -- FIXME!!! conwayGenesis <- decodeConwayGenesisFile $ rootdir "genesis.conway.spec.json" forM_ [ 1 .. numGenesisKeys ] $ \index -> do diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs index 6f1f675437..7347a468ae 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs @@ -57,7 +57,7 @@ import Ouroboros.Consensus.Shelley.Node (ShelleyGenesisStaking (..)) import Control.DeepSeq (NFData, deepseq) import Control.Monad (forM, forM_, unless, void, when) -import qualified Data.Aeson as Aeson +import qualified Data.Aeson as A import Data.Bifunctor (Bifunctor (..)) import qualified Data.Binary.Get as Bin import Data.ByteString (ByteString) @@ -90,7 +90,7 @@ decodeShelleyGenesisFile :: MonadIOTransError GenesisCmdError t m => FilePath -> t m (ShelleyGenesis StandardCrypto) -decodeShelleyGenesisFile = readAndDecodeGenesisFile +decodeShelleyGenesisFile = readAndDecodeGenesisFileWith A.eitherDecode decodeAlonzoGenesisFile :: MonadIOTransError GenesisCmdError t m @@ -103,16 +103,12 @@ decodeConwayGenesisFile :: MonadIOTransError GenesisCmdError t m => FilePath -> t m (ConwayGenesis StandardCrypto) -decodeConwayGenesisFile = readAndDecodeGenesisFile - -readAndDecodeGenesisFile - :: MonadIOTransError GenesisCmdError t m - => FromJSON a => FilePath -> t m a -readAndDecodeGenesisFile = readAndDecodeGenesisFileWith Aeson.eitherDecode +decodeConwayGenesisFile = readAndDecodeGenesisFileWith A.eitherDecode readAndDecodeGenesisFileWith :: MonadIOTransError GenesisCmdError t m - => (LBS.ByteString -> Either String a) -> FilePath -> t m a + => (LBS.ByteString -> Either String a) -> FilePath + -> t m a readAndDecodeGenesisFileWith decode' fpath = do lbs <- handleIOExceptionsLiftWith (GenesisCmdGenesisFileError . FileIOError fpath) . liftIO $ LBS.readFile fpath modifyError (GenesisCmdGenesisFileDecodeError fpath . Text.pack) @@ -153,4 +149,4 @@ readRelays fp = do relaySpecJsonBs <- handleIOExceptT (GenesisCmdStakePoolRelayFileError fp) (LBS.readFile fp) firstExceptT (GenesisCmdStakePoolRelayJsonDecodeError fp) - . hoistEither $ Aeson.eitherDecode relaySpecJsonBs + . hoistEither $ A.eitherDecode relaySpecJsonBs