-
Notifications
You must be signed in to change notification settings - Fork 125
/
grpc_query.go
52 lines (41 loc) · 1.26 KB
/
grpc_query.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
package keeper
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/irisnet/irishub/modules/guardian/types"
)
var _ types.QueryServer = Keeper{}
// Profilers implements the Query/Profilers gRPC method
func (k Keeper) Profilers(c context.Context, req *types.QueryProfilersRequest) (*types.QueryProfilersResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
var profilers []types.Guardian
k.IterateProfilers(
ctx,
func(profiler types.Guardian) bool {
profilers = append(profilers, profiler)
return false
},
)
return &types.QueryProfilersResponse{Profilers: profilers}, nil
}
// Trustees implements the Query/Trustees gRPC method
func (k Keeper) Trustees(c context.Context, req *types.QueryTrusteesRequest) (*types.QueryTrusteesResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
var trustees []types.Guardian
k.IterateTrustees(
ctx,
func(trustee types.Guardian) bool {
trustees = append(trustees, trustee)
return false
},
)
return &types.QueryTrusteesResponse{Trustees: trustees}, nil
}