/
grpc_query_provider_conflicts.go
46 lines (37 loc) · 1.13 KB
/
grpc_query_provider_conflicts.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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/x/conflict/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) ProviderConflicts(c context.Context, req *types.QueryProviderConflictsRequest) (*types.QueryProviderConflictsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
var (
reported []string
notVoted []string
committed []string
)
ctx := sdk.UnwrapSDKContext(c)
conflicts := k.GetAllConflictVote(ctx)
for _, conflict := range conflicts {
if conflict.FirstProvider.Account == req.Provider ||
conflict.SecondProvider.Account == req.Provider {
reported = append(reported, conflict.Index)
}
for _, vote := range conflict.Votes {
if vote.Address == req.Provider {
if vote.Result == types.NoVote {
notVoted = append(notVoted, conflict.Index)
}
if vote.Result == types.Commit {
committed = append(committed, conflict.Index)
}
}
}
}
return &types.QueryProviderConflictsResponse{Reported: reported, NotVoted: notVoted, Committed: committed}, nil
}