-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start working on the new genesis workflow
Ref #2596
- Loading branch information
Alessio Treglia
committed
Oct 28, 2018
1 parent
855e0ac
commit 2642980
Showing
8 changed files
with
440 additions
and
446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package init | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/cosmos/cosmos-sdk/x/auth" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/tendermint/go-amino" | ||
cfg "github.com/tendermint/tendermint/config" | ||
"github.com/tendermint/tendermint/crypto" | ||
"github.com/tendermint/tendermint/libs/cli" | ||
"github.com/tendermint/tendermint/types" | ||
) | ||
|
||
type initConfig struct { | ||
ChainID string | ||
GenTxsDir string | ||
Name string | ||
NodeID string | ||
ValPubKey crypto.PubKey | ||
} | ||
|
||
// nolint | ||
func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "collect-gentxs", | ||
Short: "Collect genesis txs and output a genesis.json file", | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
config := ctx.Config | ||
config.SetRoot(viper.GetString(cli.HomeFlag)) | ||
|
||
name := viper.GetString(client.FlagName) | ||
nodeID, valPubKey, err := InitializeNodeValidatorFiles(config) | ||
if err != nil { | ||
return err | ||
} | ||
genDoc, err := loadGenesisDoc(cdc, config.GenesisFile()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
toPrint := printInfo{ | ||
Moniker: config.Moniker, | ||
NodeID: nodeID, | ||
} | ||
|
||
initCfg := initConfig{ | ||
ChainID: genDoc.ChainID, | ||
GenTxsDir: filepath.Join(config.RootDir, "config", "gentx"), | ||
Name: name, | ||
NodeID: nodeID, | ||
ValPubKey: valPubKey, | ||
} | ||
appMessage, err := genTxsWithConfig(cdc, config, initCfg, genDoc) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
toPrint.AppMessage = appMessage | ||
// print out some key information | ||
return displayInfo(cdc, toPrint) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(cli.HomeFlag, app.DefaultNodeHome, "node's home directory") | ||
cmd.Flags().String(client.FlagName, "", "name of private key with which to sign the gentx") | ||
return cmd | ||
} | ||
|
||
func genTxsWithConfig(cdc *codec.Codec, config *cfg.Config, initCfg initConfig, | ||
genDoc types.GenesisDoc) (appMessage json.RawMessage, err error) { | ||
|
||
genFile := config.GenesisFile() | ||
// process genesis transactions, else create default genesis.json | ||
var appGenTxs []auth.StdTx | ||
var persistentPeers string | ||
var genTxs []json.RawMessage | ||
var appState json.RawMessage | ||
var jsonRawTx json.RawMessage | ||
|
||
|
||
appGenTxs, persistentPeers, err = app.CollectStdTxs(config.Moniker, initCfg.GenTxsDir, cdc) | ||
if err != nil { | ||
return | ||
} | ||
genTxs = make([]json.RawMessage, len(appGenTxs)) | ||
config.P2P.PersistentPeers = persistentPeers | ||
for i, stdTx := range appGenTxs { | ||
jsonRawTx, err = cdc.MarshalJSON(stdTx) | ||
if err != nil { | ||
return | ||
} | ||
genTxs[i] = jsonRawTx | ||
} | ||
|
||
cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config) | ||
appState, err = app.GaiaAppGenStateJSON(cdc, genDoc, genTxs) | ||
if err != nil { | ||
return | ||
} | ||
err = WriteGenesisFile(genFile, initCfg.ChainID, nil, appState) | ||
|
||
return | ||
} | ||
|
||
func loadGenesisDoc(cdc *amino.Codec, genFile string) (genDoc types.GenesisDoc, err error) { | ||
genContents, err := ioutil.ReadFile(genFile) | ||
if err != nil { | ||
return | ||
} | ||
err = cdc.UnmarshalJSON(genContents, &genDoc) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.