main.go 3.4 KB

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