diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-20 23:09:26 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-20 23:09:26 +0800 |
commit | c07c454935609bfb0f65dc38bb596a90d5493fbb (patch) | |
tree | b8d4ffc72b06bcd60d6f61de70bea8b680ed8333 /ethereum/ethereum.go | |
parent | 942f552c620471602326c1ded54095c1cf41ed76 (diff) | |
parent | 34014c1c516ea03b28e56db1a0478087d2416f74 (diff) | |
download | go-tangerine-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar go-tangerine-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.gz go-tangerine-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.bz2 go-tangerine-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.lz go-tangerine-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.xz go-tangerine-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.zst go-tangerine-c07c454935609bfb0f65dc38bb596a90d5493fbb.zip |
Merge branch 'release/poc5-rc7'poc5-rc7
Diffstat (limited to 'ethereum/ethereum.go')
-rw-r--r-- | ethereum/ethereum.go | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go index 2abf6da42..2fdfd5caf 100644 --- a/ethereum/ethereum.go +++ b/ethereum/ethereum.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" + "io/ioutil" "log" "os" "os/signal" @@ -15,16 +16,15 @@ import ( const Debug = true -// Register interrupt handlers so we can stop the ethereum -func RegisterInterrupts(s *eth.Ethereum) { - // Buffered chan of one is enough - c := make(chan os.Signal, 1) - // Notify about interrupts for now - signal.Notify(c, os.Interrupt) +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 { - fmt.Printf("Shutting down (%v) ... \n", sig) - s.Stop() + cb(sig) } }() } @@ -52,7 +52,12 @@ func main() { var logSys *log.Logger flags := log.LstdFlags - ethutil.ReadConfig(DataDir) + if StartJsConsole || len(InputFile) > 0 { + ethutil.ReadConfig(DataDir, ethutil.LogFile) + } else { + ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd) + } + logger := ethutil.Config.Log if LogFile != "" { @@ -136,21 +141,40 @@ save these words so you can restore your account later: %s utils.DoMining(ethereum) } - if StartConsole { - err := os.Mkdir(ethutil.Config.ExecPath, os.ModePerm) - // Error is OK if the error is ErrExist - if err != nil && !os.IsExist(err) { - log.Panic("Unable to create EXECPATH:", err) + 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) } - console := NewConsole(ethereum) - go console.Start() + 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) } - RegisterInterrupts(ethereum) + RegisterInterrupt(func(sig os.Signal) { + fmt.Printf("Shutting down (%v) ... \n", sig) + ethereum.Stop() + }) ethereum.Start(UseSeed) |