main.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. "fmt"
  20. "os"
  21. "runtime"
  22. "time"
  23. "github.com/ethereum/go-ethereum/cmd/utils"
  24. "github.com/ethereum/go-ethereum/core/types"
  25. "github.com/ethereum/go-ethereum/eth"
  26. "github.com/ethereum/go-ethereum/ethutil"
  27. "github.com/ethereum/go-ethereum/logger"
  28. )
  29. const (
  30. ClientIdentifier = "Ethereum(G)"
  31. Version = "0.7.11"
  32. )
  33. var clilogger = logger.NewLogger("CLI")
  34. func main() {
  35. runtime.GOMAXPROCS(runtime.NumCPU())
  36. defer func() {
  37. logger.Flush()
  38. }()
  39. utils.HandleInterrupt()
  40. // precedence: code-internal flag default < config file < environment variables < command line
  41. Init() // parsing command line
  42. utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
  43. ethereum, err := eth.New(&eth.Config{
  44. Name: ClientIdentifier,
  45. Version: Version,
  46. KeyStore: KeyStore,
  47. DataDir: Datadir,
  48. LogFile: LogFile,
  49. LogLevel: LogLevel,
  50. Identifier: Identifier,
  51. MaxPeers: MaxPeer,
  52. Port: OutboundPort,
  53. NATType: PMPGateway,
  54. PMPGateway: PMPGateway,
  55. KeyRing: KeyRing,
  56. })
  57. if err != nil {
  58. clilogger.Fatalln(err)
  59. }
  60. utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
  61. if Dump {
  62. var block *types.Block
  63. if len(DumpHash) == 0 && DumpNumber == -1 {
  64. block = ethereum.ChainManager().CurrentBlock()
  65. } else if len(DumpHash) > 0 {
  66. block = ethereum.ChainManager().GetBlock(ethutil.Hex2Bytes(DumpHash))
  67. } else {
  68. block = ethereum.ChainManager().GetBlockByNumber(uint64(DumpNumber))
  69. }
  70. if block == nil {
  71. fmt.Fprintln(os.Stderr, "block not found")
  72. // We want to output valid JSON
  73. fmt.Println("{}")
  74. os.Exit(1)
  75. }
  76. // Leave the Println. This needs clean output for piping
  77. fmt.Printf("%s\n", block.State().Dump())
  78. fmt.Println(block)
  79. return
  80. }
  81. if StartMining {
  82. utils.StartMining(ethereum)
  83. }
  84. if len(ImportChain) > 0 {
  85. start := time.Now()
  86. err := utils.ImportChain(ethereum, ImportChain)
  87. if err != nil {
  88. clilogger.Infoln(err)
  89. }
  90. clilogger.Infoln("import done in", time.Since(start))
  91. return
  92. }
  93. // better reworked as cases
  94. if StartJsConsole {
  95. InitJsConsole(ethereum)
  96. } else if len(InputFile) > 0 {
  97. ExecJsFile(ethereum, InputFile)
  98. }
  99. if StartRpc {
  100. utils.StartRpc(ethereum, RpcPort)
  101. }
  102. if StartWebSockets {
  103. utils.StartWebSockets(ethereum)
  104. }
  105. utils.StartEthereum(ethereum, UseSeed)
  106. // this blocks the thread
  107. ethereum.WaitForShutdown()
  108. }