make bids for lowest rather than highest

This commit is contained in:
2022-09-01 02:02:23 +00:00
parent 0d1513e35d
commit 8f4f5d270a
7 changed files with 30 additions and 30 deletions

View File

@@ -29,7 +29,7 @@ func (k *Keeper) EndExpiredAuctions(ctx types.Context) {
if uint64(ctx.BlockHeight()) >= auction.Deadline-auctionconfig.AuctionTime {
var err error
auction.TopBid, err = memdb.BidDB.GetHighestBid(auctionId)
auction.Best, err = memdb.BidDB.GetLowestBid(auctionId)
if err != nil {
return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err)
}

View File

@@ -24,7 +24,7 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
Index: index,
Name: msg.Name,
Description: msg.Description,
TopBid: new(types.Bid),
Best: new(types.Bid),
Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime,
}

View File

@@ -38,7 +38,7 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("bid amount must be greater than 0")
}
highestBid, err := memdb.BidDB.GetHighestBid(msg.AuctionIndex)
highestBid, err := memdb.BidDB.GetLowestBid(msg.AuctionIndex)
// we manually handle KeyNotFound in GetHighestBid, so should return (nil, nil) if not found
if err != nil {
return nil, fmt.Errorf("failed to get highest bid: %s", reflect.TypeOf(err))
@@ -51,8 +51,8 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("failed to convert max bid (%s) to a large integer", msg.Amount)
}
if amt.Cmp(amtPrev) < 1 {
return nil, fmt.Errorf("bid amount must be greater than largest bid")
if amt.Cmp(amtPrev) != -1 {
return nil, fmt.Errorf("bid amount must be less than current lowest bid (%s)", amtPrev)
}
}