2019-11-25 19:46:02 +00:00
|
|
|
package auction
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-23 16:35:58 +00:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2020-01-14 14:00:37 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/auction/types"
|
2019-11-25 19:46:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewHandler returns a function to handle all "auction" type messages.
|
|
|
|
func NewHandler(keeper Keeper) sdk.Handler {
|
2020-04-23 16:35:58 +00:00
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
2020-01-14 14:00:37 +00:00
|
|
|
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
|
|
|
|
2019-11-25 19:46:02 +00:00
|
|
|
switch msg := msg.(type) {
|
|
|
|
case MsgPlaceBid:
|
|
|
|
return handleMsgPlaceBid(ctx, keeper, msg)
|
|
|
|
default:
|
2020-04-23 16:35:58 +00:00
|
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 16:35:58 +00:00
|
|
|
func handleMsgPlaceBid(ctx sdk.Context, keeper Keeper, msg MsgPlaceBid) (*sdk.Result, error) {
|
2019-11-25 19:46:02 +00:00
|
|
|
|
2020-01-12 15:12:22 +00:00
|
|
|
err := keeper.PlaceBid(ctx, msg.AuctionID, msg.Bidder, msg.Amount)
|
2019-11-25 19:46:02 +00:00
|
|
|
if err != nil {
|
2020-04-23 16:35:58 +00:00
|
|
|
return nil, err
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 14:00:37 +00:00
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
sdk.EventTypeMessage,
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
|
|
|
sdk.NewAttribute(sdk.AttributeKeySender, msg.Bidder.String()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2020-04-23 16:35:58 +00:00
|
|
|
return &sdk.Result{
|
2020-01-14 14:00:37 +00:00
|
|
|
Events: ctx.EventManager().Events(),
|
2020-04-23 16:35:58 +00:00
|
|
|
}, nil
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|