Skip to content

Commit

Permalink
Reintroduce collect-gentxs's --gentx-dir flag
Browse files Browse the repository at this point in the history
It went lost in last genesis workflow refactoring.

Also address structs initializations as per #2835.
  • Loading branch information
Alessio Treglia committed Dec 6, 2018
1 parent 5b42e83 commit cb01a55
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
48 changes: 36 additions & 12 deletions cmd/gaia/init/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/tendermint/tendermint/types"
)

const (
flagGenTxDir = "gentx-dir"
)

type initConfig struct {
ChainID string
GenTxsDir string
Expand All @@ -34,7 +38,6 @@ func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))
name := viper.GetString(client.FlagName)

nodeID, valPubKey, err := InitializeNodeValidatorFiles(config)
if err != nil {
return err
Expand All @@ -45,19 +48,13 @@ func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
return err
}

toPrint := printInfo{
Moniker: config.Moniker,
ChainID: genDoc.ChainID,
NodeID: nodeID,
genTxsDir := viper.GetString(flagGenTxDir)
if genTxsDir == "" {
genTxsDir = filepath.Join(config.RootDir, "config", "gentx")
}

initCfg := initConfig{
ChainID: genDoc.ChainID,
GenTxsDir: filepath.Join(config.RootDir, "config", "gentx"),
Name: name,
NodeID: nodeID,
ValPubKey: valPubKey,
}
toPrint := makePrintInfo(config.Moniker, genDoc.ChainID, nodeID, genTxsDir, json.RawMessage(""))
initCfg := makeInitConfig(genDoc.ChainID, genTxsDir, name, nodeID, valPubKey)

appMessage, err := genAppStateFromConfig(cdc, config, initCfg, genDoc)
if err != nil {
Expand All @@ -72,6 +69,9 @@ func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
}

cmd.Flags().String(cli.HomeFlag, app.DefaultNodeHome, "node's home directory")
cmd.Flags().String(flagGenTxDir, "",
"override default \"gentx\" directory from which collect and execute "+
"genesis transactions; default [--home]/config/gentx/")
return cmd
}

Expand Down Expand Up @@ -116,3 +116,27 @@ func genAppStateFromConfig(
err = ExportGenesisFile(genFile, initCfg.ChainID, nil, appState)
return
}

func makeInitConfig(chainID, genTxsDir, name, nodeID string,
valPubKey crypto.PubKey) initConfig {

return initConfig{
ChainID: chainID,
GenTxsDir: genTxsDir,
Name: name,
NodeID: nodeID,
ValPubKey: valPubKey,
}
}

func makePrintInfo(moniker, chainID, nodeID, genTxsDir string,
appMessage json.RawMessage) printInfo {

return printInfo{
Moniker: moniker,
ChainID: chainID,
NodeID: nodeID,
GenTxsDir: genTxsDir,
AppMessage: appMessage,
}
}
8 changes: 2 additions & 6 deletions cmd/gaia/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type printInfo struct {
Moniker string `json:"moniker"`
ChainID string `json:"chain_id"`
NodeID string `json:"node_id"`
GenTxsDir string `json:"gentxs_dir"`
AppMessage json.RawMessage `json:"app_message"`
}

Expand Down Expand Up @@ -76,12 +77,7 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
return err
}

toPrint := printInfo{
ChainID: chainID,
Moniker: config.Moniker,
NodeID: nodeID,
AppMessage: appState,
}
toPrint := makePrintInfo(config.Moniker, chainID, nodeID, "", appState)

cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config)

Expand Down
8 changes: 1 addition & 7 deletions cmd/gaia/init/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,7 @@ func collectGenFiles(
config.SetRoot(nodeDir)

nodeID, valPubKey := nodeIDs[i], valPubKeys[i]
initCfg := initConfig{
ChainID: chainID,
GenTxsDir: gentxsDir,
Name: moniker,
NodeID: nodeID,
ValPubKey: valPubKey,
}
initCfg := makeInitConfig(chainID, gentxsDir, moniker, nodeID, valPubKey)

genDoc, err := loadGenesisDoc(cdc, config.GenesisFile())
if err != nil {
Expand Down

0 comments on commit cb01a55

Please sign in to comment.