main.go 3.4 KB

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