forked from cosmos/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
querier.go
52 lines (42 loc) · 1.58 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
package globalfee
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gaia/v16/x/globalfee/types"
)
var _ types.QueryServer = &GrpcQuerier{}
// ParamSource is a read only subset of paramtypes.Subspace
type ParamSource interface {
Get(ctx sdk.Context, key []byte, ptr interface{})
Has(ctx sdk.Context, key []byte) bool
}
type GrpcQuerier struct {
paramSource ParamSource
}
func NewGrpcQuerier(paramSource ParamSource) GrpcQuerier {
return GrpcQuerier{paramSource: paramSource}
}
// MinimumGasPrices return minimum gas prices
func (g GrpcQuerier) Params(stdCtx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
var minGasPrices sdk.DecCoins
var bypassMinFeeMsgTypes []string
var maxTotalBypassMinFeeMsgGasUsage uint64
ctx := sdk.UnwrapSDKContext(stdCtx)
// todo: if return err if not exist?
if g.paramSource.Has(ctx, types.ParamStoreKeyMinGasPrices) {
g.paramSource.Get(ctx, types.ParamStoreKeyMinGasPrices, &minGasPrices)
}
if g.paramSource.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) {
g.paramSource.Get(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &bypassMinFeeMsgTypes)
}
if g.paramSource.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) {
g.paramSource.Get(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &maxTotalBypassMinFeeMsgGasUsage)
}
return &types.QueryParamsResponse{
Params: types.Params{
MinimumGasPrices: minGasPrices,
BypassMinFeeMsgTypes: bypassMinFeeMsgTypes,
MaxTotalBypassMinFeeMsgGasUsage: maxTotalBypassMinFeeMsgGasUsage,
},
}, nil
}