github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/ethereum/flags.go (about)

     1  /*
     2  	This file is part of go-ethereum
     3  
     4  	go-ethereum is free software: you can redistribute it and/or modify
     5  	it under the terms of the GNU General Public License as published by
     6  	the Free Software Foundation, either version 3 of the License, or
     7  	(at your option) any later version.
     8  
     9  	go-ethereum is distributed in the hope that it will be useful,
    10  	but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  	GNU General Public License for more details.
    13  
    14  	You should have received a copy of the GNU General Public License
    15  	along with go-ethereum.  If not, see <http://www.gnu.org/licenses/>.
    16  */
    17  /**
    18   * @authors
    19   * 	Jeffrey Wilcke <i@jev.io>
    20   */
    21  package main
    22  
    23  import (
    24  	"crypto/ecdsa"
    25  	"flag"
    26  	"fmt"
    27  	"log"
    28  	"os"
    29  	"os/user"
    30  	"path"
    31  
    32  	"github.com/jonasnick/go-ethereum/crypto"
    33  	"github.com/jonasnick/go-ethereum/logger"
    34  	"github.com/jonasnick/go-ethereum/p2p/nat"
    35  	"github.com/jonasnick/go-ethereum/vm"
    36  )
    37  
    38  var (
    39  	Identifier      string
    40  	KeyRing         string
    41  	DiffTool        bool
    42  	DiffType        string
    43  	KeyStore        string
    44  	StartRpc        bool
    45  	StartWebSockets bool
    46  	RpcPort         int
    47  	WsPort          int
    48  	OutboundPort    string
    49  	ShowGenesis     bool
    50  	AddPeer         string
    51  	MaxPeer         int
    52  	GenAddr         bool
    53  	BootNodes       string
    54  	NodeKey         *ecdsa.PrivateKey
    55  	NAT             nat.Interface
    56  	SecretFile      string
    57  	ExportDir       string
    58  	NonInteractive  bool
    59  	Datadir         string
    60  	LogFile         string
    61  	ConfigFile      string
    62  	DebugFile       string
    63  	LogLevel        int
    64  	LogFormat       string
    65  	Dump            bool
    66  	DumpHash        string
    67  	DumpNumber      int
    68  	VmType          int
    69  	ImportChain     string
    70  	SHH             bool
    71  	Dial            bool
    72  	PrintVersion    bool
    73  )
    74  
    75  // flags specific to cli client
    76  var (
    77  	StartMining    bool
    78  	StartJsConsole bool
    79  	InputFile      string
    80  )
    81  
    82  func defaultDataDir() string {
    83  	usr, _ := user.Current()
    84  	return path.Join(usr.HomeDir, ".ethereum")
    85  }
    86  
    87  var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini")
    88  
    89  func Init() {
    90  	// TODO: move common flag processing to cmd/util
    91  	flag.Usage = func() {
    92  		fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
    93  		flag.PrintDefaults()
    94  	}
    95  
    96  	flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
    97  	flag.StringVar(&Identifier, "id", "", "Custom client identifier")
    98  	flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
    99  	flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
   100  
   101  	flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
   102  	flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
   103  	flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
   104  	flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
   105  	flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
   106  	flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
   107  	flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
   108  	flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
   109  	flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
   110  	flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
   111  	flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
   112  	flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
   113  	flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
   114  	flag.StringVar(&LogFormat, "logformat", "std", "logformat: std,raw)")
   115  	flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
   116  	flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
   117  	flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
   118  	flag.StringVar(&ImportChain, "chain", "", "Imports given chain")
   119  
   120  	flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
   121  	flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
   122  	flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")
   123  
   124  	flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
   125  	flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
   126  	flag.BoolVar(&PrintVersion, "version", false, "prints version number")
   127  
   128  	// Network stuff
   129  	var (
   130  		nodeKeyFile = flag.String("nodekey", "", "network private key file")
   131  		nodeKeyHex  = flag.String("nodekeyhex", "", "network private key (for testing)")
   132  		natstr      = flag.String("nat", "any", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
   133  	)
   134  	flag.BoolVar(&Dial, "dial", true, "dial out connections (default on)")
   135  	flag.BoolVar(&SHH, "shh", true, "run whisper protocol (default on)")
   136  	flag.StringVar(&OutboundPort, "port", "30303", "listening port")
   137  
   138  	flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
   139  	flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
   140  
   141  	flag.Parse()
   142  
   143  	var err error
   144  	if NAT, err = nat.Parse(*natstr); err != nil {
   145  		log.Fatalf("-nat: %v", err)
   146  	}
   147  	switch {
   148  	case *nodeKeyFile != "" && *nodeKeyHex != "":
   149  		log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive")
   150  	case *nodeKeyFile != "":
   151  		if NodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil {
   152  			log.Fatalf("-nodekey: %v", err)
   153  		}
   154  	case *nodeKeyHex != "":
   155  		if NodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil {
   156  			log.Fatalf("-nodekeyhex: %v", err)
   157  		}
   158  	}
   159  
   160  	if VmType >= int(vm.MaxVmTy) {
   161  		log.Fatal("Invalid VM type ", VmType)
   162  	}
   163  
   164  	InputFile = flag.Arg(0)
   165  }