@@ -17,7 +17,7 @@ type BlockHeightMonitor struct {
17
17
Hash map [string ]string
18
18
}
19
19
20
- func (b * BlockHeightMonitor ) Run (coin string , db * sql.DB ){
20
+ func (b * BlockHeightMonitor ) Run (coin string , db * sql.DB ) {
21
21
b .Height = make (map [string ]int64 )
22
22
b .Hash = make (map [string ]string )
23
23
switch coin {
@@ -145,20 +145,22 @@ func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
145
145
}()
146
146
}
147
147
b .wg .Add (1 )
148
- var temp4 models.BTCcom
149
- temp4 .GetBlockInfo (coin )
150
- b .Height ["BTCcom" ] = temp4 .Height
151
- b .Hash ["BTCcom" ] = temp4 .Hash
152
- b .wg .Done ()
148
+ go func () {
149
+ var temp4 models.BTCcom
150
+ temp4 .GetBlockInfo (coin )
151
+ b .Height ["BTCcom" ] = temp4 .Height
152
+ b .Hash ["BTCcom" ] = temp4 .Hash
153
+ b .wg .Done ()
154
+ }()
153
155
154
- b .wg .Add (1 )
156
+ /* b.wg.Add(1)
155
157
go func() {
156
158
var temp5 models.Node
157
159
temp5.GetBlockInfo(coin)
158
160
b.Height["Node"] = temp5.Height
159
161
b.Hash["Node"] = temp5.Hash
160
162
b.wg.Done()
161
- }()
163
+ }()*/
162
164
b .wg .Wait ()
163
165
util .Insert (db , coin , b .Height , b .Hash )
164
166
b .Compare (coin )
@@ -167,44 +169,44 @@ func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
167
169
}
168
170
169
171
func (b BlockHeightMonitor ) Compare (coin string ) {
170
- text := make (map [string ]string ) //write the information which to send
171
- count := make (map [string ]int64 ) //Record the blockHeight difference between other explorers and BTC.com
172
- var N int64 //the AlarmThreshold of every coin
172
+ text := make (map [string ]string ) //write the information which to send
173
+ count := make (map [string ]int64 ) //Record the blockHeight difference between other explorers and BTC.com
174
+ var N int64 //the AlarmThreshold of every coin
173
175
switch coin {
174
176
case "btc" :
175
177
N = configs .Config .AlarmThreshold .Btc
176
178
text ["0" ] = fmt .Sprintf ("The BTC of BTC.com(v3)'s latest blockHeight: " )
177
- text ["0" ] += fmt .Sprintf ("%d" ,b .Height ["BTCcom" ])
179
+ text ["0" ] += fmt .Sprintf ("%d" , b .Height ["BTCcom" ])
178
180
count ["BlockChain" ] = b .Height ["BlockChain" ] - b .Height ["BTCcom" ]
179
181
count ["BlockChair" ] = b .Height ["BlockChair" ] - b .Height ["BTCcom" ]
180
182
count ["ViaBtc" ] = b .Height ["ViaBtc" ] - b .Height ["BTCcom" ]
181
183
182
184
case "bch" :
183
185
N = configs .Config .AlarmThreshold .Bch
184
186
text ["0" ] = fmt .Sprintf ("The BCH of BTC.com(v3)'s latest blockHeight: " )
185
- text ["0" ] += fmt .Sprintf ("%d" ,b .Height ["BTCcom" ])
187
+ text ["0" ] += fmt .Sprintf ("%d" , b .Height ["BTCcom" ])
186
188
count ["Bitcoin" ] = b .Height ["Bitcoin" ] - b .Height ["BTCcom" ]
187
189
count ["BlockChair" ] = b .Height ["BlockChair" ] - b .Height ["BTCcom" ]
188
190
count ["ViaBtc" ] = b .Height ["ViaBtc" ] - b .Height ["BTCcom" ]
189
191
190
192
case "ltc" :
191
193
N = configs .Config .AlarmThreshold .Ltc
192
194
text ["0" ] = fmt .Sprintf ("The LTC of BTC.com(v3)'s latest blockHeight: " )
193
- text ["0" ] += fmt .Sprintf ("%d" ,b .Height ["BTCcom" ])
195
+ text ["0" ] += fmt .Sprintf ("%d" , b .Height ["BTCcom" ])
194
196
count ["ViaBtc" ] = b .Height ["ViaBtc" ] - b .Height ["BTCcom" ]
195
197
count ["BlockChair" ] = b .Height ["BlockChair" ] - b .Height ["BTCcom" ]
196
198
count ["BlockCypher" ] = b .Height ["BlockCypher" ] - b .Height ["BTCcom" ]
197
199
case "eth" :
198
200
N = configs .Config .AlarmThreshold .Eth
199
201
text ["0" ] = fmt .Sprintf ("The ETH of BTC.com(v3)'s latest blockHeight: " )
200
- text ["0" ] += fmt .Sprintf ("%d" ,b .Height ["BTCcom" ])
202
+ text ["0" ] += fmt .Sprintf ("%d" , b .Height ["BTCcom" ])
201
203
count ["Etherscan" ] = b .Height ["Etherscan" ] - b .Height ["BTCcom" ]
202
204
count ["BlockScout" ] = b .Height ["BlockScout" ] - b .Height ["BTCcom" ]
203
205
count ["BlockChair" ] = b .Height ["BlockChair" ] - b .Height ["BTCcom" ]
204
206
case "etc" :
205
207
N = configs .Config .AlarmThreshold .Etc
206
208
text ["0" ] = fmt .Sprintf ("The ETC of BTC.com(v3)'s latest blockHeight: " )
207
- text ["0" ] += fmt .Sprintf ("%d" ,b .Height ["BTCcom" ])
209
+ text ["0" ] += fmt .Sprintf ("%d" , b .Height ["BTCcom" ])
208
210
count ["Gastracker" ] = b .Height ["Gastracker" ] - b .Height ["BTCcom" ]
209
211
count ["EtcBlockExplorer" ] = b .Height ["EtcBlockExplorer" ] - b .Height ["BTCcom" ]
210
212
}
@@ -228,16 +230,15 @@ func (b BlockHeightMonitor) Compare(coin string) {
228
230
if len (text ) == 1 {
229
231
return
230
232
}
231
- textHeight := ""
233
+ textHeight := ""
232
234
for key , result := range b .Height {
233
- if key != "Node" {
234
- tempHeight := fmt .Sprintf (key + ":" )
235
- tempHeight += fmt .Sprintf ("%d " ,result )
236
- textHeight += tempHeight
237
- }
235
+ tempHeight := fmt .Sprintf (key + ":" )
236
+ tempHeight += fmt .Sprintf ("%d " , result )
237
+ textHeight += tempHeight
238
+
238
239
}
239
240
fmt .Println (textHeight )
240
241
241
- senders .SlackPoster .SendText (text ," All latest blockHeight——" + textHeight ) //send alarm info to slack channel
242
- senders .EmailPublisher .SendText (text ," All latest blockHeight——" + textHeight ) //send alarm info to email
242
+ senders .SlackPoster .SendText (text , " All latest blockHeight——" + textHeight ) //send alarm info to slack channel
243
+ senders .EmailPublisher .SendText (text , " All latest blockHeight——" + textHeight ) //send alarm info to email
243
244
}
0 commit comments