-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool.go
47 lines (43 loc) · 1.08 KB
/
pool.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
package npapi
// NumberOfMiners returns the nanopool miners count.
func NumberOfMiners() (uint, error) {
var size uint
if err := fetch(&size, activeMinersEndpoint); err != nil {
return size, err
}
return size, nil
}
// NumberOfWorkers returns the nanopool workers count.
func NumberOfWorkers() (uint, error) {
var size uint
if err := fetch(&size, activeWorkersEndpoint); err != nil {
return size, err
}
return size, nil
}
// PoolHashrate returns the nanopool hashrate [MH/s].
func PoolHashrate() (float64, error) {
var hashrate float64
if err := fetch(&hashrate, poolHashrateEndpoint); err != nil {
return hashrate, err
}
return hashrate, nil
}
// TopMiners returns the top 15 nanopool miners.
func TopMiners() ([]User, error) {
jsonMiners := []struct {
Address string `json:"address"`
Hashrate float64 `json:"hashrate"`
}{}
if err := fetch(&jsonMiners, topMinersEndpoint); err != nil {
return nil, err
}
miners := make([]User, len(jsonMiners))
for i, m := range jsonMiners {
miners[i] = User{
Address: m.Address,
Hashrate: m.Hashrate,
}
}
return miners, nil
}