From 2a2da4f449548f5f799ecb4c3331554df9d0c64a Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Mon, 15 Jul 2024 17:21:55 +0200 Subject: [PATCH] more more fix --- .../src/Cardano/CLI/EraBased/Run/Genesis.hs | 17 +---- .../CLI/EraBased/Run/Genesis/Common.hs | 72 ++++++------------- .../EraBased/Run/Genesis/CreateTestnetData.hs | 17 ++--- .../Cardano/CLI/EraBased/Run/Transaction.hs | 2 +- .../cardano-cli-golden/files/golden/help.cli | 40 +++++++++-- .../golden/help/genesis_create-cardano.cli | 16 ++++- .../files/golden/help/genesis_create.cli | 16 ++++- .../help/legacy_genesis_create-cardano.cli | 16 ++++- .../golden/help/legacy_genesis_create.cli | 16 ++++- 9 files changed, 125 insertions(+), 87 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs index f672aabe04..028ccb312f 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs @@ -26,9 +26,6 @@ module Cardano.CLI.EraBased.Run.Genesis , runGenesisKeyHashCmd , runGenesisTxInCmd , runGenesisVerKeyCmd - - -- * Protocol Parameters - , readProtocolParameters ) where import Cardano.Api @@ -409,7 +406,7 @@ runGenesisCreateCardanoCmd , sgSlotLength = L.secondsToNominalDiffTimeMicro $ MkFixed (fromIntegral slotLength) * 1_000 } shelleyGenesisTemplate' <- overrideShelleyGenesis <$> decodeShelleyGenesisFile shelleyGenesisTemplate - alonzoGenesis <- decodeAlonzoGenesisFile (Just era) alonzoGenesisTemplate -- FIXME!!! + alonzoGenesis <- decodeAlonzoGenesisFile (Just era) alonzoGenesisTemplate conwayGenesis <- decodeConwayGenesisFile conwayGenesisTemplate (delegateMap, vrfKeys, kesKeys, opCerts) <- liftIO $ generateShelleyNodeSecrets shelleyDelegateKeys shelleyGenesisvkeys let @@ -1157,15 +1154,3 @@ runGenesisHashFileCmd (GenesisFile fpath) = do gh = Crypto.hashWith id content liftIO $ Text.putStrLn (Crypto.hashToTextAsHex gh) --- Protocol Parameters - ---TODO: eliminate this and get only the necessary params, and get them in a more --- helpful way rather than requiring them as a local file. -readProtocolParameters :: () - => ShelleyBasedEra era - -> ProtocolParamsFile - -> ExceptT ProtocolParamsError IO (L.PParams (ShelleyLedgerEra era)) -readProtocolParameters sbe (ProtocolParamsFile fpath) = do - pparams <- handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $ LBS.readFile fpath - firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $ - shelleyBasedEraConstraints sbe $ Aeson.eitherDecode' pparams 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 7347a468ae..c8370a15ea 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs @@ -1,17 +1,13 @@ {-# LANGUAGE DataKinds #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} + module Cardano.CLI.EraBased.Run.Genesis.Common ( decodeShelleyGenesisFile @@ -20,68 +16,34 @@ module Cardano.CLI.EraBased.Run.Genesis.Common , genStuffedAddress , getCurrentTimePlus30 , readRelays + + -- * Protocol Parameters + , readProtocolParameters ) where import Cardano.Api hiding (ConwayEra) -import Cardano.Api.Ledger (AlonzoGenesis, ConwayGenesis, StandardCrypto, - StrictMaybe (SNothing)) +import Cardano.Api.Ledger (AlonzoGenesis, ConwayGenesis, StandardCrypto) import qualified Cardano.Api.Ledger as L -import Cardano.Api.Shelley (Address (ShelleyAddress), - Hash (DRepKeyHash, GenesisDelegateKeyHash, GenesisKeyHash, StakeKeyHash, VrfKeyHash), - KESPeriod (KESPeriod), - OperationalCertificateIssueCounter (OperationalCertificateIssueCounter), - ShelleyGenesis (ShelleyGenesis, sgGenDelegs, sgInitialFunds, sgMaxLovelaceSupply, sgNetworkMagic, sgProtocolParams, sgStaking, sgSystemStart), - StakeCredential (StakeCredentialByKey), VerificationKey (VrfVerificationKey), - VrfKey, alonzoGenesisDefaults, conwayGenesisDefaults, decodeAlonzoGenesis, - shelleyGenesisDefaults, toShelleyAddr, toShelleyNetwork, toShelleyStakeAddr) - -import Cardano.CLI.EraBased.Commands.Genesis as Cmd -import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep -import qualified Cardano.CLI.EraBased.Commands.Node as Cmd -import Cardano.CLI.EraBased.Run.Address (generateAndWriteKeyFiles) -import qualified Cardano.CLI.EraBased.Run.Governance.DRep as DRep -import qualified Cardano.CLI.EraBased.Run.Key as Key -import Cardano.CLI.EraBased.Run.Node (runNodeIssueOpCertCmd, runNodeKeyGenColdCmd, - runNodeKeyGenKesCmd, runNodeKeyGenVrfCmd) -import Cardano.CLI.EraBased.Run.StakeAddress (runStakeAddressKeyGenCmd) -import qualified Cardano.CLI.IO.Lazy as Lazy +import Cardano.Api.Shelley (Address (ShelleyAddress), ShelleyGenesis, ShelleyLedgerEra, + decodeAlonzoGenesis) + import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.GenesisCmdError -import Cardano.CLI.Types.Errors.NodeCmdError -import Cardano.CLI.Types.Errors.StakePoolCmdError -import Cardano.CLI.Types.Key +import Cardano.CLI.Types.Errors.ProtocolParamsError import Cardano.Crypto.Hash (HashAlgorithm) import qualified Cardano.Crypto.Hash as Hash import qualified Cardano.Crypto.Random as Crypto -import Ouroboros.Consensus.Shelley.Node (ShelleyGenesisStaking (..)) -import Control.DeepSeq (NFData, deepseq) -import Control.Monad (forM, forM_, unless, void, when) import qualified Data.Aeson as A -import Data.Bifunctor (Bifunctor (..)) import qualified Data.Binary.Get as Bin import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy.Char8 as LBS import Data.Coerce (coerce) import Data.Data (Proxy (..)) -import Data.ListMap (ListMap (..)) -import qualified Data.ListMap as ListMap -import Data.Map.Strict (Map, fromList, toList) -import qualified Data.Map.Strict as Map -import Data.Maybe (fromMaybe) -import qualified Data.Sequence.Strict as Seq -import Data.String (fromString) +import Data.Map.Strict (Map) import qualified Data.Text as Text import Data.Time (NominalDiffTime, UTCTime, addUTCTime, getCurrentTime) -import Data.Tuple (swap) import Data.Word (Word64) -import GHC.Generics (Generic) -import GHC.Num (Natural) -import Lens.Micro ((^.)) -import System.Directory (createDirectoryIfMissing) -import System.FilePath (()) -import qualified System.Random as Random -import System.Random (StdGen) import Crypto.Random (getRandomBytes) @@ -92,9 +54,10 @@ decodeShelleyGenesisFile -> t m (ShelleyGenesis StandardCrypto) decodeShelleyGenesisFile = readAndDecodeGenesisFileWith A.eitherDecode +-- | Decode Alonzo Genesis file. See 'Cardano.Api.Genesis.decodeAlonzoGenesis' haddocks for details. decodeAlonzoGenesisFile :: MonadIOTransError GenesisCmdError t m - => Maybe (CardanoEra era) + => Maybe (CardanoEra era) -- ^ Optional era in which we're decoding alonzo genesis. -> FilePath -> t m AlonzoGenesis decodeAlonzoGenesisFile mEra = readAndDecodeGenesisFileWith (runExcept . decodeAlonzoGenesis mEra) @@ -150,3 +113,14 @@ readRelays fp = do handleIOExceptT (GenesisCmdStakePoolRelayFileError fp) (LBS.readFile fp) firstExceptT (GenesisCmdStakePoolRelayJsonDecodeError fp) . hoistEither $ A.eitherDecode relaySpecJsonBs + +--TODO: eliminate this and get only the necessary params, and get them in a more +-- helpful way rather than requiring them as a local file. +readProtocolParameters :: () + => ShelleyBasedEra era + -> ProtocolParamsFile + -> ExceptT ProtocolParamsError IO (L.PParams (ShelleyLedgerEra era)) +readProtocolParameters sbe (ProtocolParamsFile fpath) = do + pparams <- handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $ LBS.readFile fpath + firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $ + shelleyBasedEraConstraints sbe $ A.eitherDecode' pparams diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs index ec14fbbc8e..05c83960a6 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs @@ -23,14 +23,14 @@ module Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData import Cardano.Api hiding (ConwayEra) import Cardano.Api.Ledger (StrictMaybe (SNothing)) import qualified Cardano.Api.Ledger as L -import Cardano.Api.Shelley (Address (ShelleyAddress), - Hash (DRepKeyHash, GenesisDelegateKeyHash, GenesisKeyHash, StakeKeyHash, VrfKeyHash), +import Cardano.Api.Shelley + (Hash (DRepKeyHash, GenesisDelegateKeyHash, GenesisKeyHash, StakeKeyHash, VrfKeyHash), KESPeriod (KESPeriod), OperationalCertificateIssueCounter (OperationalCertificateIssueCounter), ShelleyGenesis (ShelleyGenesis, sgGenDelegs, sgInitialFunds, sgMaxLovelaceSupply, sgNetworkMagic, sgProtocolParams, sgStaking, sgSystemStart), StakeCredential (StakeCredentialByKey), VerificationKey (VrfVerificationKey), - VrfKey, alonzoGenesisDefaults, conwayGenesisDefaults, decodeAlonzoGenesis, - shelleyGenesisDefaults, toShelleyAddr, toShelleyNetwork, toShelleyStakeAddr) + VrfKey, alonzoGenesisDefaults, conwayGenesisDefaults, shelleyGenesisDefaults, + toShelleyAddr, toShelleyNetwork, toShelleyStakeAddr) import Cardano.CLI.EraBased.Commands.Genesis as Cmd import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep @@ -48,20 +48,13 @@ import Cardano.CLI.Types.Errors.GenesisCmdError import Cardano.CLI.Types.Errors.NodeCmdError import Cardano.CLI.Types.Errors.StakePoolCmdError import Cardano.CLI.Types.Key -import Cardano.Crypto.Hash (HashAlgorithm) -import qualified Cardano.Crypto.Hash as Hash -import qualified Cardano.Crypto.Random as Crypto 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 Data.Bifunctor (Bifunctor (..)) -import qualified Data.Binary.Get as Bin -import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy.Char8 as LBS -import Data.Coerce (coerce) -import Data.Data (Proxy (..)) import Data.ListMap (ListMap (..)) import qualified Data.ListMap as ListMap import Data.Map.Strict (Map, fromList, toList) @@ -70,7 +63,6 @@ import Data.Maybe (fromMaybe) import qualified Data.Sequence.Strict as Seq import Data.String (fromString) import qualified Data.Text as Text -import Data.Time (NominalDiffTime, UTCTime, addUTCTime, getCurrentTime) import Data.Tuple (swap) import Data.Word (Word64) import GHC.Generics (Generic) @@ -81,7 +73,6 @@ import System.FilePath (()) import qualified System.Random as Random import System.Random (StdGen) -import Crypto.Random (getRandomBytes) runGenesisKeyGenGenesisCmd :: GenesisKeyGenGenesisCmdArgs diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 7dac34d604..eb00d5a730 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -42,7 +42,7 @@ import Cardano.Api.Shelley import qualified Cardano.Binary as CBOR import qualified Cardano.Chain.Common as Byron import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd -import Cardano.CLI.EraBased.Run.Genesis +import Cardano.CLI.EraBased.Run.Genesis.Common (readProtocolParameters) import Cardano.CLI.EraBased.Run.Query import Cardano.CLI.Json.Friendly (FriendlyFormat (..), friendlyTx, friendlyTxBody) import Cardano.CLI.Read diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 2fe58598ba..eb266242ad 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -9828,7 +9828,15 @@ Usage: cardano-cli legacy genesis initial-txin --verification-key-file FILE Get the TxIn for an initial UTxO based on the verification key -Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR +Usage: cardano-cli legacy genesis create-cardano + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] [--start-time UTC-TIME] @@ -9848,7 +9856,15 @@ Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR Create a Byron and Shelley genesis file from a genesis template and genesis/delegation/spending keys. -Usage: cardano-cli legacy genesis create [--key-output-format STRING] +Usage: cardano-cli legacy genesis create + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + [--key-output-format STRING] --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] @@ -11103,7 +11119,15 @@ Usage: cardano-cli genesis initial-txin --verification-key-file FILE Get the TxIn for an initial UTxO based on the verification key -Usage: cardano-cli genesis create-cardano --genesis-dir DIR +Usage: cardano-cli genesis create-cardano + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] [--start-time UTC-TIME] @@ -11123,7 +11147,15 @@ Usage: cardano-cli genesis create-cardano --genesis-dir DIR Create a Byron and Shelley genesis file from a genesis template and genesis/delegation/spending keys. -Usage: cardano-cli genesis create [--key-output-format STRING] +Usage: cardano-cli genesis create + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + [--key-output-format STRING] --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create-cardano.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create-cardano.cli index d630a99e9d..ad83ead8e7 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create-cardano.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create-cardano.cli @@ -1,4 +1,12 @@ -Usage: cardano-cli genesis create-cardano --genesis-dir DIR +Usage: cardano-cli genesis create-cardano + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] [--start-time UTC-TIME] @@ -19,6 +27,12 @@ Usage: cardano-cli genesis create-cardano --genesis-dir DIR genesis/delegation/spending keys. Available options: + --shelley-era Specify the Shelley era + --allegra-era Specify the Allegra era + --mary-era Specify the Mary era + --alonzo-era Specify the Alonzo era + --babbage-era Specify the Babbage era (default) + --conway-era Specify the Conway era --genesis-dir DIR The genesis directory containing the genesis template and required genesis/delegation/spending keys. --gen-genesis-keys INT The number of genesis keys to make [default is 3]. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create.cli index 9b7e8bf664..bd6f7b1c31 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/genesis_create.cli @@ -1,4 +1,12 @@ -Usage: cardano-cli genesis create [--key-output-format STRING] +Usage: cardano-cli genesis create + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + [--key-output-format STRING] --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] @@ -10,6 +18,12 @@ Usage: cardano-cli genesis create [--key-output-format STRING] genesis/delegation/spending keys. Available options: + --shelley-era Specify the Shelley era + --allegra-era Specify the Allegra era + --mary-era Specify the Mary era + --alonzo-era Specify the Alonzo era + --babbage-era Specify the Babbage era (default) + --conway-era Specify the Conway era --key-output-format STRING Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create-cardano.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create-cardano.cli index 541c2e0ef0..f98fe2ccbc 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create-cardano.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create-cardano.cli @@ -1,4 +1,12 @@ -Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR +Usage: cardano-cli legacy genesis create-cardano + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] [--start-time UTC-TIME] @@ -19,6 +27,12 @@ Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR genesis/delegation/spending keys. Available options: + --shelley-era Specify the Shelley era + --allegra-era Specify the Allegra era + --mary-era Specify the Mary era + --alonzo-era Specify the Alonzo era + --babbage-era Specify the Babbage era (default) + --conway-era Specify the Conway era --genesis-dir DIR The genesis directory containing the genesis template and required genesis/delegation/spending keys. --gen-genesis-keys INT The number of genesis keys to make [default is 3]. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create.cli index ceb617891a..deb636083d 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/legacy_genesis_create.cli @@ -1,4 +1,12 @@ -Usage: cardano-cli legacy genesis create [--key-output-format STRING] +Usage: cardano-cli legacy genesis create + [ --shelley-era + | --allegra-era + | --mary-era + | --alonzo-era + | --babbage-era + | --conway-era + ] + [--key-output-format STRING] --genesis-dir DIR [--gen-genesis-keys INT] [--gen-utxo-keys INT] @@ -10,6 +18,12 @@ Usage: cardano-cli legacy genesis create [--key-output-format STRING] genesis/delegation/spending keys. Available options: + --shelley-era Specify the Shelley era + --allegra-era Specify the Allegra era + --mary-era Specify the Mary era + --alonzo-era Specify the Alonzo era + --babbage-era Specify the Babbage era (default) + --conway-era Specify the Conway era --key-output-format STRING Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is