main.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. This file is part of go-ethereum
  3. go-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. go-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /**
  15. * @authors
  16. * Jeffrey Wilcke <i@jev.io>
  17. */
  18. package main
  19. import (
  20. "fmt"
  21. "os"
  22. "runtime"
  23. "time"
  24. "github.com/codegangsta/cli"
  25. "github.com/ethereum/go-ethereum/cmd/utils"
  26. "github.com/ethereum/go-ethereum/common"
  27. "github.com/ethereum/go-ethereum/eth"
  28. "github.com/ethereum/go-ethereum/logger"
  29. "github.com/ethereum/go-ethereum/ui/qt/webengine"
  30. "github.com/obscuren/qml"
  31. )
  32. const (
  33. ClientIdentifier = "Mist"
  34. Version = "0.9.0"
  35. )
  36. var (
  37. gitCommit string // set via linker flag
  38. nodeNameVersion string
  39. app = utils.NewApp(Version, "the ether browser")
  40. assetPathFlag = cli.StringFlag{
  41. Name: "asset_path",
  42. Usage: "absolute path to GUI assets directory",
  43. Value: common.DefaultAssetPath(),
  44. }
  45. rpcCorsFlag = utils.RPCCORSDomainFlag
  46. )
  47. func init() {
  48. // Mist-specific default
  49. if len(rpcCorsFlag.Value) == 0 {
  50. rpcCorsFlag.Value = "http://localhost"
  51. }
  52. if gitCommit == "" {
  53. nodeNameVersion = Version
  54. } else {
  55. nodeNameVersion = Version + "-" + gitCommit[:8]
  56. }
  57. app.Action = run
  58. app.Flags = []cli.Flag{
  59. assetPathFlag,
  60. rpcCorsFlag,
  61. utils.BootnodesFlag,
  62. utils.DataDirFlag,
  63. utils.ListenPortFlag,
  64. utils.LogFileFlag,
  65. utils.LogLevelFlag,
  66. utils.MaxPeersFlag,
  67. utils.MaxPendingPeersFlag,
  68. utils.MinerThreadsFlag,
  69. utils.NATFlag,
  70. utils.NodeKeyFileFlag,
  71. utils.RPCListenAddrFlag,
  72. utils.RPCPortFlag,
  73. utils.JSpathFlag,
  74. utils.ProtocolVersionFlag,
  75. utils.BlockchainVersionFlag,
  76. utils.NetworkIdFlag,
  77. }
  78. }
  79. func main() {
  80. runtime.GOMAXPROCS(runtime.NumCPU())
  81. // This is a bit of a cheat, but ey!
  82. os.Setenv("QTWEBKIT_INSPECTOR_SERVER", "127.0.0.1:99999")
  83. var interrupted = false
  84. utils.RegisterInterrupt(func(os.Signal) {
  85. interrupted = true
  86. })
  87. utils.HandleInterrupt()
  88. if err := app.Run(os.Args); err != nil {
  89. fmt.Fprintln(os.Stderr, "Error: ", err)
  90. }
  91. // we need to run the interrupt callbacks in case gui is closed
  92. // this skips if we got here by actual interrupt stopping the GUI
  93. if !interrupted {
  94. utils.RunInterruptCallbacks(os.Interrupt)
  95. }
  96. logger.Flush()
  97. }
  98. func run(ctx *cli.Context) {
  99. tstart := time.Now()
  100. // TODO: show qml popup instead of exiting if initialization fails.
  101. cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
  102. cfg.Shh = true
  103. ethereum, err := eth.New(cfg)
  104. if err != nil {
  105. utils.Fatalf("%v", err)
  106. }
  107. utils.StartRPC(ethereum, ctx)
  108. go utils.StartEthereum(ethereum)
  109. fmt.Println("initializing eth stack took", time.Since(tstart))
  110. // Open the window
  111. qml.Run(func() error {
  112. webengine.Initialize()
  113. gui := NewWindow(ethereum)
  114. utils.RegisterInterrupt(func(os.Signal) { gui.Stop() })
  115. // gui blocks the main thread
  116. gui.Start(ctx.GlobalString(assetPathFlag.Name), ctx.GlobalString(utils.JSpathFlag.Name))
  117. return nil
  118. })
  119. }