-
Notifications
You must be signed in to change notification settings - Fork 3
/
main1.go.bk
199 lines (148 loc) · 5.24 KB
/
main1.go.bk
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// package main
// import (
// "context"
// "fmt"
// "log"
// "math/big"
// "sync"
// "time"
// "github.com/ethereum/go-ethereum/accounts/abi"
// "github.com/ethereum/go-ethereum/common"
// "github.com/diadata-org/oracle-monitoring/internal/config"
// "github.com/diadata-org/oracle-monitoring/internal/database"
// "github.com/diadata-org/oracle-monitoring/internal/helpers"
// "github.com/diadata-org/oracle-monitoring/internal/scraper"
// )
// func main() {
// var rpcmap map[string]string
// var wg sync.WaitGroup
// wg.Add(1)
// // Parse the command-line arguments
// // configFilePath := flag.String("targets", "oracles.json", "Path to the configuration file")
// // flag.Parse()
// // read the configuration data from the file
// // targets, err := config.LoadTargetConfig(*configFilePath)
// // if err != nil {
// // log.Fatalf("failed to read config file: %v", err)
// // }
// // connect to db
// db := database.NewPostgresDB()
// err := db.Connect()
// if err != nil {
// log.Fatalf("failed to connect to the database: %v", err)
// }
// defer db.Close()
// // update the list of targets
// // err = db.InsertOracles(targets)
// // if err != nil {
// // log.Fatalf("failed to update the list of target oracles: %v", err)
// // }
// // fetch the full list of oracles with the known metadata
// metricschan := make(chan helpers.OracleMetrics)
// rpcmap, err = db.GetRPCByChainID()
// if err != nil {
// log.Printf("failed to get rpcmap: %v", err)
// }
// ticker := time.NewTicker(1 * time.Minute)
// go func(chainid string) {
// var wg sync.WaitGroup
// var oracles []helpers.Oracle
// _oracles, err := db.SelectOracles(chainid)
// if err != nil {
// log.Fatalf("failed to get the saved metadata from the DB: %v", err)
// }
// minimum := big.NewInt(0)
// maximum := big.NewInt(0)
// // add the ABI
// for _, _oracle := range _oracles {
// var oracle helpers.Oracle
// var oracleABI *abi.ABI
// oracle.ContractAddress = common.HexToAddress(_oracle.ContractAddress)
// oracle.NodeUrl = _oracle.NodeUrl
// oracle.LatestScrapedBlock = new(big.Int).SetUint64(_oracle.LatestScrapedBlock)
// if minimum.Cmp(oracle.LatestScrapedBlock) == 1 {
// minimum = oracle.LatestScrapedBlock
// }
// if maximum.Cmp(oracle.LatestScrapedBlock) < 0 {
// maximum = oracle.LatestScrapedBlock
// }
// // read the oracle contract ABI from a file
// oracleABI, err = config.LoadContractAbi(fmt.Sprintf("internal/abi/%s.json", "oracle-v2"))
// if err != nil {
// log.Fatalf("failed to load the oracle contract ABI: %v", err)
// }
// oracle.ContractABI = oracleABI
// oracle.ChainID = _oracle.ChainId
// oracles = append(oracles, oracle)
// }
// fmt.Printf("\n Scrapping started for chain %s, upto minimum block %s and total oracles %d", chainid, minimum, len(oracles))
// ctx := context.Background()
// sc := scraper.NewScraper(ctx, metricschan, rpcmap, minimum, maximum, oracles, &wg, chainid)
// sc.UpdateHistorical()
// }("5")
// go func() {
// for {
// select {
// case <-ticker.C:
// if true {
// fmt.Println("Ticker fired at:", time.Now())
// // for chain, _ := range rpcmap {
// go func(chainid string) {
// var wg sync.WaitGroup
// var oracles []helpers.Oracle
// _oracles, err := db.SelectOracles(chainid)
// if err != nil {
// log.Fatalf("failed to get the saved metadata from the DB: %v", err)
// }
// minimum := big.NewInt(0)
// maximum := big.NewInt(0)
// // add the ABI
// for _, _oracle := range _oracles {
// var oracle helpers.Oracle
// var oracleABI *abi.ABI
// oracle.ContractAddress = common.HexToAddress(_oracle.ContractAddress)
// oracle.NodeUrl = _oracle.NodeUrl
// oracle.LatestScrapedBlock = new(big.Int).SetUint64(_oracle.LatestScrapedBlock)
// if minimum.Cmp(oracle.LatestScrapedBlock) == 1 {
// minimum = oracle.LatestScrapedBlock
// }
// if maximum.Cmp(oracle.LatestScrapedBlock) < 0 {
// maximum = oracle.LatestScrapedBlock
// }
// // read the oracle contract ABI from a file
// oracleABI, err = config.LoadContractAbi(fmt.Sprintf("internal/abi/%s.json", "oracle-v2"))
// if err != nil {
// log.Fatalf("failed to load the oracle contract ABI: %v", err)
// }
// oracle.ContractABI = oracleABI
// oracle.ChainID = _oracle.ChainId
// oracles = append(oracles, oracle)
// }
// fmt.Printf("\n Scrapping started for chain %s, upto minimum block %s and total oracles %d", chainid, minimum, len(oracles))
// ctx := context.Background()
// sc := scraper.NewScraper(ctx, metricschan, rpcmap, minimum, maximum, oracles, &wg, chainid)
// sc.UpdateRecent()
// }("5")
// }
// }
// }
// // }
// }()
// log.Println("wait for events")
// for {
// select {
// case metrics, ok := <-metricschan:
// {
// if !ok {
// log.Println("Metrics channel closed, stopping loop.")
// return
// }
// fmt.Println("---", metrics)
// err := db.InsertOracleMetrics(&metrics)
// if err != nil {
// log.Println("Error inserting oracle metrics:", err)
// }
// }
// }
// }
// }