-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
85 lines (69 loc) · 1.73 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
85
package main
import (
"anti-validators/cacher"
"anti-validators/config"
"anti-validators/db/models"
"anti-validators/server"
"anti-validators/signer"
"context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
const (
defaultConfigFileName = "config.json"
defaultHost = "127.0.0.1:8080"
)
func openDb() *gorm.DB {
db, err := gorm.Open("sqlite3", "anti.db")
if err != nil {
fmt.Println(err.Error())
panic("failed to connect database")
}
db.AutoMigrate(&models.Request{})
db.AutoMigrate(&models.Signs{})
return db
}
func main() {
db := openDb()
defer db.Close()
ctx := context.Background()
var host, confFileName, oracleAddress string
flag.StringVar(&confFileName, "config", defaultConfigFileName, "set host")
flag.StringVar(&oracleAddress, "oracleAddress", "", "set oracle address")
flag.StringVar(&host, "host", defaultHost, "set host")
flag.Parse()
cfg, err := config.Load(confFileName)
if err != nil {
panic(err)
}
//---------
go server.StartServer(host, oracleAddress, db)
if err := cacher.StartEthCacher(cfg.Ethereum.ContractAddress, cfg.Ethereum.NodeURL, ctx, db); err != nil {
panic(err)
}
cacher.StartWavesCacher(cfg.Waves.ContractAddress, cfg.Waves.NodeURL, ctx, db)
if err := signer.StartWavesSigner(cfg, oracleAddress, ctx, db); err != nil {
panic(err)
}
if err := signer.StartEthSigner(cfg, 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...")
}