2019-01-11 12:08:01 -08:00
|
|
|
package staking
|
2018-02-23 15:57:31 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-12-27 09:57:54 -08:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2019-01-11 12:08:01 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
2018-02-23 15:57:31 -08:00
|
|
|
)
|
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
func NewHandler(k keeper.Keeper) sdk.Handler {
|
2020-10-16 07:53:49 -07:00
|
|
|
msgServer := keeper.NewMsgServerImpl(k)
|
|
|
|
|
2019-12-27 09:57:54 -08:00
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
2019-06-26 09:03:25 -07:00
|
|
|
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
|
|
|
|
2018-03-14 11:42:50 -07:00
|
|
|
switch msg := msg.(type) {
|
2020-06-03 12:52:05 -07:00
|
|
|
case *types.MsgCreateValidator:
|
2020-10-16 07:53:49 -07:00
|
|
|
res, err := msgServer.CreateValidator(sdk.WrapSDKContext(ctx), msg)
|
|
|
|
return sdk.WrapServiceResult(ctx, res, err)
|
2019-04-15 09:25:04 -07:00
|
|
|
|
2020-06-03 12:52:05 -07:00
|
|
|
case *types.MsgEditValidator:
|
2020-10-16 07:53:49 -07:00
|
|
|
res, err := msgServer.EditValidator(sdk.WrapSDKContext(ctx), msg)
|
|
|
|
return sdk.WrapServiceResult(ctx, res, err)
|
2019-04-15 09:25:04 -07:00
|
|
|
|
2020-06-03 12:52:05 -07:00
|
|
|
case *types.MsgDelegate:
|
2020-10-16 07:53:49 -07:00
|
|
|
res, err := msgServer.Delegate(sdk.WrapSDKContext(ctx), msg)
|
|
|
|
return sdk.WrapServiceResult(ctx, res, err)
|
2019-04-15 09:25:04 -07:00
|
|
|
|
2020-06-03 12:52:05 -07:00
|
|
|
case *types.MsgBeginRedelegate:
|
2020-10-16 07:53:49 -07:00
|
|
|
res, err := msgServer.BeginRedelegate(sdk.WrapSDKContext(ctx), msg)
|
|
|
|
return sdk.WrapServiceResult(ctx, res, err)
|
2019-04-15 09:25:04 -07:00
|
|
|
|
2020-06-03 12:52:05 -07:00
|
|
|
case *types.MsgUndelegate:
|
2020-10-16 07:53:49 -07:00
|
|
|
res, err := msgServer.Undelegate(sdk.WrapSDKContext(ctx), msg)
|
|
|
|
return sdk.WrapServiceResult(ctx, res, err)
|
2019-04-15 09:25:04 -07:00
|
|
|
|
2018-03-13 11:27:52 -07:00
|
|
|
default:
|
2020-06-12 07:54:37 -07:00
|
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
|
2018-02-27 18:07:20 -08:00
|
|
|
}
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
|
|
|
}
|