main.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. "github.com/ethereum/go-ethereum/chain"
  23. "github.com/ethereum/go-ethereum/cmd/utils"
  24. "github.com/ethereum/go-ethereum/ethutil"
  25. "github.com/ethereum/go-ethereum/logger"
  26. "github.com/ethgo.old/ethlog"
  27. )
  28. const (
  29. ClientIdentifier = "Ethereum(G)"
  30. Version = "0.7.0"
  31. )
  32. var clilogger = logger.NewLogger("CLI")
  33. func main() {
  34. runtime.GOMAXPROCS(runtime.NumCPU())
  35. utils.HandleInterrupt()
  36. // precedence: code-internal flag default < config file < environment variables < command line
  37. Init() // parsing command line
  38. // If the difftool option is selected ignore all other log output
  39. if DiffTool || Dump {
  40. LogLevel = 0
  41. }
  42. utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
  43. ethutil.Config.Diff = DiffTool
  44. ethutil.Config.DiffType = DiffType
  45. utils.InitDataDir(Datadir)
  46. utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
  47. db := utils.NewDatabase()
  48. err := utils.DBSanityCheck(db)
  49. if err != nil {
  50. fmt.Println(err)
  51. os.Exit(1)
  52. }
  53. keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
  54. // create, import, export keys
  55. utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
  56. clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier)
  57. ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer)
  58. if Dump {
  59. var block *chain.Block
  60. if len(DumpHash) == 0 && DumpNumber == -1 {
  61. block = ethereum.ChainManager().CurrentBlock
  62. } else if len(DumpHash) > 0 {
  63. block = ethereum.ChainManager().GetBlock(ethutil.Hex2Bytes(DumpHash))
  64. } else {
  65. block = ethereum.ChainManager().GetBlockByNumber(uint64(DumpNumber))
  66. }
  67. if block == nil {
  68. fmt.Fprintln(os.Stderr, "block not found")
  69. // We want to output valid JSON
  70. fmt.Println("{}")
  71. os.Exit(1)
  72. }
  73. fmt.Printf("RLP: %x\nstate: %x\nhash: %x\n", ethutil.Rlp(block), block.GetRoot(), block.Hash())
  74. // Leave the Println. This needs clean output for piping
  75. fmt.Printf("%s\n", block.State().Dump())
  76. fmt.Println(block)
  77. os.Exit(0)
  78. }
  79. if ShowGenesis {
  80. utils.ShowGenesis(ethereum)
  81. }
  82. if StartMining {
  83. utils.StartMining(ethereum)
  84. }
  85. // better reworked as cases
  86. if StartJsConsole {
  87. InitJsConsole(ethereum)
  88. } else if len(InputFile) > 0 {
  89. ExecJsFile(ethereum, InputFile)
  90. }
  91. if StartRpc {
  92. utils.StartRpc(ethereum, RpcPort)
  93. }
  94. if StartWebSockets {
  95. utils.StartWebSockets(ethereum)
  96. }
  97. utils.StartEthereum(ethereum, UseSeed)
  98. // this blocks the thread
  99. ethereum.WaitForShutdown()
  100. ethlog.Flush()
  101. }