-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
78 lines (63 loc) · 1.52 KB
/
Copy pathmain.go
File metadata and controls
78 lines (63 loc) · 1.52 KB
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
package main
import (
"flag"
"fmt"
"runtime"
"time"
"github.com/eosforce/goforceio/ecc"
"github.com/eosforce/goforceio/p2p"
"github.com/codexnetwork/trunk/cfg"
"github.com/codexnetwork/trunk/logger"
"github.com/codexnetwork/trunk/relay"
"github.com/codexnetwork/trunk/side"
)
var configPath = flag.String("cfg", "./config.json", "config file path")
var isDebug = flag.Bool("d", false, "run in debug mode")
func init() {
ecc.PublicKeyPrefixCompat = "CDX"
}
func main() {
flag.Parse()
logger.EnableLogging(*isDebug)
if *isDebug {
p2p.EnableP2PLogging()
}
defer func() {
err := logger.Logger().Sync()
if err != nil {
fmt.Printf("logger sync err by %s", err.Error())
}
}()
runtime.GOMAXPROCS(2)
err := cfg.LoadCfgs(*configPath)
if err != nil {
logger.Sugar().Errorf("load cfg err by %s", err.Error())
return
}
sideChainCfg, _ := cfg.GetChainCfg("side")
sideChainTyp := cfg.GetChainTyp("side")
relay.CreateSideClient(sideChainTyp, sideChainCfg)
relayChainCfg, _ := cfg.GetChainCfg("relay")
relayChainTyp := cfg.GetChainTyp("relay")
side.CreateClient(relayChainTyp, relayChainCfg)
go func() {
if len(cfg.GetWatchers()) == 0 {
logger.Sugar().Infof("no need start relay")
return
}
logger.Sugar().Infof("start relay service")
startRelayService()
}()
go func() {
if len(cfg.GetTransfers()) == 0 {
logger.Sugar().Infof("no need start side")
return
}
logger.Sugar().Infof("start side service")
startSideService()
}()
for {
time.Sleep(1 * time.Second)
// TODO check status
}
}