main.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
  2. //
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 2.1 of the License, or (at your option) any later version.
  7. //
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this library; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. // MA 02110-1301 USA
  17. package main
  18. import (
  19. "os"
  20. "runtime"
  21. "github.com/ethereum/go-ethereum"
  22. "github.com/ethereum/go-ethereum/cmd/utils"
  23. "github.com/ethereum/go-ethereum/logger"
  24. "gopkg.in/qml.v1"
  25. )
  26. const (
  27. ClientIdentifier = "Mist"
  28. Version = "0.7.2"
  29. )
  30. var ethereum *eth.Ethereum
  31. func run() error {
  32. // precedence: code-internal flag default < config file < environment variables < command line
  33. Init() // parsing command line
  34. config := utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
  35. utils.InitDataDir(Datadir)
  36. stdLog := utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
  37. db := utils.NewDatabase()
  38. err := utils.DBSanityCheck(db)
  39. if err != nil {
  40. ErrorWindow(err)
  41. os.Exit(1)
  42. }
  43. keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
  44. // create, import, export keys
  45. utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
  46. clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier)
  47. ethereum = utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer)
  48. if ShowGenesis {
  49. utils.ShowGenesis(ethereum)
  50. }
  51. if StartRpc {
  52. utils.StartRpc(ethereum, RpcPort)
  53. }
  54. gui := NewWindow(ethereum, config, clientIdentity, KeyRing, LogLevel)
  55. gui.stdLog = stdLog
  56. utils.RegisterInterrupt(func(os.Signal) {
  57. gui.Stop()
  58. })
  59. utils.StartEthereum(ethereum, UseSeed)
  60. // gui blocks the main thread
  61. gui.Start(AssetPath)
  62. return nil
  63. }
  64. func main() {
  65. runtime.GOMAXPROCS(runtime.NumCPU())
  66. // This is a bit of a cheat, but ey!
  67. os.Setenv("QTWEBKIT_INSPECTOR_SERVER", "127.0.0.1:99999")
  68. qml.Run(run)
  69. var interrupted = false
  70. utils.RegisterInterrupt(func(os.Signal) {
  71. interrupted = true
  72. })
  73. utils.HandleInterrupt()
  74. if StartWebSockets {
  75. utils.StartWebSockets(ethereum)
  76. }
  77. // we need to run the interrupt callbacks in case gui is closed
  78. // this skips if we got here by actual interrupt stopping the GUI
  79. if !interrupted {
  80. utils.RunInterruptCallbacks(os.Interrupt)
  81. }
  82. // this blocks the thread
  83. ethereum.WaitForShutdown()
  84. logger.Flush()
  85. }