main.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/ethereum/go-ethereum/cmd/utils"
  25. "github.com/ethereum/go-ethereum/eth"
  26. "github.com/ethereum/go-ethereum/logger"
  27. "github.com/ethereum/go-ethereum/p2p"
  28. "gopkg.in/qml.v1"
  29. )
  30. const (
  31. ClientIdentifier = "Mist"
  32. Version = "0.8.1"
  33. )
  34. var ethereum *eth.Ethereum
  35. var mainlogger = logger.NewLogger("MAIN")
  36. func run() error {
  37. // precedence: code-internal flag default < config file < environment variables < command line
  38. Init() // parsing command line
  39. tstart := time.Now()
  40. config := utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
  41. ethereum, err := eth.New(&eth.Config{
  42. Name: ClientIdentifier,
  43. Version: Version,
  44. KeyStore: KeyStore,
  45. DataDir: Datadir,
  46. LogFile: LogFile,
  47. LogLevel: LogLevel,
  48. Identifier: Identifier,
  49. MaxPeers: MaxPeer,
  50. Port: OutboundPort,
  51. NATType: PMPGateway,
  52. PMPGateway: PMPGateway,
  53. KeyRing: KeyRing,
  54. Dial: true,
  55. })
  56. if err != nil {
  57. mainlogger.Fatalln(err)
  58. }
  59. utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
  60. if StartRpc {
  61. utils.StartRpc(ethereum, RpcPort)
  62. }
  63. if StartWebSockets {
  64. utils.StartWebSockets(ethereum)
  65. }
  66. gui := NewWindow(ethereum, config, ethereum.ClientIdentity().(*p2p.SimpleClientIdentity), KeyRing, LogLevel)
  67. utils.RegisterInterrupt(func(os.Signal) {
  68. gui.Stop()
  69. })
  70. go utils.StartEthereum(ethereum, UseSeed)
  71. fmt.Println("ETH stack took", time.Since(tstart))
  72. // gui blocks the main thread
  73. gui.Start(AssetPath)
  74. return nil
  75. }
  76. func main() {
  77. runtime.GOMAXPROCS(runtime.NumCPU())
  78. // This is a bit of a cheat, but ey!
  79. os.Setenv("QTWEBKIT_INSPECTOR_SERVER", "127.0.0.1:99999")
  80. qml.Run(run)
  81. var interrupted = false
  82. utils.RegisterInterrupt(func(os.Signal) {
  83. interrupted = true
  84. })
  85. utils.HandleInterrupt()
  86. // we need to run the interrupt callbacks in case gui is closed
  87. // this skips if we got here by actual interrupt stopping the GUI
  88. if !interrupted {
  89. utils.RunInterruptCallbacks(os.Interrupt)
  90. }
  91. logger.Flush()
  92. }