7 log "github.com/sirupsen/logrus"
8 "github.com/spf13/cobra"
9 cmn "github.com/tendermint/tmlibs/common"
11 "github.com/bytom/node"
12 "github.com/bytom/types"
15 var runNodeCmd = &cobra.Command{
17 Short: "Run the bytomd",
22 runNodeCmd.Flags().String("prof_laddr", config.ProfListenAddress, "Use http to profile bytomd programs")
23 runNodeCmd.Flags().Bool("mining", config.Mining, "Enable mining")
25 runNodeCmd.Flags().Bool("auth.disable", config.Auth.Disable, "Disable rpc access authenticate")
27 runNodeCmd.Flags().Bool("wallet.enable", config.Wallet.Enable, "Enable wallet")
30 runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
31 runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
32 runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
33 runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange ")
34 runNodeCmd.Flags().Int("p2p.max_num_peers", config.P2P.MaxNumPeers, "Set max num peers")
35 runNodeCmd.Flags().Int("p2p.handshake_timeout", config.P2P.HandshakeTimeout, "Set handshake timeout")
36 runNodeCmd.Flags().Int("p2p.dial_timeout", config.P2P.DialTimeout, "Set dial timeout")
38 RootCmd.AddCommand(runNodeCmd)
41 func runNode(cmd *cobra.Command, args []string) error {
42 genDocFile := config.GenesisFile()
43 if cmn.FileExists(genDocFile) {
44 jsonBlob, err := ioutil.ReadFile(genDocFile)
46 return fmt.Errorf("Couldn't read GenesisDoc file: %v", err)
48 genDoc, err := types.GenesisDocFromJSON(jsonBlob)
50 return fmt.Errorf("Error reading GenesisDoc: %v", err)
52 if genDoc.ChainID == "" {
53 return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
55 config.ChainID = genDoc.ChainID
56 config.PrivateKey = genDoc.PrivateKey
57 config.Time = genDoc.GenesisTime
59 return fmt.Errorf("not find genesis.json")
62 // Create & start node
63 n := node.NewNodeDefault(config)
64 if _, err := n.Start(); err != nil {
65 return fmt.Errorf("Failed to start node: %v", err)
67 log.WithField("nodeInfo", n.Switch().NodeInfo()).Info("Started node")
70 // Trap signal, run forever.