factor verified providers into bidding tx flow

This commit is contained in:
2022-09-13 22:58:07 +00:00
parent 84bb357bc8
commit 11829e1017
13 changed files with 161 additions and 53 deletions

View File

@@ -24,7 +24,7 @@ func (k Keeper) AuctionIsExpired(ctx sdk.Context, auctionId string) (bool, error
}
func (k Keeper) FinalizeExpiredAuctions(ctx sdk.Context) {
memdb.BidDB.ForEachAuction(func(auctionId string) error {
memdb.AuctionDB.ForEachAuctionBidList(func(auctionId string) error {
auction, found := k.GetAuction(ctx, auctionId)
// make sure the auction exists on-chain
if !found {
@@ -33,7 +33,7 @@ func (k Keeper) FinalizeExpiredAuctions(ctx sdk.Context) {
if uint64(ctx.BlockHeight()) >= auction.Deadline {
var err error
auction.Best, err = memdb.BidDB.GetLowestBid(auctionId)
auction.Best, err = memdb.AuctionDB.GetLowestBid(auctionId)
if err != nil {
return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err)
}
@@ -42,10 +42,14 @@ func (k Keeper) FinalizeExpiredAuctions(ctx sdk.Context) {
auction.Remaining = auction.Best.Amount
// clear auction
if err := memdb.BidDB.ClearAuction(auctionId); err != nil {
if err := memdb.AuctionDB.ClearAuctionBids(auctionId); err != nil {
return errors.Errorf("failed to clear auction from memcache: %s", err)
}
if err := memdb.AuctionDB.ClearVerifiedProviders(auctionId); err != nil {
return errors.Errorf("failed to clear verified providers for auction %s: %s", auctionId, err)
}
// pay out unpaid remainder to auction creator
ceiling := new(big.Int)
ceiling.SetString(auction.Ceiling, 10)

View File

@@ -28,7 +28,7 @@ func (k Keeper) AuctionBids(goCtx context.Context, req *types.QueryAuctionBidsRe
return nil, fmt.Errorf("auction %s is already finalized", req.Index)
}
bids, err := memdb.BidDB.GetBids(auction.Index)
bids, err := memdb.AuctionDB.GetBids(auction.Index)
if err != nil {
return nil, fmt.Errorf("failed to get bids for auction %s: %s", auction.Index, err)
}

View File

@@ -49,6 +49,22 @@ found:
)
}
senderAddr, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return nil, fmt.Errorf("sender address `%s` format invalid (bech32 required)", msg.Creator)
}
if len(msg.VerifiedProviders) > auctionconfig.MaxVerifiedProviders {
return nil, fmt.Errorf("must submit no more than %d verified providers (got %d)", auctionconfig.MaxVerifiedProviders, len(msg.VerifiedProviders))
}
bech32Len := len("colinear") + 39
for i, provider := range msg.VerifiedProviders {
if len(provider) > bech32Len {
return nil, fmt.Errorf("verified provider address %s (#%d) must be no longer than a colinear bech32 address (%d)", provider, i, bech32Len)
}
}
auction := types.Auction{
Index: index,
Name: msg.Name,
@@ -67,11 +83,6 @@ found:
// Remaining: "0",
}
senderAddr, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return nil, fmt.Errorf("sender address `%s` format invalid (bech32 required)", msg.Creator)
}
spendable := k.bank.SpendableCoins(ctx, senderAddr)
// if balance does not exceed or equal proposed auction ceiling...
ceiling := new(big.Int)

View File

@@ -45,6 +45,21 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("auction %s is expired", msg.AuctionIndex)
}
if verProvs, err := memdb.AuctionDB.GetVerifiedProviders(msg.AuctionIndex); err == nil {
if len(verProvs) == 0 {
goto bidderVerified
} else {
for _, provider := range verProvs {
if msg.Creator == provider {
goto bidderVerified
}
}
return nil, fmt.Errorf("bid sender is not verified by the creator of auction %s", auction.Index)
}
}
bidderVerified:
amt := new(big.Int)
amt, ok = amt.SetString(msg.Amount, 10)
if !ok {
@@ -60,7 +75,7 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("bid amount cannot be greater than auction price ceiling (%s)", auction.Ceiling)
}
lowestBid, err := memdb.BidDB.GetLowestBid(msg.AuctionIndex)
lowestBid, err := memdb.AuctionDB.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 lowest bid: %s", reflect.TypeOf(err))
@@ -85,7 +100,7 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
Owner: msg.Creator,
}
if err := memdb.BidDB.AddBid(msg.AuctionIndex, bid); err != nil {
if err := memdb.AuctionDB.AddBid(msg.AuctionIndex, bid); err != nil {
return nil, fmt.Errorf("failed to add bid: %s", err)
}