feat(genutil): allow manually setting the consensus key type in genesis. (#19971)

Co-authored-by: Marko <marko@baricevic.me>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
This commit is contained in:
Devon Bear
2024-04-30 12:45:36 +00:00
committed by GitHub
co-authored by Marko marbar3778
parent 128bb968b2
commit abb2994a8f
2 changed files with 13 additions and 0 deletions
+12
View File
@@ -9,6 +9,7 @@ import (
"path/filepath"
cfg "github.com/cometbft/cometbft/config"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/go-bip39"
"github.com/spf13/cobra"
@@ -35,6 +36,9 @@ const (
// FlagDefaultBondDenom defines the default denom to use in the genesis file.
FlagDefaultBondDenom = "default-denom"
// FlagConsensusKeyAlgo defines the algorithm to use for the consensus signing key.
FlagConsensusKeyAlgo = "consensus-key-algo"
)
type printInfo struct {
@@ -158,8 +162,15 @@ func InitCmd(mm *module.Manager) *cobra.Command {
appGenesis.InitialHeight = initHeight
appGenesis.Consensus = &types.ConsensusGenesis{
Validators: nil,
Params: cmttypes.DefaultConsensusParams(),
}
consensusKey, err := cmd.Flags().GetString(FlagConsensusKeyAlgo)
if err != nil {
return errorsmod.Wrap(err, "Failed to get consensus key algo")
}
appGenesis.Consensus.Params.Validator.PubKeyTypes = []string{consensusKey}
if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil {
return errorsmod.Wrap(err, "Failed to export genesis file")
}
@@ -176,6 +187,7 @@ func InitCmd(mm *module.Manager) *cobra.Command {
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(FlagDefaultBondDenom, "", "genesis file default denomination, if left blank default value is 'stake'")
cmd.Flags().Int64(flags.FlagInitHeight, 1, "specify the initial block height at genesis")
cmd.Flags().String(FlagConsensusKeyAlgo, "ed25519", "algorithm to use for the consensus key")
return cmd
}