2020-06-12 19:45:07 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2023-04-05 23:21:59 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
2020-06-12 19:45:07 +00:00
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/kavadist/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewQuerier is the module level router for state queries
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
2020-06-12 19:45:07 +00:00
|
|
|
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err error) {
|
|
|
|
switch path[0] {
|
|
|
|
case types.QueryGetParams:
|
2022-01-08 00:39:27 +00:00
|
|
|
return queryGetParams(ctx, req, k, legacyQuerierCdc)
|
2020-06-17 13:04:16 +00:00
|
|
|
case types.QueryGetBalance:
|
2022-01-08 00:39:27 +00:00
|
|
|
return queryGetBalance(ctx, req, k, legacyQuerierCdc)
|
2020-06-12 19:45:07 +00:00
|
|
|
default:
|
2023-04-05 23:21:59 +00:00
|
|
|
return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0])
|
2020-06-12 19:45:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// query params in the store
|
2022-01-08 00:39:27 +00:00
|
|
|
func queryGetParams(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
2020-06-12 19:45:07 +00:00
|
|
|
// Get params
|
|
|
|
params := k.GetParams(ctx)
|
|
|
|
|
|
|
|
// Encode results
|
2022-01-08 00:39:27 +00:00
|
|
|
bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, params)
|
2020-06-12 19:45:07 +00:00
|
|
|
if err != nil {
|
2023-04-05 23:21:59 +00:00
|
|
|
return nil, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
2020-06-12 19:45:07 +00:00
|
|
|
}
|
|
|
|
return bz, nil
|
|
|
|
}
|
2020-06-17 13:04:16 +00:00
|
|
|
|
|
|
|
// queryGetBalance returns current balance of kavadist module account
|
2022-01-08 00:39:27 +00:00
|
|
|
func queryGetBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
|
|
|
|
acc := k.accountKeeper.GetModuleAccount(ctx, types.KavaDistMacc)
|
|
|
|
balance := k.bankKeeper.GetAllBalances(ctx, acc.GetAddress())
|
|
|
|
bz, err := codec.MarshalJSONIndent(legacyQuerierCdc, balance)
|
2020-06-17 13:04:16 +00:00
|
|
|
if err != nil {
|
2023-04-05 23:21:59 +00:00
|
|
|
return nil, errorsmod.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
2020-06-17 13:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bz, nil
|
|
|
|
}
|