From f90001e938ce34457cc0ed5822c8e7dff52ec58c Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 11:38:14 +0100 Subject: add logging start/exit to js console --- ethereum/repl.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ethereum') diff --git a/ethereum/repl.go b/ethereum/repl.go index 0208459ad..a95d73300 100644 --- a/ethereum/repl.go +++ b/ethereum/repl.go @@ -23,11 +23,13 @@ func NewJSRepl(ethereum *eth.Ethereum) *JSRepl { } func (self *JSRepl) Start() { + logger.Infoln("init JS Console") self.read() } func (self *JSRepl) Stop() { self.re.Stop() + logger.Infoln("exit JS Console") } func (self *JSRepl) parseInput(code string) { -- cgit v1.2.3 From 7bcf875c577cd9710d27dd4511ae21aa62067d79 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 11:39:09 +0100 Subject: add logging for jsre --- ethereum/javascript_runtime.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ethereum') diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go index b05d39232..34b805e7f 100644 --- a/ethereum/javascript_runtime.go +++ b/ethereum/javascript_runtime.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/otto" "io/ioutil" @@ -14,6 +15,8 @@ import ( "path/filepath" ) +var jsrelogger = ethlog.NewLogger("JSRE") + type JSRE struct { ethereum *eth.Ethereum vm *otto.Otto @@ -31,7 +34,7 @@ func (jsre *JSRE) LoadExtFile(path string) { if err == nil { jsre.vm.Run(result) } else { - ethutil.Config.Log.Debugln("Could not load file:", path) + jsrelogger.Debugln("Could not load file:", path) } } @@ -65,6 +68,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { re.initStdFuncs() + jsrelogger.Infoln("started") + return re } @@ -99,6 +104,7 @@ func (self *JSRE) Stop() { close(self.blockChan) close(self.quitChan) close(self.changeChan) + jsrelogger.Infoln("stopped") } func (self *JSRE) mainLoop() { -- cgit v1.2.3 From 1024766514eea7bb628ec6e5ed974e997b8faefc Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 12:20:59 +0100 Subject: refactor cli and gui wrapper code. Details: - all cli functions shared between ethereum and ethereal abstracted to utils/ cmd.go (should be ethcommon or shared or sth) - simplify main() now readable stepwise - rename main wrapper files to main.go - rename commmand line args definition file from config.go to flags.go - rename Do -> Start to parallel option names - register interrupt for rpc server stop - fix interrupt stopping js repl and ethereum - register interrupt for mining stop - custom config file option from command line - debug option from command line - loglevel option from command line - changed ethutil.Config API - default datadir and default config file set together with other flag defaults in wrappers - default assetpath set together with other command line flags defaults in gui wrapper (not in ethutil.Config or ui/ui_lib) - options precedence: default < config file < environment variables < command line --- ethereum/cmd.go | 33 +++++++++ ethereum/config.go | 56 --------------- ethereum/ethereum.go | 193 --------------------------------------------------- ethereum/flags.go | 72 +++++++++++++++++++ ethereum/main.go | 47 +++++++++++++ 5 files changed, 152 insertions(+), 249 deletions(-) create mode 100644 ethereum/cmd.go delete mode 100644 ethereum/config.go delete mode 100644 ethereum/ethereum.go create mode 100644 ethereum/flags.go create mode 100644 ethereum/main.go (limited to 'ethereum') diff --git a/ethereum/cmd.go b/ethereum/cmd.go new file mode 100644 index 000000000..0e9c2be8c --- /dev/null +++ b/ethereum/cmd.go @@ -0,0 +1,33 @@ +package main + +import ( + "github.com/ethereum/eth-go" + "github.com/ethereum/go-ethereum/utils" + "os" + "io/ioutil" +) + +func InitJsConsole(ethereum *eth.Ethereum) { + repl := NewJSRepl(ethereum) + go repl.Start() + utils.RegisterInterrupt(func(os.Signal) { + repl.Stop() + ethereum.Stop() + }) +} + +func ExecJsFile (ethereum *eth.Ethereum, InputFile string) { + file, err := os.Open(InputFile) + if err != nil { + logger.Fatalln(err) + } + content, err := ioutil.ReadAll(file) + if err != nil { + logger.Fatalln(err) + } + re := NewJSRE(ethereum) + utils.RegisterInterrupt(func(os.Signal) { + re.Stop() + }) + re.Run(string(content)) +} diff --git a/ethereum/config.go b/ethereum/config.go deleted file mode 100644 index a80b47a8e..000000000 --- a/ethereum/config.go +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" -) - -var Identifier string -var StartMining bool -var StartRpc bool -var RpcPort int -var UseUPnP bool -var OutboundPort string -var ShowGenesis bool -var AddPeer string -var MaxPeer int -var GenAddr bool -var UseSeed bool -var ImportKey string -var ExportKey bool -var LogFile string -var NonInteractive bool -var StartJsConsole bool -var InputFile string - -var Datadir string - -func Init() { - flag.Usage = func() { - fmt.Fprintf(os.Stderr, "%s [options] [filename]:\n", os.Args[0]) - flag.PrintDefaults() - } - - flag.StringVar(&Identifier, "id", "", "Custom client identifier") - flag.StringVar(&OutboundPort, "port", "30303", "listening port") - flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") - flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") - flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") - flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") - flag.BoolVar(&StartJsConsole, "js", false, "exp") - - flag.BoolVar(&StartMining, "mine", false, "start dagger mining") - flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") - flag.BoolVar(&UseSeed, "seed", true, "seed peers") - flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") - flag.BoolVar(&ExportKey, "export", false, "export private key") - flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)") - flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") - - flag.StringVar(&Datadir, "datadir", ".ethereum", "specifies the datadir to use. Takes precedence over config file.") - - flag.Parse() - - InputFile = flag.Arg(0) -} diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go deleted file mode 100644 index 8812e0a60..000000000 --- a/ethereum/ethereum.go +++ /dev/null @@ -1,193 +0,0 @@ -package main - -import ( - "fmt" - "github.com/ethereum/eth-go" - "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/go-ethereum/utils" - "github.com/rakyll/globalconf" - "io/ioutil" - "log" - "os" - "os/signal" - "path" - "runtime" - "strings" -) - -const Debug = true - -func RegisterInterrupt(cb func(os.Signal)) { - go func() { - // Buffered chan of one is enough - c := make(chan os.Signal, 1) - // Notify about interrupts for now - signal.Notify(c, os.Interrupt) - - for sig := range c { - cb(sig) - } - }() -} - -func confirm(message string) bool { - fmt.Println(message, "Are you sure? (y/n)") - var r string - fmt.Scanln(&r) - for ; ; fmt.Scanln(&r) { - if r == "n" || r == "y" { - break - } else { - fmt.Printf("Yes or no?", r) - } - } - return r == "y" -} - -func main() { - Init() - - runtime.GOMAXPROCS(runtime.NumCPU()) - - // set logger - var logSys *log.Logger - flags := log.LstdFlags - - var lt ethutil.LoggerType - if StartJsConsole || len(InputFile) > 0 { - lt = ethutil.LogFile - } else { - lt = ethutil.LogFile | ethutil.LogStd - } - - g, err := globalconf.NewWithOptions(&globalconf.Options{ - Filename: path.Join(ethutil.ApplicationFolder(Datadir), "conf.ini"), - }) - if err != nil { - fmt.Println(err) - } else { - g.ParseAll() - } - ethutil.ReadConfig(Datadir, lt, g, Identifier) - - logger := ethutil.Config.Log - - if LogFile != "" { - logfile, err := os.OpenFile(LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) - if err != nil { - panic(fmt.Sprintf("error opening log file '%s': %v", LogFile, err)) - } - defer logfile.Close() - log.SetOutput(logfile) - logSys = log.New(logfile, "", flags) - logger.AddLogSystem(logSys) - } else { - logSys = log.New(os.Stdout, "", flags) - } - - // Instantiated a eth stack - ethereum, err := eth.New(eth.CapDefault, UseUPnP) - if err != nil { - log.Println("eth start err:", err) - return - } - ethereum.Port = OutboundPort - - // bookkeeping tasks - switch { - case GenAddr: - if NonInteractive || confirm("This action overwrites your old private key.") { - utils.CreateKeyPair(true) - } - os.Exit(0) - case len(ImportKey) > 0: - if NonInteractive || confirm("This action overwrites your old private key.") { - mnemonic := strings.Split(ImportKey, " ") - if len(mnemonic) == 24 { - logSys.Println("Got mnemonic key, importing.") - key := ethutil.MnemonicDecode(mnemonic) - utils.ImportPrivateKey(key) - } else if len(mnemonic) == 1 { - logSys.Println("Got hex key, importing.") - utils.ImportPrivateKey(ImportKey) - } else { - logSys.Println("Did not recognise format, exiting.") - } - } - os.Exit(0) - case ExportKey: - keyPair := ethutil.GetKeyRing().Get(0) - fmt.Printf(` -Generating new address and keypair. -Please keep your keys somewhere save. - -++++++++++++++++ KeyRing +++++++++++++++++++ -addr: %x -prvk: %x -pubk: %x -++++++++++++++++++++++++++++++++++++++++++++ -save these words so you can restore your account later: %s -`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey) - - os.Exit(0) - case ShowGenesis: - logSys.Println(ethereum.BlockChain().Genesis()) - os.Exit(0) - default: - // Creates a keypair if non exists - utils.CreateKeyPair(false) - } - - // client - logger.Infoln(fmt.Sprintf("Starting Ethereum v%s", ethutil.Config.Ver)) - - // Set the max peers - ethereum.MaxPeers = MaxPeer - - // Set Mining status - ethereum.Mining = StartMining - - if StartMining { - utils.DoMining(ethereum) - } - - if StartJsConsole { - repl := NewJSRepl(ethereum) - - go repl.Start() - - RegisterInterrupt(func(os.Signal) { - repl.Stop() - }) - } else if len(InputFile) > 0 { - file, err := os.Open(InputFile) - if err != nil { - ethutil.Config.Log.Fatal(err) - } - - content, err := ioutil.ReadAll(file) - if err != nil { - ethutil.Config.Log.Fatal(err) - } - - re := NewJSRE(ethereum) - RegisterInterrupt(func(os.Signal) { - re.Stop() - }) - re.Run(string(content)) - } - - if StartRpc { - utils.DoRpc(ethereum, RpcPort) - } - - RegisterInterrupt(func(sig os.Signal) { - fmt.Printf("Shutting down (%v) ... \n", sig) - ethereum.Stop() - }) - - ethereum.Start(UseSeed) - - // Wait for shutdown - ethereum.WaitForShutdown() -} diff --git a/ethereum/flags.go b/ethereum/flags.go new file mode 100644 index 000000000..513d93a6d --- /dev/null +++ b/ethereum/flags.go @@ -0,0 +1,72 @@ +package main + +import ( + "flag" + "fmt" + "os" + "os/user" + "path" + "github.com/ethereum/eth-go/ethlog" +) + +var Identifier string +var StartRpc bool +var RpcPort int +var UseUPnP bool +var OutboundPort string +var ShowGenesis bool +var AddPeer string +var MaxPeer int +var GenAddr bool +var UseSeed bool +var ImportKey string +var ExportKey bool +var NonInteractive bool +var Datadir string +var LogFile string +var ConfigFile string +var DebugFile string +var LogLevel int + +// flags specific to cli client +var StartMining bool +var StartJsConsole bool +var InputFile string + +func defaultDataDir() string { + usr, _ := user.Current() + return path.Join(usr.HomeDir, ".ethereum") +} + +var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") + +func Init() { + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line", os.Args[0]) + flag.PrintDefaults() + } + + flag.StringVar(&Identifier, "id", "", "Custom client identifier") + flag.StringVar(&OutboundPort, "port", "30303", "listening port") + flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") + flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") + flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") + flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") + flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") + flag.BoolVar(&UseSeed, "seed", true, "seed peers") + flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") + flag.BoolVar(&ExportKey, "export", false, "export private key") + flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)") + flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") + flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use") + flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") + flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") + flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-4: silent,error,warn,info,debug)") + + flag.BoolVar(&StartMining, "mine", false, "start dagger mining") + flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console") + + flag.Parse() + + InputFile = flag.Arg(0) +} diff --git a/ethereum/main.go b/ethereum/main.go new file mode 100644 index 000000000..bbbaf5541 --- /dev/null +++ b/ethereum/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "github.com/ethereum/go-ethereum/utils" + "github.com/ethereum/eth-go/ethlog" + "runtime" +) + +var logger = ethlog.NewLogger("CLI") + +func main() { + runtime.GOMAXPROCS(runtime.NumCPU()) + + // precedence: code-internal flag default < config file < environment variables < command line + Init() // parsing command line + utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH") + + utils.InitDataDir(Datadir) + + utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile) + + ethereum := utils.NewEthereum(UseUPnP, OutboundPort, MaxPeer) + + // create, import, export keys + utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive) + + if ShowGenesis { + utils.ShowGenesis(ethereum) + } + + if StartMining { + utils.StartMining(ethereum) + } + + // better reworked as cases + if StartJsConsole { + InitJsConsole(ethereum) + } else if len(InputFile) > 0 { + ExecJsFile(ethereum, InputFile) + } + + if StartRpc { + utils.StartRpc(ethereum, RpcPort) + } + + utils.StartEthereum(ethereum, UseSeed) +} -- cgit v1.2.3 From 8ee1abecb971e39ad5e0ed5b199ff4bf553ca67a Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 16:54:29 +0100 Subject: update log levels to include DebugDetail; correct default datadir for ethereal --- ethereum/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereum') diff --git a/ethereum/flags.go b/ethereum/flags.go index 513d93a6d..99aa9b250 100644 --- a/ethereum/flags.go +++ b/ethereum/flags.go @@ -61,7 +61,7 @@ func Init() { flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use") flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") - flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-4: silent,error,warn,info,debug)") + flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)") flag.BoolVar(&StartMining, "mine", false, "start dagger mining") flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console") -- cgit v1.2.3 From bf57e9603b9ef2c96e8e6d7c3d22ea674392d56b Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 18:09:42 +0100 Subject: add newline to help usage msg --- ethereum/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereum') diff --git a/ethereum/flags.go b/ethereum/flags.go index 99aa9b250..232a2bc92 100644 --- a/ethereum/flags.go +++ b/ethereum/flags.go @@ -42,7 +42,7 @@ var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") func Init() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line", os.Args[0]) + fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0]) flag.PrintDefaults() } -- cgit v1.2.3 From 6763d28a170b4e91c78532feed68805fe88c41dd Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 18:18:22 +0100 Subject: repl.Stop() to only if running, fixes panic after js> exit followed by interrupt --- ethereum/repl.go | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'ethereum') diff --git a/ethereum/repl.go b/ethereum/repl.go index c162c78b0..34380a06f 100644 --- a/ethereum/repl.go +++ b/ethereum/repl.go @@ -23,6 +23,8 @@ type JSRepl struct { prompt string history *os.File + + running bool } func NewJSRepl(ethereum *eth.Ethereum) *JSRepl { @@ -35,26 +37,32 @@ func NewJSRepl(ethereum *eth.Ethereum) *JSRepl { } func (self *JSRepl) Start() { - logger.Infoln("init JS Console") - reader := bufio.NewReader(self.history) - for { - line, err := reader.ReadString('\n') - if err != nil && err == io.EOF { - break - } else if err != nil { - fmt.Println("error reading history", err) - break + if !self.running { + self.running = true + logger.Infoln("init JS Console") + reader := bufio.NewReader(self.history) + for { + line, err := reader.ReadString('\n') + if err != nil && err == io.EOF { + break + } else if err != nil { + fmt.Println("error reading history", err) + break + } + + addHistory(line[:len(line)-1]) } - - addHistory(line[:len(line)-1]) + self.read() } - self.read() } func (self *JSRepl) Stop() { - self.re.Stop() - logger.Infoln("exit JS Console") - self.history.Close() + if self.running { + self.running = false + self.re.Stop() + logger.Infoln("exit JS Console") + self.history.Close() + } } func (self *JSRepl) parseInput(code string) { -- cgit v1.2.3 From 2f96652bb408e65c205317403d749ba9a395c6bb Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 10:47:45 +0100 Subject: interrupt handlers now ordered --- ethereum/cmd.go | 1 - ethereum/main.go | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'ethereum') diff --git a/ethereum/cmd.go b/ethereum/cmd.go index 0e9c2be8c..2dfd54666 100644 --- a/ethereum/cmd.go +++ b/ethereum/cmd.go @@ -12,7 +12,6 @@ func InitJsConsole(ethereum *eth.Ethereum) { go repl.Start() utils.RegisterInterrupt(func(os.Signal) { repl.Stop() - ethereum.Stop() }) } diff --git a/ethereum/main.go b/ethereum/main.go index bbbaf5541..800486e56 100644 --- a/ethereum/main.go +++ b/ethereum/main.go @@ -11,6 +11,8 @@ var logger = ethlog.NewLogger("CLI") func main() { runtime.GOMAXPROCS(runtime.NumCPU()) + utils.HandleInterrupt() + // precedence: code-internal flag default < config file < environment variables < command line Init() // parsing command line utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH") -- cgit v1.2.3 From 21d86ca486a88c936a1fe71f78d76c78df36a7eb Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 16:26:14 +0100 Subject: gui stop - introduce gui.Stop() - remember state with open - stopping ethereum stack is not gui concern, moved to main - stopping mining, gui and ethereum handled via interrupt callbacks - ^C triggers exactly the same behaviour as quit via menu --- ethereum/main.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ethereum') diff --git a/ethereum/main.go b/ethereum/main.go index 800486e56..93b2b47d3 100644 --- a/ethereum/main.go +++ b/ethereum/main.go @@ -46,4 +46,8 @@ func main() { } utils.StartEthereum(ethereum, UseSeed) + + // this blocks the thread + ethereum.WaitForShutdown() + ethlog.Flush() } -- cgit v1.2.3 From ae5ace16190d48bfe7a0364fdb0b51644518ec42 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 18:41:36 +0100 Subject: go fmt --- ethereum/cmd.go | 46 +++++++++++++++++++++--------------------- ethereum/flags.go | 10 ++++----- ethereum/javascript_runtime.go | 4 ++-- ethereum/main.go | 14 ++++++------- 4 files changed, 37 insertions(+), 37 deletions(-) (limited to 'ethereum') diff --git a/ethereum/cmd.go b/ethereum/cmd.go index 2dfd54666..08147824d 100644 --- a/ethereum/cmd.go +++ b/ethereum/cmd.go @@ -1,32 +1,32 @@ package main import ( - "github.com/ethereum/eth-go" - "github.com/ethereum/go-ethereum/utils" - "os" - "io/ioutil" + "github.com/ethereum/eth-go" + "github.com/ethereum/go-ethereum/utils" + "io/ioutil" + "os" ) func InitJsConsole(ethereum *eth.Ethereum) { - repl := NewJSRepl(ethereum) - go repl.Start() - utils.RegisterInterrupt(func(os.Signal) { - repl.Stop() - }) + repl := NewJSRepl(ethereum) + go repl.Start() + utils.RegisterInterrupt(func(os.Signal) { + repl.Stop() + }) } -func ExecJsFile (ethereum *eth.Ethereum, InputFile string) { - file, err := os.Open(InputFile) - if err != nil { - logger.Fatalln(err) - } - content, err := ioutil.ReadAll(file) - if err != nil { - logger.Fatalln(err) - } - re := NewJSRE(ethereum) - utils.RegisterInterrupt(func(os.Signal) { - re.Stop() - }) - re.Run(string(content)) +func ExecJsFile(ethereum *eth.Ethereum, InputFile string) { + file, err := os.Open(InputFile) + if err != nil { + logger.Fatalln(err) + } + content, err := ioutil.ReadAll(file) + if err != nil { + logger.Fatalln(err) + } + re := NewJSRE(ethereum) + utils.RegisterInterrupt(func(os.Signal) { + re.Stop() + }) + re.Run(string(content)) } diff --git a/ethereum/flags.go b/ethereum/flags.go index 232a2bc92..8fb87cf34 100644 --- a/ethereum/flags.go +++ b/ethereum/flags.go @@ -3,10 +3,10 @@ package main import ( "flag" "fmt" + "github.com/ethereum/eth-go/ethlog" "os" - "os/user" - "path" - "github.com/ethereum/eth-go/ethlog" + "os/user" + "path" ) var Identifier string @@ -34,8 +34,8 @@ var StartJsConsole bool var InputFile string func defaultDataDir() string { - usr, _ := user.Current() - return path.Join(usr.HomeDir, ".ethereum") + usr, _ := user.Current() + return path.Join(usr.HomeDir, ".ethereum") } var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini") diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go index 0a9a882ad..0dfe07a54 100644 --- a/ethereum/javascript_runtime.go +++ b/ethereum/javascript_runtime.go @@ -1,12 +1,12 @@ - package main +package main import ( "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/otto" "io/ioutil" diff --git a/ethereum/main.go b/ethereum/main.go index 93b2b47d3..6b1995eec 100644 --- a/ethereum/main.go +++ b/ethereum/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/ethereum/go-ethereum/utils" "github.com/ethereum/eth-go/ethlog" + "github.com/ethereum/go-ethereum/utils" "runtime" ) @@ -24,11 +24,11 @@ func main() { ethereum := utils.NewEthereum(UseUPnP, OutboundPort, MaxPeer) // create, import, export keys - utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive) + utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive) - if ShowGenesis { - utils.ShowGenesis(ethereum) - } + if ShowGenesis { + utils.ShowGenesis(ethereum) + } if StartMining { utils.StartMining(ethereum) @@ -48,6 +48,6 @@ func main() { utils.StartEthereum(ethereum, UseSeed) // this blocks the thread - ethereum.WaitForShutdown() - ethlog.Flush() + ethereum.WaitForShutdown() + ethlog.Flush() } -- cgit v1.2.3