-
Notifications
You must be signed in to change notification settings - Fork 560
/
grpc_query.go
152 lines (135 loc) · 6.65 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
package keeper
import (
"context"
"github.com/c-osmosis/osmosis/x/lockup/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var _ types.QueryServer = Keeper{}
// ModuleBalance Return full balance of the module
func (k Keeper) ModuleBalance(goCtx context.Context, req *types.ModuleBalanceRequest) (*types.ModuleBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.ModuleBalanceResponse{Coins: k.GetModuleBalance(ctx)}, nil
}
// ModuleLockedAmount Returns locked balance of the module
func (k Keeper) ModuleLockedAmount(goCtx context.Context, req *types.ModuleLockedAmountRequest) (*types.ModuleLockedAmountResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.ModuleLockedAmountResponse{Coins: k.GetModuleLockedCoins(ctx)}, nil
}
// AccountUnlockableCoins returns unlockable coins which are not withdrawn yet
func (k Keeper) AccountUnlockableCoins(goCtx context.Context, req *types.AccountUnlockableCoinsRequest) (*types.AccountUnlockableCoinsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountUnlockableCoinsResponse{Coins: k.GetAccountUnlockableCoins(ctx, owner)}, nil
}
// AccountUnlockingCoins returns whole unlocking coins
func (k Keeper) AccountUnlockingCoins(goCtx context.Context, req *types.AccountUnlockingCoinsRequest) (*types.AccountUnlockingCoinsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountUnlockingCoinsResponse{Coins: k.GetAccountUnlockingCoins(ctx, owner)}, nil
}
// AccountLockedCoins Returns a locked coins that can't be withdrawn
func (k Keeper) AccountLockedCoins(goCtx context.Context, req *types.AccountLockedCoinsRequest) (*types.AccountLockedCoinsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountLockedCoinsResponse{Coins: k.GetAccountLockedCoins(ctx, owner)}, nil
}
// AccountLockedPastTime Returns the total locks of an account whose unlock time is beyond timestamp
func (k Keeper) AccountLockedPastTime(goCtx context.Context, req *types.AccountLockedPastTimeRequest) (*types.AccountLockedPastTimeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountLockedPastTimeResponse{Locks: k.GetAccountLockedPastTime(ctx, owner, req.Timestamp)}, nil
}
// AccountUnlockedBeforeTime Returns the total unlocks of an account whose unlock time is before timestamp
func (k Keeper) AccountUnlockedBeforeTime(goCtx context.Context, req *types.AccountUnlockedBeforeTimeRequest) (*types.AccountUnlockedBeforeTimeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountUnlockedBeforeTimeResponse{Locks: k.GetAccountUnlockedBeforeTime(ctx, owner, req.Timestamp)}, nil
}
// AccountLockedPastTimeDenom is equal to GetAccountLockedPastTime but denom specific
func (k Keeper) AccountLockedPastTimeDenom(goCtx context.Context, req *types.AccountLockedPastTimeDenomRequest) (*types.AccountLockedPastTimeDenomResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountLockedPastTimeDenomResponse{Locks: k.GetAccountLockedPastTimeDenom(ctx, owner, req.Denom, req.Timestamp)}, nil
}
// LockedByID Returns lock by lock ID
func (k Keeper) LockedByID(goCtx context.Context, req *types.LockedRequest) (*types.LockedResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
lock, err := k.GetLockByID(ctx, req.LockId)
return &types.LockedResponse{Lock: lock}, err
}
// AccountLockedLongerDuration Returns account locked with duration longer than specified
func (k Keeper) AccountLockedLongerDuration(goCtx context.Context, req *types.AccountLockedLongerDurationRequest) (*types.AccountLockedLongerDurationResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
locks := k.GetAccountLockedLongerDuration(ctx, owner, req.Duration)
return &types.AccountLockedLongerDurationResponse{Locks: locks}, nil
}
// AccountLockedLongerDurationDenom Returns account locked with duration longer than specified with specific denom
func (k Keeper) AccountLockedLongerDurationDenom(goCtx context.Context, req *types.AccountLockedLongerDurationDenomRequest) (*types.AccountLockedLongerDurationDenomResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
locks := k.GetAccountLockedLongerDurationDenom(ctx, owner, req.Denom, req.Duration)
return &types.AccountLockedLongerDurationDenomResponse{Locks: locks}, nil
}
// AccountLockedPastTimeNotUnlockingOnly Returns locked records of an account with unlock time beyond timestamp excluding tokens started unlocking
func (k Keeper) AccountLockedPastTimeNotUnlockingOnly(goCtx context.Context, req *types.AccountLockedPastTimeNotUnlockingOnlyRequest) (*types.AccountLockedPastTimeNotUnlockingOnlyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountLockedPastTimeNotUnlockingOnlyResponse{Locks: k.GetAccountLockedPastTimeNotUnlockingOnly(ctx, owner, req.Timestamp)}, nil
}
// AccountLockedLongerDurationNotUnlockingOnly Returns account locked records with longer duration excluding tokens started unlocking
func (k Keeper) AccountLockedLongerDurationNotUnlockingOnly(goCtx context.Context, req *types.AccountLockedLongerDurationNotUnlockingOnlyRequest) (*types.AccountLockedLongerDurationNotUnlockingOnlyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
owner, err := sdk.AccAddressFromBech32(req.Owner)
if req.Owner == "" {
owner = sdk.AccAddress{}
} else if err != nil {
return nil, err
}
return &types.AccountLockedLongerDurationNotUnlockingOnlyResponse{Locks: k.GetAccountLockedLongerDurationNotUnlockingOnly(ctx, owner, req.Duration)}, nil
}