fix auction logic, finalization, & memcaching

This commit is contained in:
2022-09-01 04:48:54 +00:00
parent a2bb428f2f
commit 9727e246ee
4 changed files with 23 additions and 20 deletions

View File

@@ -1,7 +1,6 @@
package keeper
import (
"cosmos-test/x/cosmostest/auctionconfig"
"cosmos-test/x/cosmostest/memdb"
"github.com/cosmos/cosmos-sdk/types"
@@ -24,10 +23,10 @@ func (k *Keeper) EndExpiredAuctions(ctx types.Context) {
auction, found := k.GetAuction(ctx, auctionId)
// make sure the auction exists on-chain
if !found {
return errors.Errorf("auction %s not found", auctionId)
return errors.Errorf("auction %s not found on-chain", auctionId)
}
if uint64(ctx.BlockHeight()) >= auction.Deadline-auctionconfig.AuctionTime {
if uint64(ctx.BlockHeight()) >= auction.Deadline {
var err error
auction.Best, err = memdb.BidDB.GetLowestBid(auctionId)
if err != nil {

View File

@@ -38,15 +38,15 @@ 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.GetLowestBid(msg.AuctionIndex)
lowestBid, 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))
return nil, fmt.Errorf("failed to get lowest bid: %s", reflect.TypeOf(err))
}
if highestBid != nil {
if lowestBid != nil {
amtPrev := new(big.Int)
amtPrev, ok = amtPrev.SetString(highestBid.Amount, 10)
amtPrev, ok = amtPrev.SetString(lowestBid.Amount, 10)
if !ok { // this should have been checked before, but whatever
return nil, fmt.Errorf("failed to convert max bid (%s) to a large integer", msg.Amount)
}
@@ -61,7 +61,9 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
Owner: msg.Creator,
}
memdb.BidDB.AddBid(msg.AuctionIndex, bid)
if err := memdb.BidDB.AddBid(msg.AuctionIndex, bid); err != nil {
return nil, fmt.Errorf("failed to add bid: %s", err)
}
// auction.Bids = append(auction.Bids, bid)
// k.Keeper.SetAuction(ctx, auction)