link up bid txs and memdb storage + key fixes

lfg it works
This commit is contained in:
2022-08-30 23:29:04 +00:00
parent b5c7075bd0
commit d6b4b51ca6
3 changed files with 30 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"reflect"
"cosmos-test/x/cosmostest/memdb"
"cosmos-test/x/cosmostest/types"
@@ -30,17 +31,21 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
}
highestBid, err := memdb.BidDB.GetHighestBid(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", err)
}
amtPrev := new(big.Int)
amtPrev, ok = amtPrev.SetString(highestBid.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)
return nil, fmt.Errorf("failed to get highest bid: %s", reflect.TypeOf(err))
}
if amt.Cmp(amtPrev) < 1 {
return nil, fmt.Errorf("bid amount must be greater than largest bid")
if highestBid != nil {
amtPrev := new(big.Int)
amtPrev, ok = amtPrev.SetString(highestBid.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)
}
if amt.Cmp(amtPrev) < 1 {
return nil, fmt.Errorf("bid amount must be greater than largest bid")
}
}
bid := &types.Bid{