-
Notifications
You must be signed in to change notification settings - Fork 199
/
grpc_query_static_providers_list.go
45 lines (36 loc) · 1.36 KB
/
grpc_query_static_providers_list.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
package keeper
import (
"context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
epochstoragetypes "github.com/lavanet/lava/x/epochstorage/types"
"github.com/lavanet/lava/x/pairing/types"
spectypes "github.com/lavanet/lava/x/spec/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) StaticProvidersList(goCtx context.Context, req *types.QueryStaticProvidersListRequest) (*types.QueryStaticProvidersListResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
spec, found := k.specKeeper.GetSpec(ctx, req.GetChainID())
if !found || !spec.Enabled {
return nil, fmt.Errorf("spec %s is not found or exist", req.GetChainID())
}
if spec.ProvidersTypes != spectypes.Spec_static {
return nil, fmt.Errorf("spec %s is does not support static providers", req.GetChainID())
}
epoch := k.epochStorageKeeper.GetEpochStart(ctx)
stakes, found, _ := k.epochStorageKeeper.GetEpochStakeEntries(ctx, epoch, req.GetChainID())
if !found {
return &types.QueryStaticProvidersListResponse{}, nil
}
finalProviders := []epochstoragetypes.StakeEntry{}
for _, stake := range stakes {
if stake.StakeAppliedBlock <= epoch {
finalProviders = append(finalProviders, stake)
}
}
return &types.QueryStaticProvidersListResponse{Providers: finalProviders}, nil
}