Skip to content

Commit

Permalink
update models/height/general.go
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangjinyuan committed Oct 29, 2019
1 parent 11ebd7e commit c42ab81
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions models/height/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type BlockHeightMonitor struct {
Hash map[string]string
}

func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
func (b *BlockHeightMonitor) Run(coin string, db *sql.DB) {
b.Height = make(map[string]int64)
b.Hash = make(map[string]string)
switch coin {
Expand Down Expand Up @@ -145,20 +145,22 @@ func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
}()
}
b.wg.Add(1)
var temp4 models.BTCcom
temp4.GetBlockInfo(coin)
b.Height["BTCcom"] = temp4.Height
b.Hash["BTCcom"] = temp4.Hash
b.wg.Done()
go func() {
var temp4 models.BTCcom
temp4.GetBlockInfo(coin)
b.Height["BTCcom"] = temp4.Height
b.Hash["BTCcom"] = temp4.Hash
b.wg.Done()
}()

b.wg.Add(1)
/*b.wg.Add(1)
go func() {
var temp5 models.Node
temp5.GetBlockInfo(coin)
b.Height["Node"] = temp5.Height
b.Hash["Node"] = temp5.Hash
b.wg.Done()
}()
}()*/
b.wg.Wait()
util.Insert(db, coin, b.Height, b.Hash)
b.Compare(coin)
Expand All @@ -167,44 +169,44 @@ func (b *BlockHeightMonitor) Run(coin string, db *sql.DB){
}

func (b BlockHeightMonitor) Compare(coin string) {
text := make(map[string]string) //write the information which to send
count := make(map[string]int64) //Record the blockHeight difference between other explorers and BTC.com
var N int64 //the AlarmThreshold of every coin
text := make(map[string]string) //write the information which to send
count := make(map[string]int64) //Record the blockHeight difference between other explorers and BTC.com
var N int64 //the AlarmThreshold of every coin
switch coin {
case "btc":
N = configs.Config.AlarmThreshold.Btc
text["0"] = fmt.Sprintf("The BTC of BTC.com(v3)'s latest blockHeight: ")
text["0"] += fmt.Sprintf("%d",b.Height["BTCcom"])
text["0"] += fmt.Sprintf("%d", b.Height["BTCcom"])
count["BlockChain"] = b.Height["BlockChain"] - b.Height["BTCcom"]
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
count["ViaBtc"] = b.Height["ViaBtc"] - b.Height["BTCcom"]

case "bch":
N = configs.Config.AlarmThreshold.Bch
text["0"] = fmt.Sprintf("The BCH of BTC.com(v3)'s latest blockHeight: ")
text["0"] += fmt.Sprintf("%d",b.Height["BTCcom"])
text["0"] += fmt.Sprintf("%d", b.Height["BTCcom"])
count["Bitcoin"] = b.Height["Bitcoin"] - b.Height["BTCcom"]
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
count["ViaBtc"] = b.Height["ViaBtc"] - b.Height["BTCcom"]

case "ltc":
N = configs.Config.AlarmThreshold.Ltc
text["0"] = fmt.Sprintf("The LTC of BTC.com(v3)'s latest blockHeight: ")
text["0"] += fmt.Sprintf("%d",b.Height["BTCcom"])
text["0"] += fmt.Sprintf("%d", b.Height["BTCcom"])
count["ViaBtc"] = b.Height["ViaBtc"] - b.Height["BTCcom"]
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
count["BlockCypher"] = b.Height["BlockCypher"] - b.Height["BTCcom"]
case "eth":
N = configs.Config.AlarmThreshold.Eth
text["0"] = fmt.Sprintf("The ETH of BTC.com(v3)'s latest blockHeight: ")
text["0"] += fmt.Sprintf("%d",b.Height["BTCcom"])
text["0"] += fmt.Sprintf("%d", b.Height["BTCcom"])
count["Etherscan"] = b.Height["Etherscan"] - b.Height["BTCcom"]
count["BlockScout"] = b.Height["BlockScout"] - b.Height["BTCcom"]
count["BlockChair"] = b.Height["BlockChair"] - b.Height["BTCcom"]
case "etc":
N = configs.Config.AlarmThreshold.Etc
text["0"] = fmt.Sprintf("The ETC of BTC.com(v3)'s latest blockHeight: ")
text["0"] += fmt.Sprintf("%d",b.Height["BTCcom"])
text["0"] += fmt.Sprintf("%d", b.Height["BTCcom"])
count["Gastracker"] = b.Height["Gastracker"] - b.Height["BTCcom"]
count["EtcBlockExplorer"] = b.Height["EtcBlockExplorer"] - b.Height["BTCcom"]
}
Expand All @@ -228,16 +230,15 @@ func (b BlockHeightMonitor) Compare(coin string) {
if len(text) == 1 {
return
}
textHeight:=""
textHeight := ""
for key, result := range b.Height {
if key != "Node"{
tempHeight:=fmt.Sprintf(key+":")
tempHeight+=fmt.Sprintf("%d ",result)
textHeight+=tempHeight
}
tempHeight := fmt.Sprintf(key + ":")
tempHeight += fmt.Sprintf("%d ", result)
textHeight += tempHeight

}
fmt.Println(textHeight)

senders.SlackPoster.SendText(text," All latest blockHeight——"+textHeight) //send alarm info to slack channel
senders.EmailPublisher.SendText(text," All latest blockHeight——"+textHeight) //send alarm info to email
senders.SlackPoster.SendText(text, " All latest blockHeight——"+textHeight) //send alarm info to slack channel
senders.EmailPublisher.SendText(text, " All latest blockHeight——"+textHeight) //send alarm info to email
}

0 comments on commit c42ab81

Please sign in to comment.