/
gas_price.go
47 lines (40 loc) · 1.37 KB
/
gas_price.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
package legacy
import (
"context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
abci "github.com/tendermint/tendermint/abci/types"
)
// Deprecated: NewQuerier
func NewQuerier(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) {
if len(path) <= 0 {
return nil, sdkerrors.ErrInvalidRequest
}
switch path[0] {
case "gasPrice":
var gasPrices sdk.Coins
for _, coin := range ctx.MinGasPrices() {
gasPrices = append(gasPrices, sdk.NewCoin(coin.Denom, coin.Amount.TruncateInt()))
}
return codec.MarshalJSONIndent(legacyQuerierCdc, gasPrices)
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query endpoint: %s", path[0])
}
}
}
// Deprecated:
type Querier struct{}
var _ QueryServer = Querier{}
func (q Querier) FxGasPrice(ctx context.Context, request *GasPriceRequest) (*GasPriceResponse, error) {
return q.GasPrice(ctx, request)
}
func (q Querier) GasPrice(c context.Context, _ *GasPriceRequest) (*GasPriceResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
var gasPrices sdk.Coins
for _, coin := range ctx.MinGasPrices() {
gasPrices = append(gasPrices, sdk.NewCoin(coin.Denom, coin.Amount.TruncateInt()))
}
return &GasPriceResponse{GasPrices: gasPrices}, nil
}