cosmos-sdk/x/slashing/handler.go

53 lines
1.3 KiB
Go
Raw Normal View History

2018-05-28 12:38:02 -07:00
package slashing
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
func NewHandler(k Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
// NOTE msg already has validate basic run
switch msg := msg.(type) {
case MsgUnrevoke:
return handleMsgUnrevoke(ctx, msg, k)
default:
return sdk.ErrTxDecode("invalid message parse in staking module").Result()
}
}
}
func handleMsgUnrevoke(ctx sdk.Context, msg MsgUnrevoke, k Keeper) sdk.Result {
validator := k.stakeKeeper.Validator(ctx, msg.ValidatorAddr)
if validator == nil {
return ErrNoValidatorForAddress(k.codespace).Result()
}
2018-05-28 14:55:39 -07:00
addr := validator.GetPubKey().Address()
info, found := k.getValidatorSigningInfo(ctx, addr)
2018-05-28 13:08:13 -07:00
if !found {
return ErrNoValidatorForAddress(k.codespace).Result()
}
if ctx.BlockHeader().Time < info.JailedUntil {
return ErrValidatorJailed(k.codespace).Result()
}
2018-05-28 12:38:02 -07:00
if ctx.IsCheckTx() {
return sdk.Result{}
}
2018-05-28 14:55:39 -07:00
// Update the starting height (so the validator can't be immediately revoked again)
info.StartHeight = ctx.BlockHeight()
k.setValidatorSigningInfo(ctx, addr, info)
// Unrevoke the validator
2018-05-28 12:38:02 -07:00
k.stakeKeeper.Unrevoke(ctx, validator.GetPubKey())
tags := sdk.NewTags("action", []byte("unrevoke"), "validator", msg.ValidatorAddr.Bytes())
2018-05-28 14:55:39 -07:00
2018-05-28 12:38:02 -07:00
return sdk.Result{
Tags: tags,
}
}