diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/bootnode/main.go | 46 | ||||
-rw-r--r-- | cmd/geth/js.go | 16 | ||||
-rw-r--r-- | cmd/geth/main.go | 22 |
3 files changed, 44 insertions, 40 deletions
diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index 7f74e9c70..7d3f9fdb3 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -19,15 +19,12 @@ package main import ( "crypto/ecdsa" - "encoding/hex" "flag" - "fmt" - "io/ioutil" - "log" "os" + "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/nat" ) @@ -43,50 +40,43 @@ func main() { nodeKey *ecdsa.PrivateKey err error ) + flag.Var(glog.GetVerbosity(), "verbosity", "log verbosity (0-9)") + flag.Var(glog.GetVModule(), "vmodule", "log verbosity pattern") + glog.SetToStderr(true) flag.Parse() - logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.DebugLevel)) if *genKey != "" { - writeKey(*genKey) + key, err := crypto.GenerateKey() + if err != nil { + utils.Fatalf("could not generate key: %v", err) + } + if err := crypto.SaveECDSA(*genKey, key); err != nil { + utils.Fatalf("%v", err) + } os.Exit(0) } natm, err := nat.Parse(*natdesc) if err != nil { - log.Fatalf("-nat: %v", err) + utils.Fatalf("-nat: %v", err) } switch { case *nodeKeyFile == "" && *nodeKeyHex == "": - log.Fatal("Use -nodekey or -nodekeyhex to specify a private key") + utils.Fatalf("Use -nodekey or -nodekeyhex to specify a private key") case *nodeKeyFile != "" && *nodeKeyHex != "": - log.Fatal("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.Fatalf("-nodekey: %v", err) + utils.Fatalf("-nodekey: %v", err) } case *nodeKeyHex != "": if nodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil { - log.Fatalf("-nodekeyhex: %v", err) + utils.Fatalf("-nodekeyhex: %v", err) } } if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil { - log.Fatal(err) + utils.Fatalf("%v", err) } select {} } - -func writeKey(target string) { - key, err := crypto.GenerateKey() - if err != nil { - log.Fatalf("could not generate key: %v", err) - } - b := crypto.FromECDSA(key) - if target == "-" { - fmt.Println(hex.EncodeToString(b)) - } else { - if err := ioutil.WriteFile(target, b, 0600); err != nil { - log.Fatal("write error: ", err) - } - } -} diff --git a/cmd/geth/js.go b/cmd/geth/js.go index 767b513c1..2b64303b2 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -123,7 +123,7 @@ func (self *jsre) batch(statement string) { err := self.re.EvalAndPrettyPrint(statement) if err != nil { - fmt.Printf("error: %v", err) + fmt.Printf("%v", jsErrorString(err)) } if self.atexit != nil { @@ -301,21 +301,19 @@ func (self *jsre) preloadJSFiles(ctx *cli.Context) error { for _, file := range jsFiles { filename := common.AbsolutePath(assetPath, strings.TrimSpace(file)) if err := self.re.Exec(filename); err != nil { - return fmt.Errorf("%s: %v", file, err) + return fmt.Errorf("%s: %v", file, jsErrorString(err)) } } } return nil } -// exec executes the JS file with the given filename and stops the JSRE -func (self *jsre) exec(filename string) error { - if err := self.re.Exec(filename); err != nil { - self.re.Stop(false) - return fmt.Errorf("Javascript Error: %v", err) +// jsErrorString adds a backtrace to errors generated by otto. +func jsErrorString(err error) string { + if ottoErr, ok := err.(*otto.Error); ok { + return ottoErr.String() } - self.re.Stop(true) - return nil + return err.Error() } func (self *jsre) interactive() { diff --git a/cmd/geth/main.go b/cmd/geth/main.go index c33e04f06..ffeb7c1e5 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "os" + "os/signal" "path/filepath" "runtime" "strconv" @@ -354,7 +355,7 @@ func console(ctx *cli.Context) { // preload user defined JS files into the console err = repl.preloadJSFiles(ctx) if err != nil { - utils.Fatalf("unable to preload JS file %v", err) + utils.Fatalf("%v", err) } // in case the exec flag holds a JS statement execute it and return @@ -373,6 +374,7 @@ func execScripts(ctx *cli.Context) { // Create and start the node based on the CLI flags node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx) startNode(ctx, node) + defer node.Stop() // Attach to the newly started node and execute the given scripts client, err := node.Attach() @@ -384,10 +386,24 @@ func execScripts(ctx *cli.Context) { ctx.GlobalString(utils.RPCCORSDomainFlag.Name), client, false) + // Run all given files. for _, file := range ctx.Args() { - repl.exec(file) + if err = repl.re.Exec(file); err != nil { + break + } } - node.Stop() + if err != nil { + utils.Fatalf("JavaScript Error: %v", jsErrorString(err)) + } + // JS files loaded successfully. + // Wait for pending callbacks, but stop for Ctrl-C. + abort := make(chan os.Signal, 1) + signal.Notify(abort, os.Interrupt) + go func() { + <-abort + repl.re.Stop(false) + }() + repl.re.Stop(true) } // startNode boots up the system node and all registered protocols, after which |