* Make JSONMarshaler require proto.Message * Use &msg with MarshalJSON * Use *LegacyAmino in queriers instead of JSONMarshaler * Revert ABCIMessageLogs String() and coins tests * Use LegacyAmino in client/debug and fix subspace tests * Use LegacyAmino in all legacy queriers and adapt simulation * Make AminoCodec implement Marshaler and some godoc fixes * Test fixes * Remove unrelevant comment * Use TxConfig.TxJSONEncoder * Use encoding/json in genutil cli migrate/validate genesis cmds * Address simulation related comments * Use JSONMarshaler in cli tests * Use proto.Message as respType in cli tests * Use tmjson for tm GenesisDoc * Update types/module/simulation.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update types/module/module_test.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Add godoc comments * Remove unused InsertKeyJSON * Fix tests Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package keeper
|
|
|
|
import (
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
|
)
|
|
|
|
// NewQuerier returns a minting Querier handler.
|
|
func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
|
return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) {
|
|
switch path[0] {
|
|
case types.QueryParameters:
|
|
return queryParams(ctx, k, legacyQuerierCdc)
|
|
|
|
case types.QueryInflation:
|
|
return queryInflation(ctx, k, legacyQuerierCdc)
|
|
|
|
case types.QueryAnnualProvisions:
|
|
return queryAnnualProvisions(ctx, k, legacyQuerierCdc)
|
|
|
|
default:
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0])
|
|
}
|
|
}
|
|
}
|
|
|
|
func queryParams(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
|
params := k.GetParams(ctx)
|
|
|
|
res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params)
|
|
if err != nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func queryInflation(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
|
minter := k.GetMinter(ctx)
|
|
|
|
res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.Inflation)
|
|
if err != nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func queryAnnualProvisions(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
|
minter := k.GetMinter(ctx)
|
|
|
|
res, err := codec.MarshalJSONIndent(legacyQuerierCdc, minter.AnnualProvisions)
|
|
if err != nil {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
}
|
|
|
|
return res, nil
|
|
}
|