refactor: x/distr module create querier (#12829)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
e39d84e06f
commit
5f9e7e6ea6
@ -14,10 +14,18 @@ import (
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
var _ types.QueryServer = Keeper{}
|
||||
var _ types.QueryServer = Querier{}
|
||||
|
||||
type Querier struct {
|
||||
Keeper
|
||||
}
|
||||
|
||||
func NewQuerier(keeper Keeper) Querier {
|
||||
return Querier{Keeper: keeper}
|
||||
}
|
||||
|
||||
// Params queries params of distribution module
|
||||
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
|
||||
func (k Querier) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
params := k.GetParams(ctx)
|
||||
|
||||
@ -25,7 +33,7 @@ func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types
|
||||
}
|
||||
|
||||
// ValidatorOutstandingRewards queries rewards of a validator address
|
||||
func (k Keeper) ValidatorOutstandingRewards(c context.Context, req *types.QueryValidatorOutstandingRewardsRequest) (*types.QueryValidatorOutstandingRewardsResponse, error) {
|
||||
func (k Querier) ValidatorOutstandingRewards(c context.Context, req *types.QueryValidatorOutstandingRewardsRequest) (*types.QueryValidatorOutstandingRewardsResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
@ -46,7 +54,7 @@ func (k Keeper) ValidatorOutstandingRewards(c context.Context, req *types.QueryV
|
||||
}
|
||||
|
||||
// ValidatorCommission queries accumulated commission for a validator
|
||||
func (k Keeper) ValidatorCommission(c context.Context, req *types.QueryValidatorCommissionRequest) (*types.QueryValidatorCommissionResponse, error) {
|
||||
func (k Querier) ValidatorCommission(c context.Context, req *types.QueryValidatorCommissionRequest) (*types.QueryValidatorCommissionResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
@ -67,7 +75,7 @@ func (k Keeper) ValidatorCommission(c context.Context, req *types.QueryValidator
|
||||
}
|
||||
|
||||
// ValidatorSlashes queries slash events of a validator
|
||||
func (k Keeper) ValidatorSlashes(c context.Context, req *types.QueryValidatorSlashesRequest) (*types.QueryValidatorSlashesResponse, error) {
|
||||
func (k Querier) ValidatorSlashes(c context.Context, req *types.QueryValidatorSlashesRequest) (*types.QueryValidatorSlashesResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
@ -110,7 +118,7 @@ func (k Keeper) ValidatorSlashes(c context.Context, req *types.QueryValidatorSla
|
||||
}
|
||||
|
||||
// DelegationRewards the total rewards accrued by a delegation
|
||||
func (k Keeper) DelegationRewards(c context.Context, req *types.QueryDelegationRewardsRequest) (*types.QueryDelegationRewardsResponse, error) {
|
||||
func (k Querier) DelegationRewards(c context.Context, req *types.QueryDelegationRewardsRequest) (*types.QueryDelegationRewardsResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
@ -151,7 +159,7 @@ func (k Keeper) DelegationRewards(c context.Context, req *types.QueryDelegationR
|
||||
}
|
||||
|
||||
// DelegationTotalRewards the total rewards accrued by a each validator
|
||||
func (k Keeper) DelegationTotalRewards(c context.Context, req *types.QueryDelegationTotalRewardsRequest) (*types.QueryDelegationTotalRewardsResponse, error) {
|
||||
func (k Querier) DelegationTotalRewards(c context.Context, req *types.QueryDelegationTotalRewardsRequest) (*types.QueryDelegationTotalRewardsResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
@ -188,7 +196,7 @@ func (k Keeper) DelegationTotalRewards(c context.Context, req *types.QueryDelega
|
||||
}
|
||||
|
||||
// DelegatorValidators queries the validators list of a delegator
|
||||
func (k Keeper) DelegatorValidators(c context.Context, req *types.QueryDelegatorValidatorsRequest) (*types.QueryDelegatorValidatorsResponse, error) {
|
||||
func (k Querier) DelegatorValidators(c context.Context, req *types.QueryDelegatorValidatorsRequest) (*types.QueryDelegatorValidatorsResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
@ -216,7 +224,7 @@ func (k Keeper) DelegatorValidators(c context.Context, req *types.QueryDelegator
|
||||
}
|
||||
|
||||
// DelegatorWithdrawAddress queries Query/delegatorWithdrawAddress
|
||||
func (k Keeper) DelegatorWithdrawAddress(c context.Context, req *types.QueryDelegatorWithdrawAddressRequest) (*types.QueryDelegatorWithdrawAddressResponse, error) {
|
||||
func (k Querier) DelegatorWithdrawAddress(c context.Context, req *types.QueryDelegatorWithdrawAddressRequest) (*types.QueryDelegatorWithdrawAddressResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid request")
|
||||
}
|
||||
@ -236,7 +244,7 @@ func (k Keeper) DelegatorWithdrawAddress(c context.Context, req *types.QueryDele
|
||||
}
|
||||
|
||||
// CommunityPool queries the community pool coins
|
||||
func (k Keeper) CommunityPool(c context.Context, req *types.QueryCommunityPoolRequest) (*types.QueryCommunityPoolResponse, error) {
|
||||
func (k Querier) CommunityPool(c context.Context, req *types.QueryCommunityPoolRequest) (*types.QueryCommunityPoolResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
pool := k.GetFeePoolCommunityCoins(ctx)
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, suite.interfaceRegistry)
|
||||
types.RegisterQueryServer(queryHelper, suite.distrKeeper)
|
||||
types.RegisterQueryServer(queryHelper, keeper.NewQuerier(suite.distrKeeper))
|
||||
queryClient := types.NewQueryClient(queryHelper)
|
||||
|
||||
suite.ctx = ctx
|
||||
@ -370,7 +370,7 @@ func (suite *KeeperTestSuite) TestGRPCDelegationRewards() {
|
||||
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
|
||||
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, suite.interfaceRegistry)
|
||||
types.RegisterQueryServer(queryHelper, suite.distrKeeper)
|
||||
types.RegisterQueryServer(queryHelper, keeper.NewQuerier(suite.distrKeeper))
|
||||
queryClient := types.NewQueryClient(queryHelper)
|
||||
|
||||
val := suite.stakingKeeper.Validator(ctx, valAddrs[0])
|
||||
|
||||
@ -135,7 +135,7 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||
// RegisterServices registers module services.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))
|
||||
|
||||
m := keeper.NewMigrator(am.keeper, am.legacySubspace)
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user