forked from ventuary-lab/anti-validators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (65 loc) · 1.71 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
package main
import (
"anti-validators/cacher"
"anti-validators/config"
"anti-validators/models"
"anti-validators/server"
"anti-validators/signer"
"context"
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
const (
defaultConfigFileName = "config.json"
)
func openDb(dbName string) *gorm.DB {
db, err := gorm.Open("sqlite3", dbName)
if err != nil {
fmt.Println(err.Error())
panic("failed to connect database")
}
db.AutoMigrate(&models.Request{})
db.AutoMigrate(&models.Signs{})
return db
}
func main() {
ctx := context.Background()
var confFileName string
flag.StringVar(&confFileName, "config", defaultConfigFileName, "set host")
flag.Parse()
cfg, err := config.Load(confFileName)
if err != nil {
panic(err)
}
cfg.Ethereum.OracleAddress = strings.ToLower(cfg.Ethereum.OracleAddress)
db := openDb(cfg.Db)
defer db.Close()
//---------
go server.StartServer(cfg.Host, cfg.Waves.OracleAddress, cfg.Ethereum.OracleAddress, db)
if err := cacher.StartEthCacher(cfg.Ethereum.ContractAddress, cfg.Ethereum.NodeURL, int64(cfg.RqTimeout), int64(cfg.Ethereum.BlockInterval), ctx, db); err != nil {
panic(err)
}
cacher.StartWavesCacher(cfg.Waves.ContractAddress, cfg.Waves.NodeURL, cfg.RqTimeout, cfg.Waves.BlockInterval, ctx, db)
if err := signer.StartSigner(cfg, cfg.Ethereum.OracleAddress, cfg.Waves.OracleAddress, ctx, db); err != nil {
panic(err)
}
//---------
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
fmt.Println()
fmt.Println(sig)
done <- true
}()
fmt.Println("Started...")
<-done
fmt.Println("Stopped...")
}