-
Notifications
You must be signed in to change notification settings - Fork 119
/
grpc_query.go
118 lines (95 loc) · 3.67 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package keeper
import (
"context"
"fmt"
"github.com/Sifchain/sifnode/x/margin/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var _ types.QueryServer = queryServer{}
type queryServer struct {
keeper types.Keeper
}
func NewQueryServer(k types.Keeper) types.QueryServer {
return &queryServer{k}
}
func (srv queryServer) GetMTP(ctx context.Context, request *types.MTPRequest) (*types.MTPResponse, error) {
mtp, err := srv.keeper.GetMTP(sdk.UnwrapSDKContext(ctx), request.Address, request.Id)
if err != nil {
return nil, err
}
return &types.MTPResponse{Mtp: &mtp}, nil
}
func (srv queryServer) GetPositionsForAddress(goCtx context.Context, request *types.PositionsForAddressRequest) (*types.PositionsForAddressResponse, error) {
addr, err := sdk.AccAddressFromBech32(request.Address)
if err != nil {
return nil, err
}
mtps, pageRes, err := srv.keeper.GetMTPsForAddress(sdk.UnwrapSDKContext(goCtx), addr, request.Pagination)
if err != nil {
return nil, err
}
return &types.PositionsForAddressResponse{Mtps: mtps, Pagination: pageRes}, nil
}
func (srv queryServer) GetParams(ctx context.Context, request *types.ParamsRequest) (*types.ParamsResponse, error) {
params := srv.keeper.GetParams(sdk.UnwrapSDKContext(ctx))
return &types.ParamsResponse{Params: ¶ms}, nil
}
func (srv queryServer) GetPositionsByPool(ctx context.Context, request *types.PositionsByPoolRequest) (*types.PositionsByPoolResponse, error) {
mtps, pageRes, err := srv.keeper.GetMTPsForPool(sdk.UnwrapSDKContext(ctx), request.Asset, request.Pagination)
if err != nil {
return nil, err
}
return &types.PositionsByPoolResponse{
Mtps: mtps,
Pagination: pageRes,
}, nil
}
func (srv queryServer) GetPositions(ctx context.Context, request *types.PositionsRequest) (*types.PositionsResponse, error) {
if request.Pagination.Limit > MaxPageLimit {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("page size greater than max %d", MaxPageLimit))
}
mtps, page, err := srv.keeper.GetMTPs(sdk.UnwrapSDKContext(ctx), request.Pagination)
if err != nil {
return nil, err
}
return &types.PositionsResponse{
Mtps: mtps,
Pagination: page,
}, nil
}
func (srv queryServer) GetStatus(ctx context.Context, request *types.StatusRequest) (*types.StatusResponse, error) {
return &types.StatusResponse{
OpenMtpCount: srv.keeper.GetOpenMTPCount(sdk.UnwrapSDKContext(ctx)),
LifetimeMtpCount: srv.keeper.GetMTPCount(sdk.UnwrapSDKContext(ctx)),
}, nil
}
func (srv queryServer) GetWhitelist(ctx context.Context, request *types.WhitelistRequest) (*types.WhitelistResponse, error) {
if request.Pagination.Limit > MaxPageLimit {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("page size greater than max %d", MaxPageLimit))
}
whitelist, page, err := srv.keeper.GetWhitelist(sdk.UnwrapSDKContext(ctx), request.Pagination)
if err != nil {
return nil, err
}
return &types.WhitelistResponse{
Whitelist: whitelist,
Pagination: page,
}, nil
}
func (srv queryServer) GetSQParams(ctx context.Context, request *types.GetSQParamsRequest) (*types.GetSQParamsResponse, error) {
pool, err := srv.keeper.ClpKeeper().GetPool(sdk.UnwrapSDKContext(ctx), request.Pool)
if err != nil {
return nil, err
}
return &types.GetSQParamsResponse{
BeginBlock: int64(srv.keeper.GetSQBeginBlock(sdk.UnwrapSDKContext(ctx), &pool)),
}, nil
}
func (srv queryServer) IsWhitelisted(ctx context.Context, request *types.IsWhitelistedRequest) (*types.IsWhitelistedResponse, error) {
return &types.IsWhitelistedResponse{
Address: request.Address,
IsWhitelisted: srv.keeper.IsWhitelisted(sdk.UnwrapSDKContext(ctx), request.Address),
}, nil
}