forked from sammy007/open-ethereum-pool
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
84 lines (71 loc) · 1.63 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// +build go1.9
package main
import (
"encoding/json"
"log"
"math/rand"
"os"
"path/filepath"
"runtime"
"time"
"github.com/jkkgbe/open-zcash-pool/api"
"github.com/jkkgbe/open-zcash-pool/payouts"
"github.com/jkkgbe/open-zcash-pool/proxy"
"github.com/jkkgbe/open-zcash-pool/storage"
)
var cfg proxy.Config
var backend *storage.RedisClient
func startProxy() {
proxy.NewProxy(&cfg, backend)
}
func startApi() {
s := api.NewApiServer(&cfg.Api, backend)
s.Start()
}
func startBlockUnlocker() {
u := payouts.NewBlockUnlocker(&cfg.BlockUnlocker, backend)
u.Start()
}
func readConfig(cfg *proxy.Config) {
configFileName := "config.json"
if len(os.Args) > 1 {
configFileName = os.Args[1]
}
configFileName, _ = filepath.Abs(configFileName)
log.Printf("Loading config: %v", configFileName)
configFile, err := os.Open(configFileName)
if err != nil {
log.Fatal("File error: ", err.Error())
}
defer configFile.Close()
jsonParser := json.NewDecoder(configFile)
if err := jsonParser.Decode(&cfg); err != nil {
log.Fatal("Config error: ", err.Error())
}
}
func main() {
readConfig(&cfg)
rand.Seed(time.Now().UnixNano())
if cfg.Threads > 0 {
runtime.GOMAXPROCS(cfg.Threads)
log.Printf("Running with %v threads", cfg.Threads)
}
backend = storage.NewRedisClient(&cfg.Redis, cfg.Coin)
pong, err := backend.Check()
if err != nil {
log.Printf("Can't establish connection to backend: %v", err)
} else {
log.Printf("Backend check reply: %v", pong)
}
if cfg.Proxy.Enabled {
go startProxy()
}
if cfg.Api.Enabled {
go startApi()
}
if cfg.BlockUnlocker.Enabled {
go startBlockUnlocker()
}
quit := make(chan bool)
<-quit
}