aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/cmd.go88
-rw-r--r--cmd/utils/customflags.go16
-rw-r--r--cmd/utils/customflags_test.go16
-rw-r--r--cmd/utils/flags.go68
4 files changed, 116 insertions, 72 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index f7520a8e4..2949d2470 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -1,24 +1,20 @@
-/*
- This file is part of go-ethereum
+// Copyright 2014 The go-ethereum Authors
+// This file is part of go-ethereum.
+//
+// go-ethereum is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// go-ethereum is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
- go-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- go-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
-*/
-/**
- * @authors
- * Jeffrey Wilcke <i@jev.io>
- * Viktor Tron <viktor@ethdev.com>
- */
+// Package utils contains internal helper functions for go-ethereum commands.
package utils
import (
@@ -46,29 +42,6 @@ const (
var interruptCallbacks = []func(os.Signal){}
-// Register interrupt handlers callbacks
-func RegisterInterrupt(cb func(os.Signal)) {
- interruptCallbacks = append(interruptCallbacks, cb)
-}
-
-// go routine that call interrupt handlers in order of registering
-func HandleInterrupt() {
- c := make(chan os.Signal, 1)
- go func() {
- signal.Notify(c, os.Interrupt)
- for sig := range c {
- glog.V(logger.Error).Infof("Shutting down (%v) ... \n", sig)
- RunInterruptCallbacks(sig)
- }
- }()
-}
-
-func RunInterruptCallbacks(sig os.Signal) {
- for _, cb := range interruptCallbacks {
- cb(sig)
- }
-}
-
func openLogFile(Datadir string, filename string) *os.File {
path := common.AbsolutePath(Datadir, filename)
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
@@ -149,19 +122,24 @@ func StartEthereum(ethereum *eth.Ethereum) {
if err := ethereum.Start(); err != nil {
Fatalf("Error starting Ethereum: %v", err)
}
- RegisterInterrupt(func(sig os.Signal) {
- ethereum.Stop()
- logger.Flush()
- })
-}
-
-func StartEthereumForTest(ethereum *eth.Ethereum) {
- glog.V(logger.Info).Infoln("Starting ", ethereum.Name())
- ethereum.StartForTest()
- RegisterInterrupt(func(sig os.Signal) {
- ethereum.Stop()
+ go func() {
+ sigc := make(chan os.Signal, 1)
+ signal.Notify(sigc, os.Interrupt)
+ defer signal.Stop(sigc)
+ <-sigc
+ glog.V(logger.Info).Infoln("Got interrupt, shutting down...")
+ go ethereum.Stop()
logger.Flush()
- })
+ for i := 10; i > 0; i-- {
+ <-sigc
+ if i > 1 {
+ glog.V(logger.Info).Infoln("Already shutting down, please be patient.")
+ glog.V(logger.Info).Infoln("Interrupt", i-1, "more times to induce panic.")
+ }
+ }
+ glog.V(logger.Error).Infof("Force quitting: this might not end so well.")
+ panic("boom")
+ }()
}
func FormatTransactionData(data string) []byte {
diff --git a/cmd/utils/customflags.go b/cmd/utils/customflags.go
index 78a6b8d22..6aeec448c 100644
--- a/cmd/utils/customflags.go
+++ b/cmd/utils/customflags.go
@@ -1,3 +1,19 @@
+// Copyright 2015 The go-ethereum Authors
+// This file is part of go-ethereum.
+//
+// go-ethereum is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// go-ethereum is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+
package utils
import (
diff --git a/cmd/utils/customflags_test.go b/cmd/utils/customflags_test.go
index 11deb38ef..726d1ab47 100644
--- a/cmd/utils/customflags_test.go
+++ b/cmd/utils/customflags_test.go
@@ -1,3 +1,19 @@
+// Copyright 2015 The go-ethereum Authors
+// This file is part of go-ethereum.
+//
+// go-ethereum is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// go-ethereum is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+
package utils
import (
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 0d59980ec..903c97e71 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -1,3 +1,19 @@
+// Copyright 2015 The go-ethereum Authors
+// This file is part of go-ethereum.
+//
+// go-ethereum is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// go-ethereum is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+
package utils
import (
@@ -9,6 +25,7 @@ import (
"os"
"path/filepath"
"runtime"
+ "strconv"
"github.com/ethereum/go-ethereum/metrics"
@@ -82,11 +99,6 @@ var (
Usage: "Data directory to be used",
Value: DirectoryString{common.DefaultDataDir()},
}
- ProtocolVersionFlag = cli.IntFlag{
- Name: "protocolversion",
- Usage: "ETH protocol version (integer)",
- Value: eth.ProtocolVersion,
- }
NetworkIdFlag = cli.IntFlag{
Name: "networkid",
Usage: "Network Id (integer)",
@@ -127,8 +139,8 @@ var (
}
EtherbaseFlag = cli.StringFlag{
Name: "etherbase",
- Usage: "Public address for block mining rewards. By default the address of your primary account is used",
- Value: "primary",
+ Usage: "Public address for block mining rewards. By default the address first created is used",
+ Value: "0",
}
GasPriceFlag = cli.StringFlag{
Name: "gasprice",
@@ -138,7 +150,7 @@ var (
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
- Usage: "Unlock the account given until this program exits (prompts for password). '--unlock primary' unlocks the primary account",
+ Usage: "Unlock the account given until this program exits (prompts for password). '--unlock n' unlocks the n-th account in order or creation.",
Value: "",
}
PasswordFileFlag = cli.StringFlag{
@@ -356,10 +368,15 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
if len(customName) > 0 {
clientID += "/" + customName
}
+ am := MakeAccountManager(ctx)
+ etherbase, err := ParamToAddress(ctx.GlobalString(EtherbaseFlag.Name), am)
+ if err != nil {
+ glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
+ }
+
return &eth.Config{
Name: common.MakeName(clientID, version),
DataDir: ctx.GlobalString(DataDirFlag.Name),
- ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name),
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
SkipBcVersionCheck: false,
@@ -367,9 +384,9 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
LogFile: ctx.GlobalString(LogFileFlag.Name),
Verbosity: ctx.GlobalInt(VerbosityFlag.Name),
LogJSON: ctx.GlobalString(LogJSONFlag.Name),
- Etherbase: ctx.GlobalString(EtherbaseFlag.Name),
+ Etherbase: common.HexToAddress(etherbase),
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
- AccountManager: MakeAccountManager(ctx),
+ AccountManager: am,
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
@@ -418,7 +435,7 @@ func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, ex
eventMux := new(event.TypeMux)
pow := ethash.New()
genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
- chain, err = core.NewChainManager(genesis, blockDB, stateDB, pow, eventMux)
+ chain, err = core.NewChainManager(genesis, blockDB, stateDB, extraDB, pow, eventMux)
if err != nil {
Fatalf("Could not start chainmanager: %v", err)
}
@@ -438,17 +455,17 @@ func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
func IpcSocketPath(ctx *cli.Context) (ipcpath string) {
if common.IsWindows() {
ipcpath = common.DefaultIpcPath()
- if ipcpath != ctx.GlobalString(IPCPathFlag.Name) {
+ if ctx.GlobalIsSet(IPCPathFlag.Name) {
ipcpath = ctx.GlobalString(IPCPathFlag.Name)
}
} else {
ipcpath = common.DefaultIpcPath()
- if ctx.GlobalString(IPCPathFlag.Name) != common.DefaultIpcPath() {
- ipcpath = ctx.GlobalString(IPCPathFlag.Name)
- } else if ctx.GlobalString(DataDirFlag.Name) != "" &&
- ctx.GlobalString(DataDirFlag.Name) != common.DefaultDataDir() {
+ if ctx.GlobalIsSet(DataDirFlag.Name) {
ipcpath = filepath.Join(ctx.GlobalString(DataDirFlag.Name), "geth.ipc")
}
+ if ctx.GlobalIsSet(IPCPathFlag.Name) {
+ ipcpath = ctx.GlobalString(IPCPathFlag.Name)
+ }
}
return
@@ -494,3 +511,20 @@ func StartPProf(ctx *cli.Context) {
log.Println(http.ListenAndServe(address, nil))
}()
}
+
+func ParamToAddress(addr string, am *accounts.Manager) (addrHex string, err error) {
+ if !((len(addr) == 40) || (len(addr) == 42)) { // with or without 0x
+ index, err := strconv.Atoi(addr)
+ if err != nil {
+ Fatalf("Invalid account address '%s'", addr)
+ }
+
+ addrHex, err = am.AddressByIndex(index)
+ if err != nil {
+ return "", err
+ }
+ } else {
+ addrHex = addr
+ }
+ return
+}