2019-11-25 19:46:02 +00:00
|
|
|
package auction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
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 {
|
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
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-01-15 10:39:55 +00:00
|
|
|
return sdk.ErrUnknownRequest(fmt.Sprintf("Unrecognized auction msg type: %T", msg)).Result()
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleMsgPlaceBid(ctx sdk.Context, keeper Keeper, msg MsgPlaceBid) sdk.Result {
|
|
|
|
|
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 {
|
|
|
|
return err.Result()
|
|
|
|
}
|
|
|
|
|
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()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
return sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}
|
2019-11-25 19:46:02 +00:00
|
|
|
}
|