/
grpc_query.go
287 lines (229 loc) · 10.5 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/osmosis-labs/osmosis/v10/x/lockup/types"
)
var _ types.QueryServer = Querier{}
// Querier defines a wrapper around the x/lockup keeper providing gRPC method
// handlers.
type Querier struct {
Keeper
}
func NewQuerier(k Keeper) Querier {
return Querier{Keeper: k}
}
// ModuleBalance Return full balance of the module.
func (q Querier) ModuleBalance(goCtx context.Context, _ *types.ModuleBalanceRequest) (*types.ModuleBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.ModuleBalanceResponse{Coins: q.Keeper.GetModuleBalance(ctx)}, nil
}
// ModuleLockedAmount returns locked balance of the module,
// which are all the tokens not unlocking + tokens that are not finished unlocking.
func (q Querier) ModuleLockedAmount(goCtx context.Context, _ *types.ModuleLockedAmountRequest) (*types.ModuleLockedAmountResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.ModuleLockedAmountResponse{Coins: q.Keeper.GetModuleLockedCoins(ctx)}, nil
}
// AccountUnlockableCoins returns unlockable coins which are not withdrawn yet.
func (q Querier) AccountUnlockableCoins(goCtx context.Context, req *types.AccountUnlockableCoinsRequest) (*types.AccountUnlockableCoinsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountUnlockableCoinsResponse{Coins: q.Keeper.GetAccountUnlockableCoins(ctx, owner)}, nil
}
// AccountUnlockingCoins returns the total amount of unlocking coins for a specific account.
func (q Querier) AccountUnlockingCoins(goCtx context.Context, req *types.AccountUnlockingCoinsRequest) (*types.AccountUnlockingCoinsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountUnlockingCoinsResponse{Coins: q.Keeper.GetAccountUnlockingCoins(ctx, owner)}, nil
}
// AccountLockedCoins returns the total amount of locked coins that can't be withdrawn for a specific account.
func (q Querier) AccountLockedCoins(goCtx context.Context, req *types.AccountLockedCoinsRequest) (*types.AccountLockedCoinsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountLockedCoinsResponse{Coins: q.Keeper.GetAccountLockedCoins(ctx, owner)}, nil
}
// AccountLockedPastTime returns the locks of an account whose unlock time is beyond provided timestamp.
func (q Querier) AccountLockedPastTime(goCtx context.Context, req *types.AccountLockedPastTimeRequest) (*types.AccountLockedPastTimeResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountLockedPastTimeResponse{Locks: q.Keeper.GetAccountLockedPastTime(ctx, owner, req.Timestamp)}, nil
}
// AccountUnlockedBeforeTime returns locks of an account of which unlock time is before the provided timestamp.
func (q Querier) AccountUnlockedBeforeTime(goCtx context.Context, req *types.AccountUnlockedBeforeTimeRequest) (*types.AccountUnlockedBeforeTimeResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountUnlockedBeforeTimeResponse{Locks: q.Keeper.GetAccountUnlockedBeforeTime(ctx, owner, req.Timestamp)}, nil
}
// AccountLockedPastTimeDenom returns the locks of an account whose unlock time is beyond provided timestamp, limited to locks with
// the specified denom. Equivalent to `AccountLockedPastTime` but denom specific.
func (q Querier) AccountLockedPastTimeDenom(goCtx context.Context, req *types.AccountLockedPastTimeDenomRequest) (*types.AccountLockedPastTimeDenomResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountLockedPastTimeDenomResponse{Locks: q.Keeper.GetAccountLockedPastTimeDenom(ctx, owner, req.Denom, req.Timestamp)}, nil
}
// LockedByID returns lock by lock ID.
func (q Querier) LockedByID(goCtx context.Context, req *types.LockedRequest) (*types.LockedResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
lock, err := q.Keeper.GetLockByID(ctx, req.LockId)
return &types.LockedResponse{Lock: lock}, err
}
// SyntheticLockupsByLockupID returns synthetic lockups by native lockup id.
func (q Querier) SyntheticLockupsByLockupID(goCtx context.Context, req *types.SyntheticLockupsByLockupIDRequest) (*types.SyntheticLockupsByLockupIDResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
synthLocks := q.Keeper.GetAllSyntheticLockupsByLockup(ctx, req.LockId)
return &types.SyntheticLockupsByLockupIDResponse{SyntheticLocks: synthLocks}, nil
}
// AccountLockedLongerDuration returns locks of an account with duration longer than specified.
func (q Querier) AccountLockedLongerDuration(goCtx context.Context, req *types.AccountLockedLongerDurationRequest) (*types.AccountLockedLongerDurationResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
locks := q.Keeper.GetAccountLockedLongerDuration(ctx, owner, req.Duration)
return &types.AccountLockedLongerDurationResponse{Locks: locks}, nil
}
// AccountLockedLongerDurationDenom returns locks of an account with duration longer than specified with specific denom.
func (q Querier) AccountLockedLongerDurationDenom(goCtx context.Context, req *types.AccountLockedLongerDurationDenomRequest) (*types.AccountLockedLongerDurationDenomResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
locks := q.Keeper.GetAccountLockedLongerDurationDenom(ctx, owner, req.Denom, req.Duration)
return &types.AccountLockedLongerDurationDenomResponse{Locks: locks}, nil
}
// AccountLockedDuration returns the account locked with the specified duration.
func (q Querier) AccountLockedDuration(goCtx context.Context, req *types.AccountLockedDurationRequest) (*types.AccountLockedDurationResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
locks := q.Keeper.GetAccountLockedDuration(ctx, owner, req.Duration)
return &types.AccountLockedDurationResponse{Locks: locks}, nil
}
// AccountLockedPastTimeNotUnlockingOnly returns locks of an account with unlock time beyond
// given timestamp excluding locks that has started unlocking.
func (q Querier) AccountLockedPastTimeNotUnlockingOnly(goCtx context.Context, req *types.AccountLockedPastTimeNotUnlockingOnlyRequest) (*types.AccountLockedPastTimeNotUnlockingOnlyResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountLockedPastTimeNotUnlockingOnlyResponse{Locks: q.Keeper.GetAccountLockedPastTimeNotUnlockingOnly(ctx, owner, req.Timestamp)}, nil
}
// AccountLockedLongerDurationNotUnlockingOnly returns locks of an account with longer duration
// than the specified duration, excluding tokens that has started unlocking.
func (q Querier) AccountLockedLongerDurationNotUnlockingOnly(goCtx context.Context, req *types.AccountLockedLongerDurationNotUnlockingOnlyRequest) (*types.AccountLockedLongerDurationNotUnlockingOnlyResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty owner")
}
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if err != nil {
return nil, err
}
return &types.AccountLockedLongerDurationNotUnlockingOnlyResponse{Locks: q.Keeper.GetAccountLockedLongerDurationNotUnlockingOnly(ctx, owner, req.Duration)}, nil
}
// LockedDenom returns the total amount of denom locked throughout all locks.
func (q Querier) LockedDenom(goCtx context.Context, req *types.LockedDenomRequest) (*types.LockedDenomResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if len(req.Denom) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty denom")
}
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.LockedDenomResponse{Amount: q.Keeper.GetLockedDenom(ctx, req.Denom, req.Duration)}, nil
}