forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminers.go
More file actions
64 lines (54 loc) · 1.64 KB
/
miners.go
File metadata and controls
64 lines (54 loc) · 1.64 KB
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
package client
import (
"context"
"time"
"github.com/textileio/powergate/index/miner"
"github.com/textileio/powergate/index/miner/rpc"
)
// Miners provides an API for viewing miner data.
type Miners struct {
client rpc.RPCServiceClient
}
// Get returns the current index of available asks.
func (a *Miners) Get(ctx context.Context) (*miner.IndexSnapshot, error) {
reply, err := a.client.Get(ctx, &rpc.GetRequest{})
if err != nil {
return nil, err
}
info := make(map[string]miner.Meta, len(reply.GetIndex().GetMeta().GetInfo()))
for key, val := range reply.GetIndex().GetMeta().GetInfo() {
info[key] = miner.Meta{
LastUpdated: time.Unix(val.GetLastUpdated(), 0),
UserAgent: val.GetUserAgent(),
Location: miner.Location{
Country: val.GetLocation().GetCountry(),
Longitude: val.GetLocation().GetLongitude(),
Latitude: val.GetLocation().GetLatitude(),
},
Online: val.GetOnline(),
}
}
metaIndex := miner.MetaIndex{
Online: reply.GetIndex().GetMeta().GetOnline(),
Offline: reply.GetIndex().GetMeta().GetOffline(),
Info: info,
}
miners := make(map[string]miner.OnChainData, len(reply.GetIndex().GetChain().GetMiners()))
for key, val := range reply.GetIndex().GetChain().GetMiners() {
miners[key] = miner.OnChainData{
Power: val.GetPower(),
RelativePower: float64(val.GetRelativePower()),
SectorSize: val.GetSectorSize(),
ActiveDeals: val.GetActiveDeals(),
}
}
chainIndex := miner.ChainIndex{
LastUpdated: reply.GetIndex().GetChain().GetLastUpdated(),
Miners: miners,
}
index := &miner.IndexSnapshot{
Meta: metaIndex,
OnChain: chainIndex,
}
return index, nil
}