mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-07 19:44:26 -08:00
fix auction logic, finalization, & memcaching
This commit is contained in:
@@ -100,16 +100,18 @@ func (b *bidDB) GetLowestBid(auctionId string) (*types.Bid, error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
amt := big.NewInt(0)
|
||||
rAmt := big.NewInt(0)
|
||||
for _, rBid := range bids {
|
||||
minAmt := big.NewInt(0)
|
||||
refAmt := big.NewInt(0)
|
||||
for _, currBid := range bids {
|
||||
if bid == nil {
|
||||
bid = rBid
|
||||
amt.SetString(rBid.Amount, 10)
|
||||
bid = currBid
|
||||
minAmt.SetString(currBid.Amount, 10)
|
||||
} else {
|
||||
rAmt.SetString(rBid.Amount, 10)
|
||||
if rAmt.Cmp(amt) == -1 {
|
||||
bid = rBid
|
||||
// set ref amt.
|
||||
refAmt.SetString(currBid.Amount, 10)
|
||||
// if ref amt is less, then we have a new min
|
||||
if refAmt.Cmp(minAmt) == -1 {
|
||||
bid = currBid
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,6 +131,7 @@ func (b *bidDB) GetBids(auctionId string) ([]*types.Bid, error) {
|
||||
err := b.db.View(func(txn *badger.Txn) error {
|
||||
res, err := txn.Get(k)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
err := res.Value(func(val []byte) error {
|
||||
dec := gob.NewDecoder(bytes.NewReader(val))
|
||||
@@ -137,7 +140,6 @@ func (b *bidDB) GetBids(auctionId string) ([]*types.Bid, error) {
|
||||
})
|
||||
return err
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
||||
return bids, err
|
||||
|
||||
@@ -34,12 +34,12 @@ func TestBasicFlow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// check highest bid
|
||||
// check lowest bid
|
||||
if bid, err := BidDB.GetLowestBid("0"); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
if bid.Owner != "cosmos456" || bid.Amount != "200" {
|
||||
panic("Highest auction item not selected")
|
||||
if bid.Owner != "cosmos123" || bid.Amount != "100" {
|
||||
panic(fmt.Sprintf("Lowest auction item not selected. Amount %s with owner %s was chosen.", bid.Amount, bid.Owner))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user