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