/
grpc_query.go
87 lines (70 loc) · 3.39 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package keeper
import (
"context"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/Stride-Labs/stride/v16/x/ratelimit/types"
)
var _ types.QueryServer = Keeper{}
// Query all rate limits
func (k Keeper) AllRateLimits(c context.Context, req *types.QueryAllRateLimitsRequest) (*types.QueryAllRateLimitsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
rateLimits := k.GetAllRateLimits(ctx)
return &types.QueryAllRateLimitsResponse{RateLimits: rateLimits}, nil
}
// Query a rate limit by denom and channelId
func (k Keeper) RateLimit(c context.Context, req *types.QueryRateLimitRequest) (*types.QueryRateLimitResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
rateLimit, found := k.GetRateLimit(ctx, req.Denom, req.ChannelId)
if !found {
return &types.QueryRateLimitResponse{}, nil
}
return &types.QueryRateLimitResponse{RateLimit: &rateLimit}, nil
}
// Query all rate limits for a given chain
func (k Keeper) RateLimitsByChainId(c context.Context, req *types.QueryRateLimitsByChainIdRequest) (*types.QueryRateLimitsByChainIdResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
rateLimits := []types.RateLimit{}
for _, rateLimit := range k.GetAllRateLimits(ctx) {
// Determine the client state from the channel Id
_, clientState, err := k.channelKeeper.GetChannelClientState(ctx, transfertypes.PortID, rateLimit.Path.ChannelId)
if err != nil {
return &types.QueryRateLimitsByChainIdResponse{}, errorsmod.Wrapf(types.ErrInvalidClientState, "Unable to fetch client state from channelId")
}
client, ok := clientState.(*ibctmtypes.ClientState)
if !ok {
return &types.QueryRateLimitsByChainIdResponse{}, errorsmod.Wrapf(types.ErrInvalidClientState, "Client state is not tendermint")
}
// If the chain ID matches, add the rate limit to the returned list
if client.ChainId == req.ChainId {
rateLimits = append(rateLimits, rateLimit)
}
}
return &types.QueryRateLimitsByChainIdResponse{RateLimits: rateLimits}, nil
}
// Query all rate limits for a given channel
func (k Keeper) RateLimitsByChannelId(c context.Context, req *types.QueryRateLimitsByChannelIdRequest) (*types.QueryRateLimitsByChannelIdResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
rateLimits := []types.RateLimit{}
for _, rateLimit := range k.GetAllRateLimits(ctx) {
// If the channel ID matches, add the rate limit to the returned list
if rateLimit.Path.ChannelId == req.ChannelId {
rateLimits = append(rateLimits, rateLimit)
}
}
return &types.QueryRateLimitsByChannelIdResponse{RateLimits: rateLimits}, nil
}
// Query all blacklisted denoms
func (k Keeper) AllBlacklistedDenoms(c context.Context, req *types.QueryAllBlacklistedDenomsRequest) (*types.QueryAllBlacklistedDenomsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
blacklistedDenoms := k.GetAllBlacklistedDenoms(ctx)
return &types.QueryAllBlacklistedDenomsResponse{Denoms: blacklistedDenoms}, nil
}
// Query all whitelisted addresses
func (k Keeper) AllWhitelistedAddresses(c context.Context, req *types.QueryAllWhitelistedAddressesRequest) (*types.QueryAllWhitelistedAddressesResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
whitelistedAddresses := k.GetAllWhitelistedAddressPairs(ctx)
return &types.QueryAllWhitelistedAddressesResponse{AddressPairs: whitelistedAddresses}, nil
}