/
validators.go
37 lines (32 loc) 路 1.08 KB
/
validators.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
package service
import (
"context"
"github.com/MinterTeam/minter-go-node/core/types"
pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// Validators returns list of active validators.
func (s *Service) Validators(ctx context.Context, req *pb.ValidatorsRequest) (*pb.ValidatorsResponse, error) {
height := int64(req.Height)
if height == 0 {
height = int64(s.blockchain.Height())
}
tmVals, err := s.client.Validators(&height, 1, 100)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
return nil, timeoutStatus.Err()
}
responseValidators := make([]*pb.ValidatorsResponse_Result, 0, len(tmVals.Validators))
for _, val := range tmVals.Validators {
var pk types.Pubkey
copy(pk[:], val.PubKey.Bytes()[5:])
responseValidators = append(responseValidators, &pb.ValidatorsResponse_Result{
PublicKey: pk.String(),
VotingPower: uint64(val.VotingPower),
})
}
return &pb.ValidatorsResponse{Validators: responseValidators}, nil
}