-
Notifications
You must be signed in to change notification settings - Fork 41
/
querier.go
153 lines (132 loc) · 5.01 KB
/
querier.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
package wasm
import (
"encoding/json"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
wasmbindingstypes "github.com/elys-network/elys/wasmbindings/types"
"github.com/elys-network/elys/x/masterchef/keeper"
"github.com/elys-network/elys/x/masterchef/types"
)
// Querier handles queries for the Masterchef module.
type Querier struct {
keeper *keeper.Keeper
stakingKeeper *stakingkeeper.Keeper
}
func NewQuerier(keeper *keeper.Keeper, stakingKeeper *stakingkeeper.Keeper) *Querier {
return &Querier{
keeper: keeper,
stakingKeeper: stakingKeeper,
}
}
func (oq *Querier) HandleQuery(ctx sdk.Context, query wasmbindingstypes.ElysQuery) ([]byte, error) {
switch {
case query.MasterchefParams != nil:
return oq.queryParams(ctx, query.MasterchefParams)
case query.MasterchefExternalIncentive != nil:
return oq.queryExternalIncentive(ctx, query.MasterchefExternalIncentive)
case query.MasterchefPoolInfo != nil:
return oq.queryPoolInfo(ctx, query.MasterchefPoolInfo)
case query.MasterchefPoolRewardInfo != nil:
return oq.queryPoolRewardInfo(ctx, query.MasterchefPoolRewardInfo)
case query.MasterchefUserRewardInfo != nil:
return oq.queryUserRewardInfo(ctx, query.MasterchefUserRewardInfo)
case query.MasterchefUserPendingReward != nil:
return oq.queryUserPendingReward(ctx, query.MasterchefUserPendingReward)
case query.MasterchefStableStakeApr != nil:
return oq.queryStableStakeApr(ctx, query.MasterchefStableStakeApr)
case query.MasterchefPoolAprs != nil:
return oq.queryPoolAprs(ctx, query.MasterchefPoolAprs)
default:
// This handler cannot handle the query
return nil, wasmbindingstypes.ErrCannotHandleQuery
}
}
func (oq *Querier) queryParams(ctx sdk.Context, query *types.QueryParamsRequest) ([]byte, error) {
res, err := oq.keeper.Params(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get params")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize params response")
}
return responseBytes, nil
}
func (oq *Querier) queryExternalIncentive(ctx sdk.Context, query *types.QueryExternalIncentiveRequest) ([]byte, error) {
res, err := oq.keeper.ExternalIncentive(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get external incentive")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize external incentive response")
}
return responseBytes, nil
}
func (oq *Querier) queryPoolInfo(ctx sdk.Context, query *types.QueryPoolInfoRequest) ([]byte, error) {
res, err := oq.keeper.PoolInfo(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get pool info")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize pool info response")
}
return responseBytes, nil
}
func (oq *Querier) queryPoolRewardInfo(ctx sdk.Context, query *types.QueryPoolRewardInfoRequest) ([]byte, error) {
res, err := oq.keeper.PoolRewardInfo(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get pool reward info")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize pool reward info response")
}
return responseBytes, nil
}
func (oq *Querier) queryUserRewardInfo(ctx sdk.Context, query *types.QueryUserRewardInfoRequest) ([]byte, error) {
res, err := oq.keeper.UserRewardInfo(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get user reward info")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize user reward info response")
}
return responseBytes, nil
}
func (oq *Querier) queryUserPendingReward(ctx sdk.Context, query *types.QueryUserPendingRewardRequest) ([]byte, error) {
res, err := oq.keeper.UserPendingReward(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get user pending reward")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize user pending reward response")
}
return responseBytes, nil
}
func (oq *Querier) queryStableStakeApr(ctx sdk.Context, query *types.QueryStableStakeAprRequest) ([]byte, error) {
res, err := oq.keeper.StableStakeApr(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get user pending reward")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize user pending reward response")
}
return responseBytes, nil
}
func (oq *Querier) queryPoolAprs(ctx sdk.Context, query *types.QueryPoolAprsRequest) ([]byte, error) {
res, err := oq.keeper.PoolAprs(ctx, query)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to get user pending reward")
}
responseBytes, err := json.Marshal(res)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to serialize user pending reward response")
}
return responseBytes, nil
}