From 33e0ddd0c188ba7e8715e06a05103d96b1936c13 Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Wed, 7 Feb 2024 11:02:16 -0600 Subject: [PATCH] rework to also pick network magic from environment --- .../Cardano/CLI/EraBased/Options/Genesis.hs | 36 ++++++++++++------- .../allegra_genesis_create-testnet-data.cli | 5 +-- .../alonzo_genesis_create-testnet-data.cli | 5 +-- .../babbage_genesis_create-testnet-data.cli | 5 +-- .../conway_genesis_create-testnet-data.cli | 5 +-- .../latest_genesis_create-testnet-data.cli | 5 +-- .../help/mary_genesis_create-testnet-data.cli | 5 +-- .../shelley_genesis_create-testnet-data.cli | 5 +-- 8 files changed, 44 insertions(+), 27 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs index f6acb69f6e..bc44edf359 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs @@ -21,6 +21,7 @@ import Data.Maybe import Data.Word (Word64) import Options.Applicative hiding (help, str) import qualified Options.Applicative as Opt +import Data.Foldable {- HLINT ignore "Use <$>" -} {- HLINT ignore "Move brackets to avoid $" -} @@ -89,7 +90,7 @@ pGenesisCmds envCli = ] , Just $ subParser "create-testnet-data" - $ Opt.info pGenesisCreateTestNetData + $ Opt.info (pGenesisCreateTestNetData envCli) $ Opt.progDesc $ mconcat [ "Create data to use for starting a testnet." @@ -199,8 +200,8 @@ pGenesisCreateStaked envCli = <*> pStuffedUtxoCount <*> Opt.optional pRelayJsonFp -pGenesisCreateTestNetData :: Parser (GenesisCmds era) -pGenesisCreateTestNetData = +pGenesisCreateTestNetData :: EnvCli -> Parser (GenesisCmds era) +pGenesisCreateTestNetData envCli = fmap GenesisCreateTestNetData $ GenesisCreateTestNetDataCmdArgs <$> (optional $ pSpecFile "shelley") <*> pNumGenesisKeys @@ -211,18 +212,10 @@ pGenesisCreateTestNetData = <*> pNumUtxoKeys <*> pSupply <*> pSupplyDelegated - <*> optional pNetworkIdForTestnetData + <*> (optional $ pNetworkIdForTestnetData envCli) <*> pMaybeSystemStart <*> pOutputDir where - pNetworkIdForTestnetData :: Parser NetworkId - pNetworkIdForTestnetData = Testnet . NetworkMagic <$> testnetMagicParser - where - testnetMagicParser = Opt.option (bounded "TESTNET_MAGIC") - ( Opt.long "testnet-magic" - <> Opt.metavar "NATURAL" - <> Opt.help "Specify a testnet magic id for the cluster. Overrides the network id supplied in the spec file." - ) pSpecFile era = Opt.strOption $ mconcat [ Opt.long $ "spec-" <> era , Opt.metavar "FILE" @@ -442,4 +435,21 @@ pBulkPoolsPerFile = , Opt.metavar "INT" , Opt.help "Each bulk pool to contain this many pool credential sets [default is 0]." , Opt.value 0 - ] \ No newline at end of file + ] + +pNetworkIdForTestnetData :: EnvCli -> Parser NetworkId +pNetworkIdForTestnetData envCli = asum $ mconcat + [ [ fmap (Testnet . NetworkMagic) $ Opt.option (bounded "TESTNET_MAGIC") $ mconcat + [ Opt.long "testnet-magic" + , Opt.metavar "NATURAL" + , Opt.help $ mconcat + [ "Specify a testnet magic id for the cluster. " + , "This overrides both the network magic from the " + , "spec file and CARDANO_NODE_NETWORK_ID environment variable" + ] + ] + ] + , -- Default to the network id specified by the environment variable if it is available. + pure <$> maybeToList (envCliNetworkId envCli) + ] + diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_genesis_create-testnet-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_genesis_create-testnet-data.cli index c85d1ef2cd..65b3b90621 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_genesis_create-testnet-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_genesis_create-testnet-data.cli @@ -42,8 +42,9 @@ Available options: delegated. Defaults to 500 000 Ada (i.e. (10^12) / 2 Lovelace). Cannot be more than the amount specified with --total-supply. - --testnet-magic NATURAL Specify a testnet magic id for the cluster. Overrides - the network id supplied in the spec file. + --testnet-magic NATURAL Specify a testnet magic id for the cluster. This + overrides both the network magic from the spec file + and CARDANO_NODE_NETWORK_ID environment variable --start-time UTC-TIME The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_genesis_create-testnet-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_genesis_create-testnet-data.cli index f02a7ea666..bb72c14ea9 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_genesis_create-testnet-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_genesis_create-testnet-data.cli @@ -42,8 +42,9 @@ Available options: delegated. Defaults to 500 000 Ada (i.e. (10^12) / 2 Lovelace). Cannot be more than the amount specified with --total-supply. - --testnet-magic NATURAL Specify a testnet magic id for the cluster. Overrides - the network id supplied in the spec file. + --testnet-magic NATURAL Specify a testnet magic id for the cluster. This + overrides both the network magic from the spec file + and CARDANO_NODE_NETWORK_ID environment variable --start-time UTC-TIME The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_genesis_create-testnet-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_genesis_create-testnet-data.cli index 3df92c5c92..aa23d8d044 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_genesis_create-testnet-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_genesis_create-testnet-data.cli @@ -42,8 +42,9 @@ Available options: delegated. Defaults to 500 000 Ada (i.e. (10^12) / 2 Lovelace). Cannot be more than the amount specified with --total-supply. - --testnet-magic NATURAL Specify a testnet magic id for the cluster. Overrides - the network id supplied in the spec file. + --testnet-magic NATURAL Specify a testnet magic id for the cluster. This + overrides both the network magic from the spec file + and CARDANO_NODE_NETWORK_ID environment variable --start-time UTC-TIME The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_genesis_create-testnet-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_genesis_create-testnet-data.cli index b684d8e815..a73282a280 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_genesis_create-testnet-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_genesis_create-testnet-data.cli @@ -42,8 +42,9 @@ Available options: delegated. Defaults to 500 000 Ada (i.e. (10^12) / 2 Lovelace). Cannot be more than the amount specified with --total-supply. - --testnet-magic NATURAL Specify a testnet magic id for the cluster. Overrides - the network id supplied in the spec file. + --testnet-magic NATURAL Specify a testnet magic id for the cluster. This + overrides both the network magic from the spec file + and CARDANO_NODE_NETWORK_ID environment variable --start-time UTC-TIME The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_genesis_create-testnet-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_genesis_create-testnet-data.cli index 5c098b47ca..564b11d1a7 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_genesis_create-testnet-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_genesis_create-testnet-data.cli @@ -42,8 +42,9 @@ Available options: delegated. Defaults to 500 000 Ada (i.e. (10^12) / 2 Lovelace). Cannot be more than the amount specified with --total-supply. - --testnet-magic NATURAL Specify a testnet magic id for the cluster. Overrides - the network id supplied in the spec file. + --testnet-magic NATURAL Specify a testnet magic id for the cluster. This + overrides both the network magic from the spec file + and CARDANO_NODE_NETWORK_ID environment variable --start-time UTC-TIME The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_genesis_create-testnet-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_genesis_create-testnet-data.cli index 54a2cf055f..055caed3c8 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_genesis_create-testnet-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_genesis_create-testnet-data.cli @@ -42,8 +42,9 @@ Available options: delegated. Defaults to 500 000 Ada (i.e. (10^12) / 2 Lovelace). Cannot be more than the amount specified with --total-supply. - --testnet-magic NATURAL Specify a testnet magic id for the cluster. Overrides - the network id supplied in the spec file. + --testnet-magic NATURAL Specify a testnet magic id for the cluster. This + overrides both the network magic from the spec file + and CARDANO_NODE_NETWORK_ID environment variable --start-time UTC-TIME The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_genesis_create-testnet-data.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_genesis_create-testnet-data.cli index e5fb4bd6ed..49fe029e8c 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_genesis_create-testnet-data.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_genesis_create-testnet-data.cli @@ -42,8 +42,9 @@ Available options: delegated. Defaults to 500 000 Ada (i.e. (10^12) / 2 Lovelace). Cannot be more than the amount specified with --total-supply. - --testnet-magic NATURAL Specify a testnet magic id for the cluster. Overrides - the network id supplied in the spec file. + --testnet-magic NATURAL Specify a testnet magic id for the cluster. This + overrides both the network magic from the spec file + and CARDANO_NODE_NETWORK_ID environment variable --start-time UTC-TIME The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds.