Skip to content

Commit

Permalink
Generate random moniker when missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Bezobchuk committed Nov 12, 2018
1 parent 811b863 commit 156370e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ IMPROVEMENTS
* [\#2749](https://github.com/cosmos/cosmos-sdk/pull/2749) Add --chain-id flag to gaiad testnet

* Gaia
* Generate random moniker on `gaiad init` if one was not provided.

* SDK
- [x/mock/simulation] [\#2720] major cleanup, introduction of helper objects, reorganization
Expand Down
12 changes: 10 additions & 2 deletions cmd/gaia/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,32 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
RunE: func(_ *cobra.Command, _ []string) error {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))

chainID := viper.GetString(client.FlagChainID)
if chainID == "" {
chainID = fmt.Sprintf("test-chain-%v", common.RandStr(6))
}

nodeID, _, err := InitializeNodeValidatorFiles(config)
if err != nil {
return err
}

if viper.GetString(flagMoniker) != "" {
config.Moniker = viper.GetString(flagMoniker)
moniker := viper.GetString(flagMoniker)
if moniker == "" {
moniker = fmt.Sprintf("node-%v", common.RandStr(6))
}

config.Moniker = moniker

var appState json.RawMessage
genFile := config.GenesisFile()

if appState, err = initializeEmptyGenesis(cdc, genFile, chainID,
viper.GetBool(flagOverwrite)); err != nil {
return err
}

if err = ExportGenesisFile(genFile, chainID, nil, appState); err != nil {
return err
}
Expand All @@ -91,5 +98,6 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().String(client.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(flagMoniker, "", "set the validator's moniker")

return cmd
}

0 comments on commit 156370e

Please sign in to comment.