check auction ceiling before placing bids

master
michael 2022-09-01 06:57:44 +00:00
parent ffd2529ccb
commit 69f2fa82de
1 changed files with 7 additions and 1 deletions

View File

@ -15,7 +15,7 @@ import (
func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.MsgNewBidResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
_, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex)
auction, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex)
if !found {
return nil, fmt.Errorf("didn't find auction of index %s", msg.AuctionIndex)
}
@ -38,6 +38,12 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("bid amount must be greater than 0")
}
ceiling := new(big.Int)
ceiling.SetString(auction.Ceiling, 10)
if amt.Cmp(ceiling) == 1 {
return nil, fmt.Errorf("bid amount cannot be greater than auction price ceiling (%s)", auction.Ceiling)
}
lowestBid, err := memdb.BidDB.GetLowestBid(msg.AuctionIndex)
// we manually handle KeyNotFound in GetHighestBid, so should return (nil, nil) if not found
if err != nil {