main.go 3.2 KB

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