OSDN Git Service

Dev (#148)
[bytom/bytom.git] / cmd / bytomd / commands / init.go
index 1f24547..381bef5 100644 (file)
@@ -9,6 +9,7 @@ import (
        cmn "github.com/tendermint/tmlibs/common"
 
        "github.com/bytom/types"
+       cfg "github.com/bytom/config"
        "github.com/bytom/crypto/ed25519/chainkd"
 )
 
@@ -19,10 +20,18 @@ var initFilesCmd = &cobra.Command{
 }
 
 func init() {
+       initFilesCmd.Flags().String("chain_id", config.ChainID, "Select [mainnet] or [testnet]")
+
        RootCmd.AddCommand(initFilesCmd)
 }
 
 func initFiles(cmd *cobra.Command, args []string) {
+       if config.ChainID == "mainnet" {
+               cfg.EnsureRoot(config.RootDir, "mainnet")
+       } else {
+               cfg.EnsureRoot(config.RootDir, "testnet")
+       }
+
        genFile := config.GenesisFile()
        if _, err := os.Stat(genFile); !os.IsNotExist(err) {
                log.WithField("genesis", config.GenesisFile()).Info("Already exits config file.")
@@ -34,7 +43,7 @@ func initFiles(cmd *cobra.Command, args []string) {
                return
        }
        genDoc := types.GenesisDoc{
-               ChainID:    cmn.Fmt("bytom"),
+               ChainID:    cmn.Fmt(config.ChainID),
                PrivateKey: hex.EncodeToString(xprv.Bytes()),
        }
        genDoc.SaveAs(genFile)