main.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/eth"
  27. "github.com/ethereum/go-ethereum/common"
  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. app = utils.NewApp(Version, "the ether browser")
  38. assetPathFlag = cli.StringFlag{
  39. Name: "asset_path",
  40. Usage: "absolute path to GUI assets directory",
  41. Value: common.DefaultAssetPath(),
  42. }
  43. )
  44. func init() {
  45. app.Action = run
  46. app.Flags = []cli.Flag{
  47. assetPathFlag,
  48. utils.BootnodesFlag,
  49. utils.DataDirFlag,
  50. utils.ListenPortFlag,
  51. utils.LogFileFlag,
  52. utils.LogLevelFlag,
  53. utils.MaxPeersFlag,
  54. utils.MinerThreadsFlag,
  55. utils.NATFlag,
  56. utils.NodeKeyFileFlag,
  57. utils.RPCListenAddrFlag,
  58. utils.RPCPortFlag,
  59. }
  60. }
  61. func main() {
  62. runtime.GOMAXPROCS(runtime.NumCPU())
  63. // This is a bit of a cheat, but ey!
  64. os.Setenv("QTWEBKIT_INSPECTOR_SERVER", "127.0.0.1:99999")
  65. var interrupted = false
  66. utils.RegisterInterrupt(func(os.Signal) {
  67. interrupted = true
  68. })
  69. utils.HandleInterrupt()
  70. if err := app.Run(os.Args); err != nil {
  71. fmt.Fprintln(os.Stderr, "Error: ", err)
  72. }
  73. // we need to run the interrupt callbacks in case gui is closed
  74. // this skips if we got here by actual interrupt stopping the GUI
  75. if !interrupted {
  76. utils.RunInterruptCallbacks(os.Interrupt)
  77. }
  78. logger.Flush()
  79. }
  80. func run(ctx *cli.Context) {
  81. tstart := time.Now()
  82. // TODO: show qml popup instead of exiting if initialization fails.
  83. cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
  84. ethereum, err := eth.New(cfg)
  85. if err != nil {
  86. utils.Fatalf("%v", err)
  87. }
  88. utils.StartRPC(ethereum, ctx)
  89. go utils.StartEthereum(ethereum)
  90. fmt.Println("initializing eth stack took", time.Since(tstart))
  91. // Open the window
  92. qml.Run(func() error {
  93. webengine.Initialize()
  94. gui := NewWindow(ethereum)
  95. utils.RegisterInterrupt(func(os.Signal) { gui.Stop() })
  96. // gui blocks the main thread
  97. gui.Start(ctx.GlobalString(assetPathFlag.Name))
  98. return nil
  99. })
  100. }