2018-09-17 20:02:15 -07:00
|
|
|
package distribution
|
2018-09-18 20:30:00 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/tags"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewHandler(k keeper.Keeper) sdk.Handler {
|
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
|
|
|
// NOTE msg already has validate basic run
|
|
|
|
switch msg := msg.(type) {
|
2018-09-19 20:01:55 -07:00
|
|
|
case types.MsgSetWithdrawAddress:
|
2018-09-18 20:30:00 -07:00
|
|
|
return handleMsgModifyWithdrawAddress(ctx, msg, k)
|
|
|
|
case types.MsgWithdrawDelegatorReward:
|
|
|
|
return handleMsgWithdrawDelegatorReward(ctx, msg, k)
|
2019-01-16 13:38:05 -08:00
|
|
|
case types.MsgWithdrawValidatorCommission:
|
|
|
|
return handleMsgWithdrawValidatorCommission(ctx, msg, k)
|
2018-09-18 20:30:00 -07:00
|
|
|
default:
|
|
|
|
return sdk.ErrTxDecode("invalid message parse in distribution module").Result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// These functions assume everything has been authenticated (ValidateBasic passed, and signatures checked)
|
2018-09-18 20:30:00 -07:00
|
|
|
|
2018-09-19 20:01:55 -07:00
|
|
|
func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAddress, k keeper.Keeper) sdk.Result {
|
2018-09-18 20:30:00 -07:00
|
|
|
|
2019-02-25 07:16:52 -08:00
|
|
|
err := k.SetWithdrawAddr(ctx, msg.DelegatorAddress, msg.WithdrawAddress)
|
2019-01-16 14:17:56 -08:00
|
|
|
if err != nil {
|
|
|
|
return err.Result()
|
|
|
|
}
|
2018-09-18 20:30:00 -07:00
|
|
|
|
2019-04-09 05:55:01 -07:00
|
|
|
resTags := sdk.NewTags(
|
|
|
|
tags.Category, tags.TxCategory,
|
|
|
|
tags.Delegator, msg.DelegatorAddress.String(),
|
2018-09-18 20:30:00 -07:00
|
|
|
)
|
|
|
|
return sdk.Result{
|
2019-04-09 05:55:01 -07:00
|
|
|
Tags: resTags,
|
2018-09-18 20:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleMsgWithdrawDelegatorReward(ctx sdk.Context, msg types.MsgWithdrawDelegatorReward, k keeper.Keeper) sdk.Result {
|
2019-01-16 13:38:05 -08:00
|
|
|
|
2019-02-25 07:16:52 -08:00
|
|
|
err := k.WithdrawDelegationRewards(ctx, msg.DelegatorAddress, msg.ValidatorAddress)
|
2018-10-18 12:58:57 -07:00
|
|
|
if err != nil {
|
|
|
|
return err.Result()
|
|
|
|
}
|
2018-09-18 20:30:00 -07:00
|
|
|
|
2019-04-09 05:55:01 -07:00
|
|
|
resTags := sdk.NewTags(
|
|
|
|
tags.Category, tags.TxCategory,
|
|
|
|
tags.Delegator, msg.DelegatorAddress.String(),
|
|
|
|
tags.Validator, msg.ValidatorAddress.String(),
|
2018-09-18 20:30:00 -07:00
|
|
|
)
|
|
|
|
return sdk.Result{
|
2019-04-09 05:55:01 -07:00
|
|
|
Tags: resTags,
|
2018-09-18 20:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
func handleMsgWithdrawValidatorCommission(ctx sdk.Context, msg types.MsgWithdrawValidatorCommission, k keeper.Keeper) sdk.Result {
|
|
|
|
|
2019-02-25 07:16:52 -08:00
|
|
|
err := k.WithdrawValidatorCommission(ctx, msg.ValidatorAddress)
|
2018-10-18 12:58:57 -07:00
|
|
|
if err != nil {
|
|
|
|
return err.Result()
|
|
|
|
}
|
2018-09-18 20:30:00 -07:00
|
|
|
|
2019-04-09 05:55:01 -07:00
|
|
|
resTags := sdk.NewTags(
|
|
|
|
tags.Category, tags.TxCategory,
|
|
|
|
tags.Validator, msg.ValidatorAddress.String(),
|
2018-09-18 20:30:00 -07:00
|
|
|
)
|
|
|
|
return sdk.Result{
|
2019-04-09 05:55:01 -07:00
|
|
|
Tags: resTags,
|
2018-09-18 20:30:00 -07:00
|
|
|
}
|
|
|
|
}
|