-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
84 lines (69 loc) · 1.49 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
package main
import (
"context"
"database/sql"
"fmt"
"math/big"
"os"
"os/signal"
"time"
_ "github.com/lib/pq"
)
const (
DBHost = "localhost"
DBPort = 5432
DBUser = "genaro"
DBPassword = "null"
DBName = "bridge"
)
const (
WsServer = "ws://101.132.159.197:8547"
)
//const (
// RedisKeyFromNum = "m:b" // monitor:block
//)
//var redisCon redis.Conn
func main() {
var pgCon *sql.DB
var err error
// connect to db
dbInfo := fmt.Sprintf(
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
DBHost, DBPort, DBUser, DBPassword, DBName)
pgCon, err = sql.Open("postgres", dbInfo)
panicErr(err)
// test connection
err = pgCon.Ping()
panicErr(err)
// connect to redis
//redisCon, err = redis.Dial("tcp", "localhost:6379")
//panicErr(err)
//defer redisCon.Close()
// subscribe for new block
cHeadNum := make(chan *big.Int, 1)
err = Subscribe(WsServer, cHeadNum)
panicErr(err)
// context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
taskManager := NewTaskManager()
err = taskManager.Run(ctx, cHeadNum, pgCon)
panicErr(err)
exit := make(chan os.Signal)
signal.Notify(exit, os.Interrupt, os.Kill)
<-exit
cancel()
time.Sleep(time.Second * 5)
// shareTxInfo
//shareTxInfo, err := client.QueryShareTxInfo(big.NewInt(200000), big.NewInt(286400))
//if err == nil {
// fmt.Printf("shareTxInfo: %v\n", shareTxInfo)
//} else {
// fmt.Printf("err: %v\n", err)
//}
}
func panicErr(err error) {
if err != nil {
panic(err)
}
}