-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgo-warchest.go
60 lines (47 loc) · 1.49 KB
/
go-warchest.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
package main
import (
"context"
"flag"
"log"
"github.com/masknetgoal634/go-warchest/common"
"github.com/masknetgoal634/go-warchest/near-shell/runner"
"github.com/masknetgoal634/go-warchest/rpc"
nearapi "github.com/masknetgoal634/go-warchest/rpc/client"
prom "github.com/masknetgoal634/go-warchest/services/prometheus"
)
type arrayFlags []string
func (i *arrayFlags) String() string {
return "delegator ids"
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
var delegatorIds arrayFlags
func main() {
log.Println("Go-Warchest started...")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
url := flag.String("url", "https://rpc.betanet.near.org", "Near JSON-RPC URL")
addr := flag.String("addr", ":9444", "listen address")
poolId := flag.String("accountId", "test", "Validator pool account id")
flag.Var(&delegatorIds, "delegatorId", "Delegator ids.")
flag.Parse()
if len(flag.Args()) > 0 {
flag.Usage()
}
client := nearapi.NewClientWithContext(ctx, *url)
// Prometheus metrics
promMetrics := prom.NewPromMetrics()
// Run a metrics service
go promMetrics.RunMetricsService(*addr)
rpcMonitor := rpc.NewMonitor(client, *poolId)
resCh := make(chan *rpc.SubscrResult)
// Quota for a concurrent rpc requests
sem := make(common.Sem, 1)
// Run a remote rpc monitor
go rpcMonitor.Run(ctx, resCh, sem, promMetrics)
// Run a near-shell runner
runner := runner.NewRunner(*poolId, delegatorIds)
runner.Run(ctx, resCh, promMetrics, sem)
}