-
Notifications
You must be signed in to change notification settings - Fork 5
/
grpc_query_tick_liquidity.go
53 lines (41 loc) · 1.46 KB
/
grpc_query_tick_liquidity.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
package keeper
import (
"context"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/duality-labs/duality/x/dex/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// NOTE: For single queries of tick liquidity use explicty typed queries
// (ie. the k.LimitOrderTranche & k.PoolReserves)
func (k Keeper) TickLiquidityAll(
c context.Context,
req *types.QueryAllTickLiquidityRequest,
) (*types.QueryAllTickLiquidityResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
var tickLiquidities []*types.TickLiquidity
ctx := sdk.UnwrapSDKContext(c)
pairID, err := types.NewPairIDFromCanonicalString(req.PairID)
if err != nil {
return nil, err
}
tradePairID := types.NewTradePairIDFromMaker(pairID, req.TokenIn)
store := ctx.KVStore(k.storeKey)
tickLiquidityStore := prefix.NewStore(store, types.TickLiquidityPrefix(tradePairID))
pageRes, err := query.Paginate(tickLiquidityStore, req.Pagination, func(key, value []byte) error {
tickLiquidity := &types.TickLiquidity{}
if err := k.cdc.Unmarshal(value, tickLiquidity); err != nil {
return err
}
tickLiquidities = append(tickLiquidities, tickLiquidity)
return nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryAllTickLiquidityResponse{TickLiquidity: tickLiquidities, Pagination: pageRes}, nil
}