0g-chain/x/auction/handler.go

44 lines
1.0 KiB
Go
Raw Normal View History

2019-11-25 19:46:02 +00:00
package auction
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"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 {
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:
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 {
err := keeper.PlaceBid(ctx, msg.AuctionID, msg.Bidder, msg.Amount)
2019-11-25 19:46:02 +00:00
if err != nil {
return err.Result()
}
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
}