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