OSDN Git Service

init blockchain cmd.
authorgguoss <1536310027@qq.com>
Fri, 14 Jul 2017 06:22:29 +0000 (14:22 +0800)
committergguoss <1536310027@qq.com>
Fri, 14 Jul 2017 06:22:29 +0000 (14:22 +0800)
cmd/blockchain/commands/init.go [deleted file]
cmd/blockchain/commands/root.go
cmd/blockchain/commands/run_node.go [deleted file]
cmd/blockchain/commands/version.go
cmd/blockchain/main.go
version/version.go [new file with mode: 0644]

diff --git a/cmd/blockchain/commands/init.go b/cmd/blockchain/commands/init.go
deleted file mode 100644 (file)
index 7ec7ac9..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-package commands
-
-import (
-       "os"
-
-       "github.com/spf13/cobra"
-
-       "github.com/node_p2p/types"
-       cmn "github.com/tendermint/tmlibs/common"
-)
-
-var initFilesCmd = &cobra.Command{
-       Use:   "init",
-       Short: "Initialize node_p2p",
-       Run:   initFiles,
-}
-
-func init() {
-       RootCmd.AddCommand(initFilesCmd)
-}
-
-func initFiles(cmd *cobra.Command, args []string) {
-       privValFile := config.PrivValidatorFile()
-       if _, err := os.Stat(privValFile); os.IsNotExist(err) {
-               privValidator := types.GenPrivValidator()
-               privValidator.SetFile(privValFile)
-               privValidator.Save()
-
-               genFile := config.GenesisFile()
-
-               if _, err := os.Stat(genFile); os.IsNotExist(err) {
-                       genDoc := types.GenesisDoc{
-                               ChainID: cmn.Fmt("chain0"),
-                       }
-                       genDoc.Validators = []types.GenesisValidator{types.GenesisValidator{
-                               PubKey: privValidator.PubKey,
-                               Amount: 10,
-                       }}
-
-                       genDoc.SaveAs(genFile)
-               }
-
-               logger.Info("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile())
-       } else {
-               logger.Info("Already initialized", "priv_validator", config.PrivValidatorFile())
-       }
-}
index 5fcd4fe..13026b8 100644 (file)
@@ -4,36 +4,27 @@ import (
        "os"
 
        "github.com/spf13/cobra"
-       "github.com/spf13/viper"
 
-       tmflags "github.com/node_p2p/node_p2p/commands/flags"
-       cfg "github.com/node_p2p/config"
+//     tmflags "github.com/blockchain/cmd/blockchain/commands/flags"
        "github.com/tendermint/tmlibs/log"
 )
 
 var (
-       config = cfg.DefaultConfig()
        logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
 )
 
 func init() {
-       RootCmd.PersistentFlags().String("log_level", config.LogLevel, "Log level")
+       RootCmd.PersistentFlags().String("log_level", "*:info", "Log level")
 }
 
 var RootCmd = &cobra.Command{
-       Use:   "node_p2p",
-       Short: "node_p2p in Go",
+       Use:   "blockchain",
+       Short: "blockchain in Go",
        PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
-               err := viper.Unmarshal(config)
+               /*logger, err := tmflags.ParseLogLevel("*:info", logger)
                if err != nil {
                        return err
-               }
-               config.SetRoot(config.RootDir)
-               cfg.EnsureRoot(config.RootDir)
-               logger, err = tmflags.ParseLogLevel(config.LogLevel, logger)
-               if err != nil {
-                       return err
-               }
+               }*/
                return nil
        },
 }
diff --git a/cmd/blockchain/commands/run_node.go b/cmd/blockchain/commands/run_node.go
deleted file mode 100644 (file)
index 0103603..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-package commands
-
-import (
-       "fmt"
-       "io/ioutil"
-       "time"
-
-       "github.com/spf13/cobra"
-
-       "github.com/node_p2p/node"
-       "github.com/node_p2p/types"
-       cmn "github.com/tendermint/tmlibs/common"
-)
-
-var runNodeCmd = &cobra.Command{
-       Use:   "node_p2p",
-       Short: "Run the p2p node",
-       RunE:  runNode,
-}
-
-func init() {
-       // p2p flags
-       runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
-       runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
-       runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
-       runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange (dev feature)")
-
-       RootCmd.AddCommand(runNodeCmd)
-}
-
-func runNode(cmd *cobra.Command, args []string) error {
-
-       // Wait until the genesis doc becomes available
-       // This is for Mintnet compatibility.
-       // TODO: If Mintnet gets deprecated or genesis_file is
-       // always available, remove.
-       genDocFile := config.GenesisFile()
-       if !cmn.FileExists(genDocFile) {
-               logger.Info(cmn.Fmt("Waiting for genesis file %v...", genDocFile))
-               for {
-                       time.Sleep(time.Second)
-                       if !cmn.FileExists(genDocFile) {
-                               continue
-                       }
-                       jsonBlob, err := ioutil.ReadFile(genDocFile)
-                       if err != nil {
-                               return fmt.Errorf("Couldn't read GenesisDoc file: %v", err)
-                       }
-                       genDoc, err := types.GenesisDocFromJSON(jsonBlob)
-                       if err != nil {
-                               return fmt.Errorf("Error reading GenesisDoc: %v", err)
-                       }
-                       if genDoc.ChainID == "" {
-                               return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
-                       }
-                       config.ChainID = genDoc.ChainID
-               }
-       }
-
-       // Create & start node
-       n := node.NewNodeDefault(config, logger.With("module", "node_p2p"))
-       if _, err := n.Start(); err != nil {
-               return fmt.Errorf("Failed to start node: %v", err)
-       } else {
-               logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
-       }
-
-       // Trap signal, run forever.
-       n.RunForever()
-
-       return nil
-}
index f7b40f8..11be247 100644 (file)
@@ -5,7 +5,7 @@ import (
 
        "github.com/spf13/cobra"
 
-       "github.com/node_p2p/version"
+       "github.com/blockchain/version"
 )
 
 var versionCmd = &cobra.Command{
index cb68520..da700f5 100644 (file)
@@ -3,11 +3,11 @@ package main
 import (
        "os"
 
-       "github.com/node_p2p/node_p2p/commands"
+       "github.com/blockchain/cmd/blockchain/commands"
        "github.com/tendermint/tmlibs/cli"
 )
 
 func main() {
-       cmd := cli.PrepareBaseCmd(commands.RootCmd, "TM", os.ExpandEnv("./.node"))
+       cmd := cli.PrepareBaseCmd(commands.RootCmd, "TM", os.ExpandEnv("./.blockchain"))
        cmd.Execute()
 }
diff --git a/version/version.go b/version/version.go
new file mode 100644 (file)
index 0000000..7d94176
--- /dev/null
@@ -0,0 +1,19 @@
+package version
+
+const Maj = "0"
+const Min = "1"
+const Fix = "0"
+
+var (
+       // The full version string
+       Version = "0.1.0"
+
+       // GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)"
+       GitCommit string
+)
+
+func init() {
+       if GitCommit != "" {
+               Version += "-" + GitCommit[:8]
+       }
+}