OSDN Git Service

little edit (#107)
[bytom/vapor.git] / cmd / bytomd / commands / init.go
index 951aecb..4003047 100644 (file)
@@ -38,15 +38,15 @@ func initFiles(cmd *cobra.Command, args []string) {
                cfg.EnsureRoot(config.RootDir, "solonet")
        }
 
-       fedFile := config.FederationFile()
-       if _, err := os.Stat(fedFile); !os.IsNotExist(err) {
-               log.WithFields(log.Fields{"module": logModule, "config": fedFile}).Panic("Already exists federation file.")
-       }
-
-       if err := cfg.ExportFederationFile(fedFile, config); err != nil {
-               log.WithFields(log.Fields{"module": logModule, "config": fedFile, "error": err}).Panic("exportFederationFile failed.")
+       //generate the federation config file
+       fedFilePath := config.FederationFile()
+       if _, err := os.Stat(fedFilePath); os.IsNotExist(err) {
+               if err := cfg.ExportFederationFile(fedFilePath, config); err != nil {
+                       log.WithFields(log.Fields{"module": logModule, "config": fedFilePath, "error": err}).Panic("fail on export federation file")
+               }
        }
 
+       //generate the node private key
        keyFilePath := path.Join(config.RootDir, config.PrivateKeyFile)
        if _, err := os.Stat(keyFilePath); os.IsNotExist(err) {
                xprv, err := chainkd.NewXPrv(nil)
@@ -54,10 +54,11 @@ func initFiles(cmd *cobra.Command, args []string) {
                        log.WithFields(log.Fields{"module": logModule, "err": err}).Panic("fail on generate private key")
                }
 
-               xprvStr := hex.EncodeToString(xprv[:])
-               if err := ioutil.WriteFile(keyFilePath, []byte(xprvStr), 0600); err != nil {
+               if err := ioutil.WriteFile(keyFilePath, []byte(hex.EncodeToString(xprv[:])), 0600); err != nil {
                        log.WithFields(log.Fields{"module": logModule, "err": err}).Panic("fail on save private key")
                }
+
+               log.WithFields(log.Fields{"pubkey": xprv.XPub()}).Info("success generate private")
        }
 
        log.WithFields(log.Fields{"module": logModule, "config": configFilePath}).Info("Initialized bytom")