aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/geth')
-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
6 files changed, 54 insertions, 74 deletions
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
}
}