forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreputation.go
More file actions
41 lines (36 loc) · 1.13 KB
/
reputation.go
File metadata and controls
41 lines (36 loc) · 1.13 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
package client
import (
"context"
ma "github.com/multiformats/go-multiaddr"
"github.com/textileio/powergate/reputation"
"github.com/textileio/powergate/reputation/rpc"
)
// Reputation provides an API for viewing reputation data.
type Reputation struct {
client rpc.RPCServiceClient
}
// AddSource adds a new external Source to be considered for reputation generation.
func (r *Reputation) AddSource(ctx context.Context, id string, maddr ma.Multiaddr) error {
req := &rpc.AddSourceRequest{
Id: id,
Maddr: maddr.String(),
}
_, err := r.client.AddSource(ctx, req)
return err
}
// GetTopMiners gets the top n miners with best score.
func (r *Reputation) GetTopMiners(ctx context.Context, limit int) ([]reputation.MinerScore, error) {
req := &rpc.GetTopMinersRequest{Limit: int32(limit)}
reply, err := r.client.GetTopMiners(ctx, req)
if err != nil {
return []reputation.MinerScore{}, err
}
topMiners := make([]reputation.MinerScore, len(reply.GetTopMiners()))
for i, val := range reply.GetTopMiners() {
topMiners[i] = reputation.MinerScore{
Addr: val.GetAddr(),
Score: int(val.GetScore()),
}
}
return topMiners, nil
}