main.go 3.3 KB

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