mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-10 12:01:18 +00:00
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/tendermint/tendermint/types"
|
|
cmn "github.com/tendermint/tmlibs/common"
|
|
)
|
|
|
|
// InitFilesCmd initialises a fresh Tendermint Core instance.
|
|
var InitFilesCmd = &cobra.Command{
|
|
Use: "init",
|
|
Short: "Initialize Tendermint",
|
|
Run: initFiles,
|
|
}
|
|
|
|
func initFiles(cmd *cobra.Command, args []string) {
|
|
privValFile := config.PrivValidatorFile()
|
|
if _, err := os.Stat(privValFile); os.IsNotExist(err) {
|
|
privValidator := types.GenPrivValidatorFS(privValFile)
|
|
privValidator.Save()
|
|
|
|
genFile := config.GenesisFile()
|
|
|
|
if _, err := os.Stat(genFile); os.IsNotExist(err) {
|
|
genDoc := types.GenesisDoc{
|
|
ChainID: cmn.Fmt("test-chain-%v", cmn.RandStr(6)),
|
|
}
|
|
genDoc.Validators = []types.GenesisValidator{{
|
|
PubKey: privValidator.GetPubKey(),
|
|
Power: 10,
|
|
}}
|
|
|
|
if err := genDoc.SaveAs(genFile); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
logger.Info("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile())
|
|
} else {
|
|
logger.Info("Already initialized", "priv_validator", config.PrivValidatorFile())
|
|
}
|
|
}
|