2013-12-26 13:45:52 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2013-12-30 00:53:20 +02:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2014-01-01 14:37:00 +02:00
|
|
|
"flag"
|
2014-01-09 00:43:20 +02:00
|
|
|
"runtime"
|
2014-01-10 01:39:16 +02:00
|
|
|
"log"
|
2014-01-10 23:44:53 +02:00
|
|
|
"github.com/ethereum/ethutil-go"
|
2013-12-26 13:45:52 +02:00
|
|
|
)
|
|
|
|
|
2014-01-01 04:07:49 +02:00
|
|
|
const Debug = true
|
2013-12-28 16:18:23 +02:00
|
|
|
|
2014-01-09 17:19:16 +02:00
|
|
|
var StartConsole bool
|
2014-01-09 00:43:20 +02:00
|
|
|
var StartMining bool
|
2014-01-01 14:37:00 +02:00
|
|
|
func Init() {
|
2014-01-09 17:19:16 +02:00
|
|
|
flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
|
2014-01-10 12:05:28 +02:00
|
|
|
flag.BoolVar(&StartMining, "m", false, "start dagger mining")
|
2014-01-01 14:37:00 +02:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:53:20 +02:00
|
|
|
// Register interrupt handlers so we can stop the server
|
|
|
|
func RegisterInterupts(s *Server) {
|
|
|
|
// Buffered chan of one is enough
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
// Notify about interrupts for now
|
|
|
|
signal.Notify(c, os.Interrupt)
|
|
|
|
go func() {
|
|
|
|
for sig := range c {
|
2014-01-09 00:43:20 +02:00
|
|
|
fmt.Printf("Shutting down (%v) ... \n", sig)
|
2013-12-30 00:53:20 +02:00
|
|
|
|
|
|
|
s.Stop()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2013-12-26 13:45:52 +02:00
|
|
|
func main() {
|
2014-01-09 00:43:20 +02:00
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
|
2014-01-10 23:44:53 +02:00
|
|
|
ethutil.InitFees()
|
2013-12-26 13:45:52 +02:00
|
|
|
|
2014-01-01 14:37:00 +02:00
|
|
|
Init()
|
2013-12-26 13:45:52 +02:00
|
|
|
|
2014-01-09 17:19:16 +02:00
|
|
|
if StartConsole {
|
|
|
|
console := NewConsole()
|
|
|
|
console.Start()
|
2014-01-10 01:39:16 +02:00
|
|
|
} else{
|
|
|
|
log.Println("Starting Ethereum")
|
2014-01-09 00:43:20 +02:00
|
|
|
server, err := NewServer()
|
|
|
|
|
|
|
|
if err != nil {
|
2014-01-10 01:39:16 +02:00
|
|
|
log.Println(err)
|
2014-01-09 00:43:20 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterInterupts(server)
|
|
|
|
|
2014-01-10 01:39:16 +02:00
|
|
|
if StartMining {
|
|
|
|
log.Println("Mining started")
|
|
|
|
dagger := &Dagger{}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
2014-01-10 23:44:53 +02:00
|
|
|
res := dagger.Search(ethutil.Big("0"), ethutil.BigPow(2, 36))
|
2014-01-10 01:44:45 +02:00
|
|
|
server.Broadcast("block", Encode(res.String()))
|
2014-01-10 01:39:16 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2014-01-09 00:43:20 +02:00
|
|
|
server.Start()
|
|
|
|
|
2014-01-10 01:39:16 +02:00
|
|
|
err = server.ConnectToPeer("localhost:12345")
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
server.Stop()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-09 00:43:20 +02:00
|
|
|
// Wait for shutdown
|
|
|
|
server.WaitForShutdown()
|
2014-01-01 14:37:00 +02:00
|
|
|
}
|
2013-12-26 13:45:52 +02:00
|
|
|
}
|