diff options
Diffstat (limited to 'ethereum.go')
-rw-r--r-- | ethereum.go | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/ethereum.go b/ethereum.go index d74cb4ff2..b7f059a02 100644 --- a/ethereum.go +++ b/ethereum.go @@ -7,6 +7,7 @@ import ( "log" "os" "os/signal" + "path" "runtime" ) @@ -44,36 +45,54 @@ func main() { Init() + ethutil.ReadConfig() + + server, err := NewServer() + + if err != nil { + log.Println(err) + return + } + if StartConsole { - console := NewConsole() - console.Start() - } else { - log.Println("Starting Ethereum") - server, err := NewServer() + 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. Exiting") + } + // TODO The logger will eventually be a non blocking logger. Logging is a expensive task + // Log to file only + file, err := os.OpenFile(path.Join(ethutil.Config.ExecPath, "debug.log"), os.O_RDWR|os.O_CREATE, os.ModePerm) if err != nil { - log.Println(err) - return + log.Panic("Unable to set proper logger", err) } - RegisterInterupts(server) + ethutil.Config.Log = log.New(file, "", 0) - if StartMining { - log.Println("Mining started") - dagger := &Dagger{} + console := NewConsole(server) + go console.Start() + } - go func() { - for { - res := dagger.Search(ethutil.Big("01001"), ethutil.BigPow(2, 36)) - log.Println("Res dagger", res) - //server.Broadcast("blockmine", ethutil.Encode(res.String())) - } - }() - } + log.Println("Starting Ethereum") + + RegisterInterupts(server) - server.Start() + if StartMining { + log.Println("Mining started") + dagger := &Dagger{} - // Wait for shutdown - server.WaitForShutdown() + go func() { + for { + res := dagger.Search(ethutil.Big("01001"), ethutil.BigPow(2, 36)) + log.Println("Res dagger", res) + //server.Broadcast("blockmine", ethutil.Encode(res.String())) + } + }() } + + server.Start() + + // Wait for shutdown + server.WaitForShutdown() } |