mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 03:55:19 +00:00
ba80b508ab
* Custom sdk.Error types for the auction module * Requested changes: naming conventions, error message text
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package auction
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/x/auction/types"
|
|
)
|
|
|
|
// 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())
|
|
|
|
switch msg := msg.(type) {
|
|
case MsgPlaceBid:
|
|
return handleMsgPlaceBid(ctx, keeper, msg)
|
|
default:
|
|
return sdk.ErrUnknownRequest(fmt.Sprintf("Unrecognized auction msg type: %T", msg)).Result()
|
|
}
|
|
}
|
|
}
|
|
|
|
func handleMsgPlaceBid(ctx sdk.Context, keeper Keeper, msg MsgPlaceBid) sdk.Result {
|
|
|
|
err := keeper.PlaceBid(ctx, msg.AuctionID, msg.Bidder, msg.Amount)
|
|
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(),
|
|
}
|
|
}
|