-
Notifications
You must be signed in to change notification settings - Fork 0
/
txstats.go
117 lines (102 loc) · 2.84 KB
/
txstats.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
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
package main
import (
"bytes"
"encoding/json"
"io"
"log"
"net/http"
"net/url"
"strconv"
)
type OverallInfoTX struct {
DailyAverage float64
HourlyAverage float64
WinPercent float64
Projection string
CurrentCoinsPerDay float64
NetHash string
DayStats []DayStatTX
HourStats []HourStatTX
TotalActiveMiners int
}
var overallInfoTX = make(map[int]OverallInfoTX)
type DayStatTX struct {
Day string
CoinCount float64
CoinsPerHour float64
WinPercent float64
}
type HourStatTX struct {
Hour int
HourStr string
CoinCount float64
CoinsPerMinute float64
}
type AddrStatResponse struct {
HourlyStats []struct {
Hour int `json:"Hour"`
Coins float64 `json:"Coins"`
ChainCoins float64 `json:"ChainCoins"`
WinPercent float64 `json:"WinPercent"`
} `json:"HourlyStats"`
DailyStats []struct {
Day string `json:"Day"`
Coins float64 `json:"Coins"`
ChainCoins float64 `json:"ChainCoins"`
WinPercent float64 `json:"WinPercent"`
} `json:"DailyStats"`
ProjectedCoinsToday float64 `json:"ProjectedCoinsToday"`
NetHash float64 `json:"NetHash"`
}
// key is user id
var addrStats = make(map[int]AddrStatResponse)
/*
http://dmo-monitor.com:9143/getminingstats
{
"Addresses": "dy1qpfr5yhdkgs6jyuk945y23pskdxmy9ajefczsvm",
}
NOTE: If an error occurs, then just do not update the stats....
*/
func txStats() {
client := &http.Client{}
reqUrl := url.URL{
Scheme: "http",
Host: "dmo-monitor.com:9143",
Path: "getminingstats",
}
mutex.Lock()
for userID, addresses := range userIDList {
// Not really an error... some users may not have configured this.
if len(addresses.ReceivingAddresses) == 0 {
continue
}
var addrsToMonitor = ""
for _, address := range addresses.ReceivingAddresses {
addrsToMonitor += address.ReceivingAddress + ","
}
addrsToMonitor = addrsToMonitor[:len(addrsToMonitor)-1]
var thisAddrStat AddrStatResponse
var data = bytes.NewBufferString(`{"jsonrpc":"1.0","id":"curltest","Addresses":"` + addrsToMonitor + `", "NumDays": ` + strconv.Itoa(myConfig.DailyStatDays) + `, "TimeZone": "` + addresses.TimeZone + `"}`)
req, err := http.NewRequest("GET", reqUrl.String(), data)
if err != nil {
log.Printf("Unable to make request to dmo-statservice: %s", err.Error())
continue
}
resp, err := client.Do(req)
if err != nil {
log.Printf("Unable to make request to dmo-statservice: %s", err.Error())
continue
}
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("Unable to make request to dmo-statservice: %s", err.Error())
continue
}
if err := json.Unmarshal(bodyText, &thisAddrStat); err != nil {
log.Printf("Unable to make request to dmo-statservice: %s", err.Error())
continue
}
addrStats[userID] = thisAddrStat
}
mutex.Unlock()
}