/
grpc_query_pool.go
52 lines (40 loc) · 1.12 KB
/
grpc_query_pool.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"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/neutron-org/neutron/v3/x/dex/types"
)
func (k Keeper) Pool(
goCtx context.Context,
req *types.QueryPoolRequest,
) (*types.QueryPoolResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
pairID, err := types.NewPairIDFromCanonicalString(req.PairId)
if err != nil {
return nil, err
}
pool, found := k.GetPool(ctx, pairID, req.TickIndex, req.Fee)
if !found {
return nil, status.Error(codes.NotFound, "not found")
}
return &types.QueryPoolResponse{Pool: pool}, nil
}
func (k Keeper) PoolByID(
goCtx context.Context,
req *types.QueryPoolByIDRequest,
) (*types.QueryPoolResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
pool, found := k.GetPoolByID(ctx, req.PoolId)
if !found {
return nil, status.Error(codes.NotFound, "not found")
}
return &types.QueryPoolResponse{Pool: pool}, nil
}