aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bootnode/main.go21
-rw-r--r--cmd/geth/accountcmd.go46
-rw-r--r--cmd/geth/chaincmd.go34
-rw-r--r--cmd/geth/consolecmd.go16
-rw-r--r--cmd/geth/main.go8
-rw-r--r--cmd/geth/misccmd.go5
-rw-r--r--cmd/geth/monitorcmd.go19
-rw-r--r--cmd/swarm/main.go18
-rw-r--r--cmd/utils/cmd.go2
-rw-r--r--cmd/utils/flags.go41
-rw-r--r--cmd/wnode/main.go36
11 files changed, 113 insertions, 133 deletions
diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go
index 31b2726be..c3fc163a1 100644
--- a/cmd/bootnode/main.go
+++ b/cmd/bootnode/main.go
@@ -23,6 +23,7 @@ import (
"fmt"
"os"
+ "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover"
@@ -56,28 +57,28 @@ func main() {
natm, err := nat.Parse(*natdesc)
if err != nil {
- log.Crit("Failed to parse requested NAT", "error", err)
+ utils.Fatalf("-nat: %v", err)
}
switch {
case *genKey != "":
nodeKey, err = crypto.GenerateKey()
if err != nil {
- log.Crit("Failed to generate new key", "error", err)
+ utils.Fatalf("could not generate key: %v", err)
}
if err = crypto.SaveECDSA(*genKey, nodeKey); err != nil {
- log.Crit("Failed to save generated key", "error", err)
+ utils.Fatalf("%v", err)
}
case *nodeKeyFile == "" && *nodeKeyHex == "":
- log.Crit("Use -nodekey or -nodekeyhex to load a private key")
+ utils.Fatalf("Use -nodekey or -nodekeyhex to specify a private key")
case *nodeKeyFile != "" && *nodeKeyHex != "":
- log.Crit("Options -nodekey and -nodekeyhex are mutually exclusive")
+ utils.Fatalf("Options -nodekey and -nodekeyhex are mutually exclusive")
case *nodeKeyFile != "":
if nodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil {
- log.Crit("Failed to loading the key file", "path", *nodeKeyFile, "error", err)
+ utils.Fatalf("-nodekey: %v", err)
}
case *nodeKeyHex != "":
if nodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil {
- log.Crit("Failed to parse the key hex", "hex", *nodeKeyHex, "error", err)
+ utils.Fatalf("-nodekeyhex: %v", err)
}
}
@@ -90,17 +91,17 @@ func main() {
if *netrestrict != "" {
restrictList, err = netutil.ParseNetlist(*netrestrict)
if err != nil {
- log.Crit("Failed to parse the network restrictions", "error", err)
+ utils.Fatalf("-netrestrict: %v", err)
}
}
if *runv5 {
if _, err := discv5.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil {
- log.Crit("Failed to start the v5 discovery protocol", "error", err)
+ utils.Fatalf("%v", err)
}
} else {
if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, "", restrictList); err != nil {
- log.Crit("Failed to start the discovery protocol", "error", err)
+ utils.Fatalf("%v", err)
}
}
diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go
index 0b0be7938..f86be62ba 100644
--- a/cmd/geth/accountcmd.go
+++ b/cmd/geth/accountcmd.go
@@ -19,7 +19,6 @@ package main
import (
"fmt"
"io/ioutil"
- "os"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
@@ -196,8 +195,7 @@ func accountList(ctx *cli.Context) error {
func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i int, passwords []string) (accounts.Account, string) {
account, err := utils.MakeAddress(ks, address)
if err != nil {
- fmt.Printf("Fatal: Could not list accounts: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Could not list accounts: %v", err)
}
for trials := 0; trials < 3; trials++ {
prompt := fmt.Sprintf("Unlocking account %s | Attempt %d/%d", address, trials+1, 3)
@@ -217,8 +215,7 @@ func unlockAccount(ctx *cli.Context, ks *keystore.KeyStore, address string, i in
}
}
// All trials expended to unlock account, bail out
- fmt.Printf("Fatal: Failed to unlock account %s (%v)\n", address, err)
- os.Exit(1)
+ utils.Fatalf("Failed to unlock account %s (%v)", address, err)
return accounts.Account{}, ""
}
@@ -239,18 +236,15 @@ func getPassPhrase(prompt string, confirmation bool, i int, passwords []string)
}
password, err := console.Stdin.PromptPassword("Passphrase: ")
if err != nil {
- fmt.Printf("Fatal: Failed to read passphrase: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Failed to read passphrase: %v", err)
}
if confirmation {
confirm, err := console.Stdin.PromptPassword("Repeat passphrase: ")
if err != nil {
- fmt.Printf("Fatal: Failed to read passphrase confirmation: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Failed to read passphrase confirmation: %v", err)
}
if password != confirm {
- fmt.Printf("Fatal: Passphrases do not match\n")
- os.Exit(1)
+ utils.Fatalf("Passphrases do not match")
}
}
return password
@@ -270,8 +264,7 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
}
}
if match == nil {
- fmt.Printf("Fatal: None of the listed files could be unlocked.\n")
- os.Exit(1)
+ utils.Fatalf("None of the listed files could be unlocked.")
}
fmt.Printf("Your passphrase unlocked %s\n", match.URL)
fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
@@ -291,8 +284,7 @@ func accountCreate(ctx *cli.Context) error {
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
account, err := ks.NewAccount(password)
if err != nil {
- fmt.Printf("Fatal: Failed to create account: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Failed to create account: %v", err)
}
fmt.Printf("Address: {%x}\n", account.Address)
return nil
@@ -302,8 +294,7 @@ func accountCreate(ctx *cli.Context) error {
// one, also providing the possibility to change the pass-phrase.
func accountUpdate(ctx *cli.Context) error {
if len(ctx.Args()) == 0 {
- fmt.Printf("Fatal: No accounts specified to update\n")
- os.Exit(1)
+ utils.Fatalf("No accounts specified to update")
}
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
@@ -311,8 +302,7 @@ func accountUpdate(ctx *cli.Context) error {
account, oldPassword := unlockAccount(ctx, ks, ctx.Args().First(), 0, nil)
newPassword := getPassPhrase("Please give a new password. Do not forget this password.", true, 0, nil)
if err := ks.Update(account, oldPassword, newPassword); err != nil {
- fmt.Printf("Fatal: Could not update the account: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Could not update the account: %v", err)
}
return nil
}
@@ -320,13 +310,11 @@ func accountUpdate(ctx *cli.Context) error {
func importWallet(ctx *cli.Context) error {
keyfile := ctx.Args().First()
if len(keyfile) == 0 {
- fmt.Printf("Fatal: keyfile must be given as argument\n")
- os.Exit(1)
+ utils.Fatalf("keyfile must be given as argument")
}
keyJson, err := ioutil.ReadFile(keyfile)
if err != nil {
- fmt.Printf("Fatal: Could not read wallet file: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Could not read wallet file: %v", err)
}
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
@@ -335,8 +323,7 @@ func importWallet(ctx *cli.Context) error {
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
acct, err := ks.ImportPreSaleKey(keyJson, passphrase)
if err != nil {
- fmt.Printf("Fatal: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("%v", err)
}
fmt.Printf("Address: {%x}\n", acct.Address)
return nil
@@ -345,13 +332,11 @@ func importWallet(ctx *cli.Context) error {
func accountImport(ctx *cli.Context) error {
keyfile := ctx.Args().First()
if len(keyfile) == 0 {
- fmt.Printf("Fatal: keyfile must be given as argument\n")
- os.Exit(1)
+ utils.Fatalf("keyfile must be given as argument")
}
key, err := crypto.LoadECDSA(keyfile)
if err != nil {
- fmt.Printf("Fatal: Failed to load the private key: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Failed to load the private key: %v", err)
}
stack := utils.MakeNode(ctx, clientIdentifier, gitCommit)
passphrase := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
@@ -359,8 +344,7 @@ func accountImport(ctx *cli.Context) error {
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
acct, err := ks.ImportECDSA(key, passphrase)
if err != nil {
- fmt.Printf("Fatal: Could not create the account: %v\n", err)
- os.Exit(1)
+ utils.Fatalf("Could not create the account: %v", err)
}
fmt.Printf("Address: {%x}\n", acct.Address)
return nil
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go
index 1127a1090..74950697c 100644
--- a/cmd/geth/chaincmd.go
+++ b/cmd/geth/chaincmd.go
@@ -112,7 +112,7 @@ Use "ethereum dump 0" to dump the genesis block.
func initGenesis(ctx *cli.Context) error {
genesisPath := ctx.Args().First()
if len(genesisPath) == 0 {
- log.Crit(fmt.Sprintf("must supply path to genesis JSON file"))
+ utils.Fatalf("must supply path to genesis JSON file")
}
stack := makeFullNode(ctx)
@@ -120,13 +120,13 @@ func initGenesis(ctx *cli.Context) error {
genesisFile, err := os.Open(genesisPath)
if err != nil {
- log.Crit(fmt.Sprintf("failed to read genesis file: %v", err))
+ utils.Fatalf("failed to read genesis file: %v", err)
}
defer genesisFile.Close()
block, err := core.WriteGenesisBlock(chaindb, genesisFile)
if err != nil {
- log.Crit(fmt.Sprintf("failed to write genesis block: %v", err))
+ utils.Fatalf("failed to write genesis block: %v", err)
}
log.Info(fmt.Sprintf("successfully wrote genesis block and/or chain rule set: %x", block.Hash()))
return nil
@@ -134,7 +134,7 @@ func initGenesis(ctx *cli.Context) error {
func importChain(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
- log.Crit(fmt.Sprintf("This command requires an argument."))
+ utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
chain, chainDb := utils.MakeChain(ctx, stack)
@@ -158,7 +158,7 @@ func importChain(ctx *cli.Context) error {
// Import the chain
start := time.Now()
if err := utils.ImportChain(chain, ctx.Args().First()); err != nil {
- log.Crit(fmt.Sprintf("Import error: %v", err))
+ utils.Fatalf("Import error: %v", err)
}
fmt.Printf("Import done in %v.\n\n", time.Since(start))
@@ -167,7 +167,7 @@ func importChain(ctx *cli.Context) error {
stats, err := db.LDB().GetProperty("leveldb.stats")
if err != nil {
- log.Crit(fmt.Sprintf("Failed to read database stats: %v", err))
+ utils.Fatalf("Failed to read database stats: %v", err)
}
fmt.Println(stats)
fmt.Printf("Trie cache misses: %d\n", trie.CacheMisses())
@@ -186,13 +186,13 @@ func importChain(ctx *cli.Context) error {
start = time.Now()
fmt.Println("Compacting entire database...")
if err = db.LDB().CompactRange(util.Range{}); err != nil {
- log.Crit(fmt.Sprintf("Compaction failed: %v", err))
+ utils.Fatalf("Compaction failed: %v", err)
}
fmt.Printf("Compaction done in %v.\n\n", time.Since(start))
stats, err = db.LDB().GetProperty("leveldb.stats")
if err != nil {
- log.Crit(fmt.Sprintf("Failed to read database stats: %v", err))
+ utils.Fatalf("Failed to read database stats: %v", err)
}
fmt.Println(stats)
@@ -201,7 +201,7 @@ func importChain(ctx *cli.Context) error {
func exportChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
- log.Crit(fmt.Sprintf("This command requires an argument."))
+ utils.Fatalf("This command requires an argument.")
}
stack := makeFullNode(ctx)
chain, _ := utils.MakeChain(ctx, stack)
@@ -216,16 +216,16 @@ func exportChain(ctx *cli.Context) error {
first, ferr := strconv.ParseInt(ctx.Args().Get(1), 10, 64)
last, lerr := strconv.ParseInt(ctx.Args().Get(2), 10, 64)
if ferr != nil || lerr != nil {
- log.Crit(fmt.Sprintf("Export error in parsing parameters: block number not an integer\n"))
+ utils.Fatalf("Export error in parsing parameters: block number not an integer\n")
}
if first < 0 || last < 0 {
- log.Crit(fmt.Sprintf("Export error: block number must be greater than 0\n"))
+ utils.Fatalf("Export error: block number must be greater than 0\n")
}
err = utils.ExportAppendChain(chain, fp, uint64(first), uint64(last))
}
if err != nil {
- log.Crit(fmt.Sprintf("Export error: %v\n", err))
+ utils.Fatalf("Export error: %v\n", err)
}
fmt.Printf("Export done in %v", time.Since(start))
return nil
@@ -243,7 +243,7 @@ func removeDB(ctx *cli.Context) error {
confirm, err := console.Stdin.PromptConfirm("Remove this database?")
switch {
case err != nil:
- log.Crit(fmt.Sprintf("%v", err))
+ utils.Fatalf("%v", err)
case !confirm:
fmt.Println("Operation aborted")
default:
@@ -269,7 +269,7 @@ func upgradeDB(ctx *cli.Context) error {
filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("20060102_150405"))
exportFile := filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename)
if err := utils.ExportChain(chain, exportFile); err != nil {
- log.Crit(fmt.Sprintf("Unable to export chain for reimport %s", err))
+ utils.Fatalf("Unable to export chain for reimport %s", err)
}
chainDb.Close()
if dir := dbDirectory(chainDb); dir != "" {
@@ -282,7 +282,7 @@ func upgradeDB(ctx *cli.Context) error {
err := utils.ImportChain(chain, exportFile)
chainDb.Close()
if err != nil {
- log.Crit(fmt.Sprintf("Import error %v (a backup is made in %s, use the import command to import it)", err, exportFile))
+ utils.Fatalf("Import error %v (a backup is made in %s, use the import command to import it)", err, exportFile)
} else {
os.Remove(exportFile)
log.Info(fmt.Sprint("Import finished"))
@@ -311,11 +311,11 @@ func dump(ctx *cli.Context) error {
}
if block == nil {
fmt.Println("{}")
- log.Crit(fmt.Sprintf("block not found"))
+ utils.Fatalf("block not found")
} else {
state, err := state.New(block.Root(), chainDb)
if err != nil {
- log.Crit(fmt.Sprintf("could not create new state: %v", err))
+ utils.Fatalf("could not create new state: %v", err)
}
fmt.Printf("%s\n", state.Dump())
}
diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go
index 4009e3e33..b1c435e00 100644
--- a/cmd/geth/consolecmd.go
+++ b/cmd/geth/consolecmd.go
@@ -17,14 +17,12 @@
package main
import (
- "fmt"
"os"
"os/signal"
"strings"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/console"
- "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc"
"gopkg.in/urfave/cli.v1"
@@ -80,7 +78,7 @@ func localConsole(ctx *cli.Context) error {
// Attach to the newly started node and start the JavaScript console
client, err := node.Attach()
if err != nil {
- log.Crit(fmt.Sprintf("Failed to attach to the inproc geth: %v", err))
+ utils.Fatalf("Failed to attach to the inproc geth: %v", err)
}
config := console.Config{
DataDir: node.DataDir(),
@@ -90,7 +88,7 @@ func localConsole(ctx *cli.Context) error {
}
console, err := console.New(config)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to start the JavaScript console: %v", err))
+ utils.Fatalf("Failed to start the JavaScript console: %v", err)
}
defer console.Stop(false)
@@ -112,7 +110,7 @@ func remoteConsole(ctx *cli.Context) error {
// Attach to a remotely running geth instance and start the JavaScript console
client, err := dialRPC(ctx.Args().First())
if err != nil {
- log.Crit(fmt.Sprintf("Unable to attach to remote geth: %v", err))
+ utils.Fatalf("Unable to attach to remote geth: %v", err)
}
config := console.Config{
DataDir: utils.MakeDataDir(ctx),
@@ -122,7 +120,7 @@ func remoteConsole(ctx *cli.Context) error {
}
console, err := console.New(config)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to start the JavaScript console: %v", err))
+ utils.Fatalf("Failed to start the JavaScript console: %v", err)
}
defer console.Stop(false)
@@ -164,7 +162,7 @@ func ephemeralConsole(ctx *cli.Context) error {
// Attach to the newly started node and start the JavaScript console
client, err := node.Attach()
if err != nil {
- log.Crit(fmt.Sprintf("Failed to attach to the inproc geth: %v", err))
+ utils.Fatalf("Failed to attach to the inproc geth: %v", err)
}
config := console.Config{
DataDir: node.DataDir(),
@@ -174,14 +172,14 @@ func ephemeralConsole(ctx *cli.Context) error {
}
console, err := console.New(config)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to start the JavaScript console: %v", err))
+ utils.Fatalf("Failed to start the JavaScript console: %v", err)
}
defer console.Stop(false)
// Evaluate each of the specified JavaScript files
for _, file := range ctx.Args() {
if err = console.Execute(file); err != nil {
- log.Crit(fmt.Sprintf("Failed to execute %s: %v", file, err))
+ utils.Fatalf("Failed to execute %s: %v", file, err)
}
}
// Wait for pending callbacks, but stop for Ctrl-C.
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 2bebccac7..803a618f1 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -235,7 +235,7 @@ func makeFullNode(ctx *cli.Context) *node.Node {
copy(config.Commit[:], commit)
return release.NewReleaseService(ctx, config)
}); err != nil {
- log.Crit(fmt.Sprintf("Failed to register the Geth release oracle service: %v", err))
+ utils.Fatalf("Failed to register the Geth release oracle service: %v", err)
}
return stack
}
@@ -265,7 +265,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
// Create an chain state reader for self-derivation
rpcClient, err := stack.Attach()
if err != nil {
- log.Crit(fmt.Sprintf("Failed to attach to self: %v", err))
+ utils.Fatalf("Failed to attach to self: %v", err)
}
stateReader := ethclient.NewClient(rpcClient)
@@ -296,10 +296,10 @@ func startNode(ctx *cli.Context, stack *node.Node) {
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
var ethereum *eth.Ethereum
if err := stack.Service(&ethereum); err != nil {
- log.Crit(fmt.Sprintf("ethereum service not running: %v", err))
+ utils.Fatalf("ethereum service not running: %v", err)
}
if err := ethereum.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name)); err != nil {
- log.Crit(fmt.Sprintf("Failed to start mining: %v", err))
+ utils.Fatalf("Failed to start mining: %v", err)
}
}
}
diff --git a/cmd/geth/misccmd.go b/cmd/geth/misccmd.go
index 9cb161e1a..077f1ad11 100644
--- a/cmd/geth/misccmd.go
+++ b/cmd/geth/misccmd.go
@@ -28,7 +28,6 @@ import (
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"gopkg.in/urfave/cli.v1"
)
@@ -69,7 +68,7 @@ The output of this command is supposed to be machine-readable.
func makedag(ctx *cli.Context) error {
args := ctx.Args()
wrongArgs := func() {
- log.Crit(fmt.Sprintf(`Usage: geth makedag <block number> <outputdir>`))
+ utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
}
switch {
case len(args) == 2:
@@ -85,7 +84,7 @@ func makedag(ctx *cli.Context) error {
}
_, err = ioutil.ReadDir(dir)
if err != nil {
- log.Crit(fmt.Sprintf("Can't find dir"))
+ utils.Fatalf("Can't find dir")
}
fmt.Println("making DAG, this could take awhile...")
ethash.MakeDAG(blockNum, dir)
diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go
index 129a80181..c63542f13 100644
--- a/cmd/geth/monitorcmd.go
+++ b/cmd/geth/monitorcmd.go
@@ -26,7 +26,6 @@ import (
"time"
"github.com/ethereum/go-ethereum/cmd/utils"
- "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc"
"github.com/gizak/termui"
@@ -77,14 +76,14 @@ func monitor(ctx *cli.Context) error {
// Attach to an Ethereum node over IPC or RPC
endpoint := ctx.String(monitorCommandAttachFlag.Name)
if client, err = dialRPC(endpoint); err != nil {
- log.Crit(fmt.Sprintf("Unable to attach to geth node: %v", err))
+ utils.Fatalf("Unable to attach to geth node: %v", err)
}
defer client.Close()
// Retrieve all the available metrics and resolve the user pattens
metrics, err := retrieveMetrics(client)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to retrieve system metrics: %v", err))
+ utils.Fatalf("Failed to retrieve system metrics: %v", err)
}
monitored := resolveMetrics(metrics, ctx.Args())
if len(monitored) == 0 {
@@ -92,18 +91,18 @@ func monitor(ctx *cli.Context) error {
sort.Strings(list)
if len(list) > 0 {
- log.Crit(fmt.Sprintf("No metrics specified.\n\nAvailable:\n - %s", strings.Join(list, "\n - ")))
+ utils.Fatalf("No metrics specified.\n\nAvailable:\n - %s", strings.Join(list, "\n - "))
} else {
- log.Crit(fmt.Sprintf("No metrics collected by geth (--%s).\n", utils.MetricsEnabledFlag.Name))
+ utils.Fatalf("No metrics collected by geth (--%s).\n", utils.MetricsEnabledFlag.Name)
}
}
sort.Strings(monitored)
if cols := len(monitored) / ctx.Int(monitorCommandRowsFlag.Name); cols > 6 {
- log.Crit(fmt.Sprintf("Requested metrics (%d) spans more that 6 columns:\n - %s", len(monitored), strings.Join(monitored, "\n - ")))
+ utils.Fatalf("Requested metrics (%d) spans more that 6 columns:\n - %s", len(monitored), strings.Join(monitored, "\n - "))
}
// Create and configure the chart UI defaults
if err := termui.Init(); err != nil {
- log.Crit(fmt.Sprintf("Unable to initialize terminal UI: %v", err))
+ utils.Fatalf("Unable to initialize terminal UI: %v", err)
}
defer termui.Close()
@@ -187,7 +186,7 @@ func resolveMetric(metrics map[string]interface{}, pattern string, path string)
if len(parts) > 1 {
for _, variation := range strings.Split(parts[0], ",") {
if submetrics, ok := metrics[variation].(map[string]interface{}); !ok {
- log.Crit(fmt.Sprintf("Failed to retrieve system metrics: %s", path+variation))
+ utils.Fatalf("Failed to retrieve system metrics: %s", path+variation)
return nil
} else {
results = append(results, resolveMetric(submetrics, parts[1], path+variation+"/")...)
@@ -206,7 +205,7 @@ func resolveMetric(metrics map[string]interface{}, pattern string, path string)
results = append(results, expandMetrics(metric, path+variation+"/")...)
default:
- log.Crit(fmt.Sprintf("Metric pattern resolved to unexpected type: %v", reflect.TypeOf(metric)))
+ utils.Fatalf("Metric pattern resolved to unexpected type: %v", reflect.TypeOf(metric))
return nil
}
}
@@ -228,7 +227,7 @@ func expandMetrics(metrics map[string]interface{}, path string) []string {
list = append(list, expandMetrics(metric, path+name+"/")...)
default:
- log.Crit(fmt.Sprintf("Metric pattern %s resolved to unexpected type: %v", path+name, reflect.TypeOf(metric)))
+ utils.Fatalf("Metric pattern %s resolved to unexpected type: %v", path+name, reflect.TypeOf(metric))
return nil
}
}
diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go
index 84af69d7a..12cad328f 100644
--- a/cmd/swarm/main.go
+++ b/cmd/swarm/main.go
@@ -307,7 +307,7 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
bzzconfig, err := bzzapi.NewConfig(bzzdir, chbookaddr, prvkey, ctx.GlobalUint64(SwarmNetworkIdFlag.Name))
if err != nil {
- log.Crit(fmt.Sprintf("unable to configure swarm: %v", err))
+ utils.Fatalf("unable to configure swarm: %v", err)
}
bzzport := ctx.GlobalString(SwarmPortFlag.Name)
if len(bzzport) > 0 {
@@ -324,13 +324,13 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
if len(ethapi) > 0 {
client, err = ethclient.Dial(ethapi)
if err != nil {
- log.Crit(fmt.Sprintf("Can't connect: %v", err))
+ utils.Fatalf("Can't connect: %v", err)
}
}
return swarm.NewSwarm(ctx, client, bzzconfig, swapEnabled, syncEnabled, cors)
}
if err := stack.Register(boot); err != nil {
- log.Crit(fmt.Sprintf("Failed to register the Swarm service: %v", err))
+ utils.Fatalf("Failed to register the Swarm service: %v", err)
}
}
@@ -338,7 +338,7 @@ func getAccount(ctx *cli.Context, stack *node.Node) *ecdsa.PrivateKey {
keyid := ctx.GlobalString(SwarmAccountFlag.Name)
if keyid == "" {
- log.Crit(fmt.Sprintf("Option %q is required", SwarmAccountFlag.Name))
+ utils.Fatalf("Option %q is required", SwarmAccountFlag.Name)
}
// Try to load the arg as a hex key file.
if key, err := crypto.LoadECDSA(keyid); err == nil {
@@ -364,14 +364,14 @@ func decryptStoreAccount(ks *keystore.KeyStore, account string) *ecdsa.PrivateKe
err = fmt.Errorf("index %d higher than number of accounts %d", ix, len(accounts))
}
} else {
- log.Crit(fmt.Sprintf("Can't find swarm account key %s", account))
+ utils.Fatalf("Can't find swarm account key %s", account)
}
if err != nil {
- log.Crit(fmt.Sprintf("Can't find swarm account key: %v", err))
+ utils.Fatalf("Can't find swarm account key: %v", err)
}
keyjson, err := ioutil.ReadFile(a.URL.Path)
if err != nil {
- log.Crit(fmt.Sprintf("Can't load swarm account key: %v", err))
+ utils.Fatalf("Can't load swarm account key: %v", err)
}
for i := 1; i <= 3; i++ {
passphrase := promptPassphrase(fmt.Sprintf("Unlocking swarm account %s [%d/3]", a.Address.Hex(), i))
@@ -380,7 +380,7 @@ func decryptStoreAccount(ks *keystore.KeyStore, account string) *ecdsa.PrivateKe
return key.PrivateKey
}
}
- log.Crit(fmt.Sprintf("Can't decrypt swarm account key"))
+ utils.Fatalf("Can't decrypt swarm account key")
return nil
}
@@ -390,7 +390,7 @@ func promptPassphrase(prompt string) string {
}
password, err := console.Stdin.PromptPassword("Passphrase: ")
if err != nil {
- log.Crit(fmt.Sprintf("Failed to read passphrase: %v", err))
+ utils.Fatalf("Failed to read passphrase: %v", err)
}
return password
}
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 5baa44980..062b9c50d 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -62,7 +62,7 @@ func Fatalf(format string, args ...interface{}) {
func StartNode(stack *node.Node) {
if err := stack.Start(); err != nil {
- log.Crit(fmt.Sprintf("Error starting protocol stack: %v", err))
+ Fatalf("Error starting protocol stack: %v", err)
}
go func() {
sigc := make(chan os.Signal, 1)
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 55713c15c..a2e4ac814 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -425,7 +425,7 @@ func MakeDataDir(ctx *cli.Context) string {
}
return path
}
- log.Crit(fmt.Sprintf("Cannot determine default data directory, please set manually (--datadir)"))
+ Fatalf("Cannot determine default data directory, please set manually (--datadir)")
return ""
}
@@ -451,16 +451,16 @@ func MakeNodeKey(ctx *cli.Context) *ecdsa.PrivateKey {
)
switch {
case file != "" && hex != "":
- log.Crit(fmt.Sprintf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name))
+ Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name)
case file != "":
if key, err = crypto.LoadECDSA(file); err != nil {
- log.Crit(fmt.Sprintf("Option %q: %v", NodeKeyFileFlag.Name, err))
+ Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err)
}
case hex != "":
if key, err = crypto.HexToECDSA(hex); err != nil {
- log.Crit(fmt.Sprintf("Option %q: %v", NodeKeyHexFlag.Name, err))
+ Fatalf("Option %q: %v", NodeKeyHexFlag.Name, err)
}
}
return key
@@ -536,7 +536,7 @@ func MakeDiscoveryV5Address(ctx *cli.Context) string {
func MakeNAT(ctx *cli.Context) nat.Interface {
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
if err != nil {
- log.Crit(fmt.Sprintf("Option %s: %v", NATFlag.Name, err))
+ Fatalf("Option %s: %v", NATFlag.Name, err)
}
return natif
}
@@ -573,11 +573,11 @@ func MakeWSRpcHost(ctx *cli.Context) string {
// for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles() int {
if err := raiseFdLimit(2048); err != nil {
- log.Crit(fmt.Sprintf("Failed to raise file descriptor allowance: %v", err))
+ Fatalf("Failed to raise file descriptor allowance: %v", err)
}
limit, err := getFdLimit()
if err != nil {
- log.Crit(fmt.Sprintf("Failed to retrieve file descriptor allowance: %v", err))
+ Fatalf("Failed to retrieve file descriptor allowance: %v", err)
}
if limit > 2048 { // cap database file descriptors even if more is available
limit = 2048
@@ -619,7 +619,7 @@ func MakeEtherbase(ks *keystore.KeyStore, ctx *cli.Context) common.Address {
// If the specified etherbase is a valid address, return it
account, err := MakeAddress(ks, etherbase)
if err != nil {
- log.Crit(fmt.Sprintf("Option %q: %v", EtherbaseFlag.Name, err))
+ Fatalf("Option %q: %v", EtherbaseFlag.Name, err)
}
return account.Address
}
@@ -641,7 +641,7 @@ func MakePasswordList(ctx *cli.Context) []string {
}
text, err := ioutil.ReadFile(path)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to read password file: %v", err))
+ Fatalf("Failed to read password file: %v", err)
}
lines := strings.Split(string(text), "\n")
// Sanitise DOS line endings.
@@ -700,14 +700,14 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
if netrestrict := ctx.GlobalString(NetrestrictFlag.Name); netrestrict != "" {
list, err := netutil.ParseNetlist(netrestrict)
if err != nil {
- log.Crit(fmt.Sprintf("Option %q: %v", NetrestrictFlag.Name, err))
+ Fatalf("Option %q: %v", NetrestrictFlag.Name, err)
}
config.NetRestrict = list
}
stack, err := node.New(config)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to create the protocol stack: %v", err))
+ Fatalf("Failed to create the protocol stack: %v", err)
}
return stack
}
@@ -723,7 +723,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
}
}
if networks > 1 {
- log.Crit(fmt.Sprintf("The %v flags are mutually exclusive", netFlags))
+ Fatalf("The %v flags are mutually exclusive", netFlags)
}
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
@@ -777,7 +777,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return les.New(ctx, ethConf)
}); err != nil {
- log.Crit(fmt.Sprintf("Failed to register the Ethereum light node service: %v", err))
+ Fatalf("Failed to register the Ethereum light node service: %v", err)
}
} else {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
@@ -788,7 +788,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
}
return fullNode, err
}); err != nil {
- log.Crit(fmt.Sprintf("Failed to register the Ethereum full node service: %v", err))
+ Fatalf("Failed to register the Ethereum full node service: %v", err)
}
}
}
@@ -796,7 +796,7 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
// RegisterShhService configures Whisper and adds it to the given node.
func RegisterShhService(stack *node.Node) {
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil {
- log.Crit(fmt.Sprintf("Failed to register the Whisper service: %v", err))
+ Fatalf("Failed to register the Whisper service: %v", err)
}
}
@@ -813,7 +813,7 @@ func RegisterEthStatsService(stack *node.Node, url string) {
return ethstats.New(url, ethServ, lesServ)
}); err != nil {
- log.Crit(fmt.Sprintf("Failed to register the Ethereum Stats service: %v", err))
+ Fatalf("Failed to register the Ethereum Stats service: %v", err)
}
}
@@ -844,7 +844,7 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *params.ChainCon
case core.ChainConfigNotFoundErr:
// No configs found, use empty, will populate below
default:
- log.Crit(fmt.Sprintf("Could not make chain configuration: %v", err))
+ Fatalf("Could not make chain configuration: %v", err)
}
}
// set chain id in case it's zero.
@@ -899,7 +899,7 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database {
chainDb, err := stack.OpenDatabase(name, cache, handles)
if err != nil {
- log.Crit(fmt.Sprintf("Could not open database: %v", err))
+ Fatalf("Could not open database: %v", err)
}
return chainDb
}
@@ -912,10 +912,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
if ctx.GlobalBool(TestNetFlag.Name) {
_, err := core.WriteTestNetGenesisBlock(chainDb)
if err != nil {
- log.Crit(fmt.Sprint(err))
+ Fatalf("Failed to write testnet genesis: %v", err)
}
}
-
chainConfig := MakeChainConfigFromDb(ctx, chainDb)
pow := pow.PoW(core.FakePow{})
@@ -924,7 +923,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
}
chain, err = core.NewBlockChain(chainDb, chainConfig, pow, new(event.TypeMux), vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)})
if err != nil {
- log.Crit(fmt.Sprintf("Could not start chainmanager: %v", err))
+ Fatalf("Could not start chainmanager: %v", err)
}
return chain, chainDb
}
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
index eb0dd2511..8191f9292 100644
--- a/cmd/wnode/main.go
+++ b/cmd/wnode/main.go
@@ -108,7 +108,7 @@ func processArgs() {
var err error
nodeid, err = crypto.LoadECDSA(*argIDFile)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to load file [%s]: %s.", *argIDFile, err))
+ utils.Fatalf("Failed to load file [%s]: %s.", *argIDFile, err)
}
}
@@ -122,7 +122,7 @@ func processArgs() {
if len(*argTopic) > 0 {
x, err := hex.DecodeString(*argTopic)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to parse the topic: %s", err))
+ utils.Fatalf("Failed to parse the topic: %s", err)
}
topic = whisper.BytesToTopic(x)
}
@@ -130,7 +130,7 @@ func processArgs() {
if *asymmetricMode && len(*argPub) > 0 {
pub = crypto.ToECDSAPub(common.FromHex(*argPub))
if !isKeyValid(pub) {
- log.Crit(fmt.Sprintf("invalid public key"))
+ utils.Fatalf("invalid public key")
}
}
@@ -161,7 +161,7 @@ func initialize() {
if *generateKey {
key, err := crypto.GenerateKey()
if err != nil {
- log.Crit(fmt.Sprintf("Failed to generate private key: %s", err))
+ utils.Fatalf("Failed to generate private key: %s", err)
}
k := hex.EncodeToString(crypto.FromECDSA(key))
fmt.Printf("Random private key: %s \n", k)
@@ -189,7 +189,7 @@ func initialize() {
if len(msPassword) == 0 {
msPassword, err = console.Stdin.PromptPassword("Please enter the Mail Server password: ")
if err != nil {
- log.Crit(fmt.Sprintf("Failed to read Mail Server password: %s", err))
+ utils.Fatalf("Failed to read Mail Server password: %s", err)
}
}
shh = whisper.New()
@@ -227,7 +227,7 @@ func initialize() {
func startServer() {
err := server.Start()
if err != nil {
- log.Crit(fmt.Sprintf("Failed to start Whisper peer: %s.", err))
+ utils.Fatalf("Failed to start Whisper peer: %s.", err)
}
fmt.Printf("my public key: %s \n", common.ToHex(crypto.FromECDSAPub(&asymKey.PublicKey)))
@@ -265,7 +265,7 @@ func configureNode() {
s := scanLine("Please enter the peer's public key: ")
pub = crypto.ToECDSAPub(common.FromHex(s))
if !isKeyValid(pub) {
- log.Crit(fmt.Sprintf("Error: invalid public key"))
+ utils.Fatalf("Error: invalid public key")
}
}
}
@@ -275,7 +275,7 @@ func configureNode() {
if len(msPassword) == 0 {
msPassword, err = console.Stdin.PromptPassword("Please enter the Mail Server password: ")
if err != nil {
- log.Crit(fmt.Sprintf("Failed to read Mail Server password: %s", err))
+ utils.Fatalf("Failed to read Mail Server password: %s", err)
}
}
}
@@ -284,7 +284,7 @@ func configureNode() {
if len(symPass) == 0 {
symPass, err = console.Stdin.PromptPassword("Please enter the password: ")
if err != nil {
- log.Crit(fmt.Sprintf("Failed to read passphrase: %v", err))
+ utils.Fatalf("Failed to read passphrase: %v", err)
}
}
@@ -330,7 +330,7 @@ func waitForConnection(timeout bool) {
if timeout {
cnt++
if cnt > 1000 {
- log.Crit(fmt.Sprintf("Timeout expired, failed to connect"))
+ utils.Fatalf("Timeout expired, failed to connect")
}
}
}
@@ -382,7 +382,7 @@ func scanLine(prompt string) string {
}
txt, err := input.ReadString('\n')
if err != nil {
- log.Crit(fmt.Sprintf("input error: %s", err))
+ utils.Fatalf("input error: %s", err)
}
txt = strings.TrimRight(txt, "\n\r")
return txt
@@ -397,7 +397,7 @@ func scanUint(prompt string) uint32 {
s := scanLine(prompt)
i, err := strconv.Atoi(s)
if err != nil {
- log.Crit(fmt.Sprintf("Fail to parse the lower time limit: %s", err))
+ utils.Fatalf("Fail to parse the lower time limit: %s", err)
}
return uint32(i)
}
@@ -430,7 +430,7 @@ func sendMsg(payload []byte) {
func messageLoop() {
f := shh.GetFilter(filterID)
if f == nil {
- log.Crit(fmt.Sprintf("filter is not installed"))
+ utils.Fatalf("filter is not installed")
}
ticker := time.NewTicker(time.Millisecond * 50)
@@ -472,7 +472,7 @@ func requestExpiredMessagesLoop() {
err := shh.AddSymKey(mailserver.MailServerKeyName, []byte(msPassword))
if err != nil {
- log.Crit(fmt.Sprintf("Failed to create symmetric key for mail request: %s", err))
+ utils.Fatalf("Failed to create symmetric key for mail request: %s", err)
}
key = shh.GetSymKey(mailserver.MailServerKeyName)
peerID = extractIdFromEnode(*argEnode)
@@ -485,7 +485,7 @@ func requestExpiredMessagesLoop() {
if len(t) >= whisper.TopicLength*2 {
x, err := hex.DecodeString(t)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to parse the topic: %s", err))
+ utils.Fatalf("Failed to parse the topic: %s", err)
}
xt = whisper.BytesToTopic(x)
}
@@ -511,12 +511,12 @@ func requestExpiredMessagesLoop() {
msg := whisper.NewSentMessage(&params)
env, err := msg.Wrap(&params)
if err != nil {
- log.Crit(fmt.Sprintf("Wrap failed: %s", err))
+ utils.Fatalf("Wrap failed: %s", err)
}
err = shh.RequestHistoricMessages(peerID, env)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to send P2P message: %s", err))
+ utils.Fatalf("Failed to send P2P message: %s", err)
}
time.Sleep(time.Second * 5)
@@ -526,7 +526,7 @@ func requestExpiredMessagesLoop() {
func extractIdFromEnode(s string) []byte {
n, err := discover.ParseNode(s)
if err != nil {
- log.Crit(fmt.Sprintf("Failed to parse enode: %s", err))
+ utils.Fatalf("Failed to parse enode: %s", err)
return nil
}
return n.ID[:]