Skip to content

Commit

Permalink
rework to also pick network magic from environment
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLopezDeLara committed Feb 7, 2024
1 parent 773a650 commit 33e0ddd
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 27 deletions.
36 changes: 23 additions & 13 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $" -}
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
]
]

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)
]

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 33e0ddd

Please sign in to comment.