Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (60 loc) · 1.78 KB
/
Copy pathmain.go
File metadata and controls
75 lines (60 loc) · 1.78 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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/patrulek/rayscan/config"
"github.com/patrulek/rayscan/connection"
"github.com/patrulek/rayscan/onchain"
)
func main() {
cfg, err := config.LoadConfig(config.DefaultConfigPath)
if err != nil {
fmt.Printf("Error loading config: %s\n", err)
os.Exit(1)
}
rpcPool, err := connection.NewRPCClientPool(cfg.Nodes)
if err != nil {
fmt.Printf("Error creating rpc pool: %s\n", err)
os.Exit(1)
}
defer rpcPool.Close()
pairCollector := onchain.NewPairCollector()
pairCollector.Start(nil)
txAnalyzer := onchain.NewTxAnalyzer(rpcPool)
txAnalyzer.Start(pairCollector.Channel())
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
var observers []*onchain.LogObserver
for _, v := range rpcPool.Connections {
if !v.ConnectionInfo.Observer {
continue
}
obs := onchain.NewLogObserver(rpcPool, v.ConnectionInfo.Name)
if err := obs.Start(ctx, txAnalyzer.Channel()); err != nil {
fmt.Printf("Error starting %s log observer: %s\n", v.ConnectionInfo.Name, err)
os.Exit(1)
}
observers = append(observers, obs)
}
var stopChan = make(chan os.Signal, 1)
signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
<-stopChan // wait for SIGINT
fmt.Printf("Interrupted; stopping...\n")
ctx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
for _, obs := range observers {
if err := obs.Stop(ctx); err != nil {
fmt.Printf("Error stopping %s log observer: %s\n", obs.ConnectionName(), err)
}
}
if err := txAnalyzer.Stop(ctx); err != nil {
fmt.Printf("Error stopping tx analyzer: %s\n", err)
}
if err := pairCollector.Stop(ctx); err != nil {
fmt.Printf("Error stopping pair collector: %s\n", err)
}
}