main.go 2.4 KB

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