github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/ethereum/main.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 "fmt" 25 "os" 26 "runtime" 27 "time" 28 29 "github.com/jonasnick/go-ethereum/cmd/utils" 30 "github.com/jonasnick/go-ethereum/core/types" 31 "github.com/jonasnick/go-ethereum/eth" 32 "github.com/jonasnick/go-ethereum/ethutil" 33 "github.com/jonasnick/go-ethereum/logger" 34 "github.com/jonasnick/go-ethereum/p2p" 35 "github.com/jonasnick/go-ethereum/state" 36 ) 37 38 const ( 39 ClientIdentifier = "Ethereum(G)" 40 Version = "0.8.3" 41 ) 42 43 var clilogger = logger.NewLogger("CLI") 44 45 func main() { 46 runtime.GOMAXPROCS(runtime.NumCPU()) 47 48 defer func() { 49 logger.Flush() 50 }() 51 52 utils.HandleInterrupt() 53 54 // precedence: code-internal flag default < config file < environment variables < command line 55 Init() // parsing command line 56 57 if PrintVersion { 58 printVersion() 59 return 60 } 61 62 utils.InitConfig(VmType, ConfigFile, Datadir, "ETH") 63 64 ethereum, err := eth.New(ð.Config{ 65 Name: p2p.MakeName(ClientIdentifier, Version), 66 KeyStore: KeyStore, 67 DataDir: Datadir, 68 LogFile: LogFile, 69 LogLevel: LogLevel, 70 MaxPeers: MaxPeer, 71 Port: OutboundPort, 72 NAT: NAT, 73 KeyRing: KeyRing, 74 Shh: SHH, 75 Dial: Dial, 76 BootNodes: BootNodes, 77 NodeKey: NodeKey, 78 }) 79 80 if err != nil { 81 clilogger.Fatalln(err) 82 } 83 84 utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) 85 86 if Dump { 87 var block *types.Block 88 89 if len(DumpHash) == 0 && DumpNumber == -1 { 90 block = ethereum.ChainManager().CurrentBlock() 91 } else if len(DumpHash) > 0 { 92 block = ethereum.ChainManager().GetBlock(ethutil.Hex2Bytes(DumpHash)) 93 } else { 94 block = ethereum.ChainManager().GetBlockByNumber(uint64(DumpNumber)) 95 } 96 97 if block == nil { 98 fmt.Fprintln(os.Stderr, "block not found") 99 100 // We want to output valid JSON 101 fmt.Println("{}") 102 103 os.Exit(1) 104 } 105 106 // Leave the Println. This needs clean output for piping 107 statedb := state.New(block.Root(), ethereum.Db()) 108 fmt.Printf("%s\n", statedb.Dump()) 109 110 fmt.Println(block) 111 112 return 113 } 114 115 if StartMining { 116 utils.StartMining(ethereum) 117 } 118 119 if len(ImportChain) > 0 { 120 start := time.Now() 121 err := utils.ImportChain(ethereum, ImportChain) 122 if err != nil { 123 clilogger.Infoln(err) 124 } 125 clilogger.Infoln("import done in", time.Since(start)) 126 return 127 } 128 129 if StartRpc { 130 utils.StartRpc(ethereum, RpcPort) 131 } 132 133 if StartWebSockets { 134 utils.StartWebSockets(ethereum, WsPort) 135 } 136 137 utils.StartEthereum(ethereum) 138 139 if StartJsConsole { 140 InitJsConsole(ethereum) 141 } else if len(InputFile) > 0 { 142 ExecJsFile(ethereum, InputFile) 143 } 144 // this blocks the thread 145 ethereum.WaitForShutdown() 146 } 147 148 func printVersion() { 149 fmt.Printf(`%v %v 150 PV=%d 151 GOOS=%s 152 GO=%s 153 GOPATH=%s 154 GOROOT=%s 155 `, ClientIdentifier, Version, eth.ProtocolVersion, runtime.GOOS, runtime.Version(), os.Getenv("GOPATH"), runtime.GOROOT()) 156 }