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("wallet.enable", config.Wallet.Enable, "Enable wallet")
28 runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
29 runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
30 runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
31 runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange ")
32 runNodeCmd.Flags().Int("p2p.max_num_peers", config.P2P.MaxNumPeers, "Set max num peers")
33 runNodeCmd.Flags().Int("p2p.handshake_timeout", config.P2P.HandshakeTimeout, "Set handshake timeout")
34 runNodeCmd.Flags().Int("p2p.dial_timeout", config.P2P.DialTimeout, "Set dial timeout")
36 RootCmd.AddCommand(runNodeCmd)
39 func runNode(cmd *cobra.Command, args []string) error {
40 genDocFile := config.GenesisFile()
41 if cmn.FileExists(genDocFile) {
42 jsonBlob, err := ioutil.ReadFile(genDocFile)
44 return fmt.Errorf("Couldn't read GenesisDoc file: %v", err)
46 genDoc, err := types.GenesisDocFromJSON(jsonBlob)
48 return fmt.Errorf("Error reading GenesisDoc: %v", err)
50 if genDoc.ChainID == "" {
51 return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
53 config.ChainID = genDoc.ChainID
54 config.PrivateKey = genDoc.PrivateKey
55 config.Time = genDoc.GenesisTime
57 return fmt.Errorf("not find genesis.json")
60 // Create & start node
61 n := node.NewNodeDefault(config)
62 if _, err := n.Start(); err != nil {
63 return fmt.Errorf("Failed to start node: %v", err)
65 log.WithField("nodeInfo", n.Switch().NodeInfo()).Info("Started node")
68 // Trap signal, run forever.