7 "github.com/spf13/cobra"
8 log "github.com/sirupsen/logrus"
9 cmn "github.com/tendermint/tmlibs/common"
11 "github.com/bytom/types"
12 cfg "github.com/bytom/config"
13 "github.com/bytom/crypto/ed25519/chainkd"
16 var initFilesCmd = &cobra.Command{
18 Short: "Initialize blockchain",
23 initFilesCmd.Flags().String("chain_id", config.ChainID, "Select [mainnet] or [testnet]")
25 RootCmd.AddCommand(initFilesCmd)
28 func initFiles(cmd *cobra.Command, args []string) {
29 if config.ChainID == "mainnet" {
30 cfg.EnsureRoot(config.RootDir, "mainnet")
32 cfg.EnsureRoot(config.RootDir, "testnet")
35 genFile := config.GenesisFile()
36 if _, err := os.Stat(genFile); !os.IsNotExist(err) {
37 log.WithField("genesis", config.GenesisFile()).Info("Already exits config file.")
40 xprv, err := chainkd.NewXPrv(nil)
42 log.WithField("error", err).Error("Spawn node's key failed.")
45 genDoc := types.GenesisDoc{
46 ChainID: cmn.Fmt(config.ChainID),
47 PrivateKey: hex.EncodeToString(xprv.Bytes()),
49 genDoc.SaveAs(genFile)
50 log.WithField("genesis", config.GenesisFile()).Info("Initialized bytom")