Skip to content

Commit

Permalink
more eon
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Jul 15, 2024
1 parent ed83517 commit 8367257
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
7 changes: 4 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 6 additions & 10 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 8367257

Please sign in to comment.