Skip to content

Commit

Permalink
Introduce create-testnet-data command
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Nov 30, 2023
1 parent d00a7d4 commit d261926
Show file tree
Hide file tree
Showing 7 changed files with 765 additions and 230 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ library
Cardano.CLI.EraBased.Run
Cardano.CLI.EraBased.Run.Address
Cardano.CLI.EraBased.Run.Address.Info
Cardano.CLI.EraBased.Run.CreateTestnetData
Cardano.CLI.EraBased.Run.Genesis
Cardano.CLI.EraBased.Run.Governance
Cardano.CLI.EraBased.Run.Governance.Actions
Expand Down
18 changes: 18 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Cardano.CLI.EraBased.Commands.Genesis
, GenesisCreateCmdArgs (..)
, GenesisCreateCardanoCmdArgs (..)
, GenesisCreateStakedCmdArgs (..)
, GenesisCreateTestNetDataCmdArgs (..)
, GenesisKeyGenGenesisCmdArgs (..)
, GenesisKeyGenDelegateCmdArgs (..)
, GenesisKeyGenUTxOCmdArgs (..)
Expand All @@ -27,6 +28,7 @@ data GenesisCmds era
= GenesisCreate !GenesisCreateCmdArgs
| GenesisCreateCardano !GenesisCreateCardanoCmdArgs
| GenesisCreateStaked !GenesisCreateStakedCmdArgs
| GenesisCreateTestNetData !GenesisCreateTestNetDataCmdArgs
| GenesisKeyGenGenesis !GenesisKeyGenGenesisCmdArgs
| GenesisKeyGenDelegate !GenesisKeyGenDelegateCmdArgs
| GenesisKeyGenUTxO !GenesisKeyGenUTxOCmdArgs
Expand Down Expand Up @@ -81,6 +83,20 @@ data GenesisCreateStakedCmdArgs = GenesisCreateStakedCmdArgs
, mStakePoolRelaySpecFile :: !(Maybe FilePath) -- ^ Relay specification filepath
} deriving Show

data GenesisCreateTestNetDataCmdArgs = GenesisCreateTestNetDataCmdArgs
{ specShelley :: !(Maybe FilePath)
, numGenesisKeys :: !Word
, numPools :: !Word
, numStakeDelegators :: !Word
, numStuffedUtxo :: !Word
, numUtxoKeys :: !Word
, supply :: !(Maybe Lovelace)
, supplyDelegated :: !(Maybe Lovelace)
, network :: !NetworkId
, systemStart :: !(Maybe SystemStart)
, outputDir :: !FilePath
} deriving Show

data GenesisKeyGenGenesisCmdArgs = GenesisKeyGenGenesisCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile Out)
Expand Down Expand Up @@ -122,6 +138,8 @@ renderGenesisCmds = \case
"genesis create-cardano"
GenesisCreateStaked {} ->
"genesis create-staked"
GenesisCreateTestNetData {} ->
"genesis create-testnet-data"
GenesisKeyGenGenesis {} ->
"genesis key-gen-genesis"
GenesisKeyGenDelegate {} ->
Expand Down
87 changes: 87 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ pGenesisCmds envCli =
[ "Create a staked Shelley genesis file from a genesis "
, "template and genesis/delegation/spending keys."
]
, Just
$ subParser "create-testnet-data"
$ Opt.info (pGenesisCreateTestNetData envCli)
$ Opt.progDesc
$ mconcat
[ "Create data to use for starting a testnet."
]
, Just
$ subParser "hash"
$ Opt.info pGenesisHash
Expand Down Expand Up @@ -191,6 +198,86 @@ pGenesisCreateStaked envCli =
<*> pStuffedUtxoCount
<*> Opt.optional pRelayJsonFp

pGenesisCreateTestNetData :: EnvCli -> Parser (GenesisCmds era)
pGenesisCreateTestNetData envCli =
fmap GenesisCreateTestNetData $ GenesisCreateTestNetDataCmdArgs
<$> (optional $ pSpecFile "shelley")
<*> pNumGenesisKeys
<*> pNumPools
<*> pNumStakeDelegs
<*> pNumStuffedUtxoCount
<*> pNumUtxoKeys
<*> pSupply
<*> pSupplyDelegated
<*> pNetworkId envCli
<*> pMaybeSystemStart
<*> pOutputDir
where
pSpecFile era = Opt.strOption $ mconcat
[ Opt.long $ "spec-" <> era
, Opt.metavar "FILE"
, Opt.help $ "The " <> era <> " specification file to use as input. A default one is generated if omitted."
]
pNumGenesisKeys = Opt.option Opt.auto $ mconcat
[ Opt.long "genesis-keys"
, Opt.metavar "INT"
, Opt.help "The number of genesis keys to make (default is 3)."
, Opt.value 3
]
pNumPools :: Parser Word
pNumPools =
Opt.option Opt.auto $ mconcat
[ Opt.long "pools"
, Opt.metavar "INT"
, Opt.help "The number of stake pool credential sets to make (default is 0)."
, Opt.value 0
]
pNumStakeDelegs :: Parser Word
pNumStakeDelegs =
Opt.option Opt.auto $ mconcat
[ Opt.long "stake-delegators"
, Opt.metavar "INT"
, Opt.help "The number of stake delegator credential sets to make (default is 0)."
, Opt.value 0
]
pNumStuffedUtxoCount :: Parser Word
pNumStuffedUtxoCount =
Opt.option Opt.auto $ mconcat
[ Opt.long "stuffed-utxo"
, Opt.metavar "INT"
, Opt.help "The number of fake UTxO entries to generate (default is 0)."
, Opt.value 0
]
pNumUtxoKeys :: Parser Word
pNumUtxoKeys =
Opt.option Opt.auto $ mconcat
[ Opt.long "utxo-keys"
, Opt.metavar "INT"
, Opt.help "The number of UTxO keys to make (default is 0)."
, Opt.value 0
]
pSupply :: Parser (Maybe Lovelace)
pSupply =
Opt.optional $ fmap Lovelace $ Opt.option Opt.auto $ mconcat
[ Opt.long "supply"
, Opt.metavar "LOVELACE"
, Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial, non-delegating stake holders. Defaults to 1 million Ada (i.e. 10^12 Lovelace)."
, Opt.value 1000000000000
]
pSupplyDelegated :: Parser (Maybe Lovelace)
pSupplyDelegated =
Opt.optional $ fmap Lovelace $ Opt.option Opt.auto $ mconcat
[ Opt.long "supply-delegated"
, Opt.metavar "LOVELACE"
, Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial, delegating stake holders. Defaults to 1 million Ada (i.e. 10^12 Lovelace)."
, Opt.value 1000000000000
]
pOutputDir = Opt.strOption $ mconcat
[ Opt.long "out-dir"
, Opt.metavar "DIR"
, Opt.help "The directory where to generate the data. Created if not existing."
]

pGenesisHash :: Parser (GenesisCmds era)
pGenesisHash =
GenesisHashFile <$> pGenesisFile "The genesis file."
Expand Down
Loading

0 comments on commit d261926

Please sign in to comment.