flags.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. "crypto/ecdsa"
  21. "flag"
  22. "fmt"
  23. "log"
  24. "os"
  25. "path"
  26. "runtime"
  27. "github.com/ethereum/go-ethereum/crypto"
  28. "github.com/ethereum/go-ethereum/ethutil"
  29. "github.com/ethereum/go-ethereum/logger"
  30. "github.com/ethereum/go-ethereum/p2p/nat"
  31. "github.com/ethereum/go-ethereum/vm"
  32. )
  33. var (
  34. Identifier string
  35. KeyRing string
  36. DiffTool bool
  37. DiffType string
  38. KeyStore string
  39. StartRpc bool
  40. StartWebSockets bool
  41. RpcListenAddress string
  42. RpcPort int
  43. WsPort int
  44. OutboundPort string
  45. ShowGenesis bool
  46. AddPeer string
  47. MaxPeer int
  48. GenAddr bool
  49. BootNodes string
  50. NodeKey *ecdsa.PrivateKey
  51. NAT nat.Interface
  52. SecretFile string
  53. ExportDir string
  54. NonInteractive bool
  55. Datadir string
  56. LogFile string
  57. ConfigFile string
  58. DebugFile string
  59. LogLevel int
  60. LogFormat string
  61. Dump bool
  62. DumpHash string
  63. DumpNumber int
  64. VmType int
  65. ImportChain string
  66. SHH bool
  67. Dial bool
  68. PrintVersion bool
  69. MinerThreads int
  70. )
  71. // flags specific to cli client
  72. var (
  73. StartMining bool
  74. StartJsConsole bool
  75. InputFile string
  76. )
  77. var defaultConfigFile = path.Join(ethutil.DefaultDataDir(), "conf.ini")
  78. func Init() {
  79. // TODO: move common flag processing to cmd/util
  80. flag.Usage = func() {
  81. fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
  82. flag.PrintDefaults()
  83. }
  84. flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
  85. flag.StringVar(&Identifier, "id", "", "Custom client identifier")
  86. flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
  87. flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
  88. flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
  89. flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
  90. flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
  91. flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
  92. flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
  93. flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
  94. flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
  95. flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
  96. flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
  97. flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
  98. flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
  99. flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
  100. flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
  101. flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
  102. flag.StringVar(&LogFormat, "logformat", "std", "logformat: std,raw)")
  103. flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
  104. flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
  105. flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
  106. flag.StringVar(&ImportChain, "chain", "", "Imports given chain")
  107. flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
  108. flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
  109. flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")
  110. flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
  111. flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
  112. flag.BoolVar(&PrintVersion, "version", false, "prints version number")
  113. flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")
  114. // Network stuff
  115. var (
  116. nodeKeyFile = flag.String("nodekey", "", "network private key file")
  117. nodeKeyHex = flag.String("nodekeyhex", "", "network private key (for testing)")
  118. natstr = flag.String("nat", "any", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
  119. )
  120. flag.BoolVar(&Dial, "dial", true, "dial out connections (default on)")
  121. //flag.BoolVar(&SHH, "shh", true, "run whisper protocol (default on)")
  122. flag.StringVar(&OutboundPort, "port", "30303", "listening port")
  123. flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
  124. flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
  125. flag.Parse()
  126. // When the javascript console is started log to a file instead
  127. // of stdout
  128. if StartJsConsole {
  129. LogFile = path.Join(Datadir, "ethereum.log")
  130. }
  131. var err error
  132. if NAT, err = nat.Parse(*natstr); err != nil {
  133. log.Fatalf("-nat: %v", err)
  134. }
  135. switch {
  136. case *nodeKeyFile != "" && *nodeKeyHex != "":
  137. log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive")
  138. case *nodeKeyFile != "":
  139. if NodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil {
  140. log.Fatalf("-nodekey: %v", err)
  141. }
  142. case *nodeKeyHex != "":
  143. if NodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil {
  144. log.Fatalf("-nodekeyhex: %v", err)
  145. }
  146. }
  147. if VmType >= int(vm.MaxVmTy) {
  148. log.Fatal("Invalid VM type ", VmType)
  149. }
  150. InputFile = flag.Arg(0)
  151. }