Skip to content

Commit c42ab81

Browse files
author
jiangjinyuan
committed
update models/height/general.go
1 parent 11ebd7e commit c42ab81

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

models/height/general.go

+25-24
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type BlockHeightMonitor struct {
1717
Hash map[string]string
1818
}
1919

20-
func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
20+
func (b *BlockHeightMonitor) Run(coin string, db *sql.DB) {
2121
b.Height = make(map[string]int64)
2222
b.Hash = make(map[string]string)
2323
switch coin {
@@ -145,20 +145,22 @@ func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
145145
}()
146146
}
147147
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+
}()
153155

154-
b.wg.Add(1)
156+
/*b.wg.Add(1)
155157
go func() {
156158
var temp5 models.Node
157159
temp5.GetBlockInfo(coin)
158160
b.Height["Node"] = temp5.Height
159161
b.Hash["Node"] = temp5.Hash
160162
b.wg.Done()
161-
}()
163+
}()*/
162164
b.wg.Wait()
163165
util.Insert(db, coin, b.Height, b.Hash)
164166
b.Compare(coin)
@@ -167,44 +169,44 @@ func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
167169
}
168170

169171
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
173175
switch coin {
174176
case "btc":
175177
N = configs.Config.AlarmThreshold.Btc
176178
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"])
178180
count["BlockChain"] = b.Height["BlockChain"] - b.Height["BTCcom"]
179181
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
180182
count["ViaBtc"] = b.Height["ViaBtc"] - b.Height["BTCcom"]
181183

182184
case "bch":
183185
N = configs.Config.AlarmThreshold.Bch
184186
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"])
186188
count["Bitcoin"] = b.Height["Bitcoin"] - b.Height["BTCcom"]
187189
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
188190
count["ViaBtc"] = b.Height["ViaBtc"] - b.Height["BTCcom"]
189191

190192
case "ltc":
191193
N = configs.Config.AlarmThreshold.Ltc
192194
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"])
194196
count["ViaBtc"] = b.Height["ViaBtc"] - b.Height["BTCcom"]
195197
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
196198
count["BlockCypher"] = b.Height["BlockCypher"] - b.Height["BTCcom"]
197199
case "eth":
198200
N = configs.Config.AlarmThreshold.Eth
199201
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"])
201203
count["Etherscan"] = b.Height["Etherscan"] - b.Height["BTCcom"]
202204
count["BlockScout"] = b.Height["BlockScout"] - b.Height["BTCcom"]
203205
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
204206
case "etc":
205207
N = configs.Config.AlarmThreshold.Etc
206208
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"])
208210
count["Gastracker"] = b.Height["Gastracker"] - b.Height["BTCcom"]
209211
count["EtcBlockExplorer"] = b.Height["EtcBlockExplorer"] - b.Height["BTCcom"]
210212
}
@@ -228,16 +230,15 @@ func (b BlockHeightMonitor) Compare(coin string) {
228230
if len(text) == 1 {
229231
return
230232
}
231-
textHeight:=""
233+
textHeight := ""
232234
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+
238239
}
239240
fmt.Println(textHeight)
240241

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
243244
}

0 commit comments

Comments
 (0)