43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package keeper
|
|
|
|
import (
|
|
"cosmos-test/x/cosmostest/auctionconfig"
|
|
"cosmos-test/x/cosmostest/memdb"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (k *Keeper) AuctionIsExpired(ctx types.Context, auctionId string) (bool, error) {
|
|
auction, found := k.GetAuction(ctx, auctionId)
|
|
|
|
// make sure the auction exists on-chain
|
|
if !found {
|
|
return true, errors.Errorf("auction %s not found", auctionId)
|
|
}
|
|
|
|
return uint64(ctx.BlockHeight()) >= auction.Deadline, nil
|
|
}
|
|
|
|
func (k *Keeper) EndExpiredAuctions(ctx types.Context) {
|
|
memdb.BidDB.ForEachAuction(func(auctionId string) error {
|
|
auction, found := k.GetAuction(ctx, auctionId)
|
|
// make sure the auction exists on-chain
|
|
if !found {
|
|
return errors.Errorf("auction %s not found", auctionId)
|
|
}
|
|
|
|
if uint64(ctx.BlockHeight()) >= auction.Deadline-auctionconfig.AuctionTime {
|
|
var err error
|
|
auction.TopBid, err = memdb.BidDB.GetHighestBid(auctionId)
|
|
if err != nil {
|
|
return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err)
|
|
}
|
|
k.SetAuction(ctx, auction)
|
|
memdb.BidDB.ClearAuction(auctionId)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|