main.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package main
  2. import (
  3. "github.com/ethereum/eth-go/ethlog"
  4. "github.com/ethereum/go-ethereum/ethereal/ui"
  5. "github.com/ethereum/go-ethereum/utils"
  6. "github.com/go-qml/qml"
  7. "os"
  8. "runtime"
  9. )
  10. func main() {
  11. // Leave QT on top at ALL times. Qt Needs to be initialized from the main thread
  12. qml.Init(nil)
  13. runtime.GOMAXPROCS(runtime.NumCPU())
  14. var interrupted = false
  15. utils.RegisterInterrupt(func(os.Signal) {
  16. interrupted = true
  17. })
  18. utils.HandleInterrupt()
  19. // precedence: code-internal flag default < config file < environment variables < command line
  20. Init() // parsing command line
  21. utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH")
  22. utils.InitDataDir(Datadir)
  23. utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
  24. db := utils.NewDatabase()
  25. keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
  26. // create, import, export keys
  27. utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
  28. ethereum := utils.NewEthereum(db, keyManager, UseUPnP, OutboundPort, MaxPeer)
  29. if ShowGenesis {
  30. utils.ShowGenesis(ethereum)
  31. }
  32. if StartRpc {
  33. utils.StartRpc(ethereum, RpcPort)
  34. }
  35. gui := ethui.New(ethereum, KeyRing, LogLevel)
  36. utils.RegisterInterrupt(func(os.Signal) {
  37. gui.Stop()
  38. })
  39. utils.StartEthereum(ethereum, UseSeed)
  40. // gui blocks the main thread
  41. gui.Start(AssetPath)
  42. // we need to run the interrupt callbacks in case gui is closed
  43. // this skips if we got here by actual interrupt stopping the GUI
  44. if !interrupted {
  45. utils.RunInterruptCallbacks(os.Interrupt)
  46. }
  47. // this blocks the thread
  48. ethereum.WaitForShutdown()
  49. ethlog.Flush()
  50. }