func to get all bids from memdb

master
michael 2022-08-30 21:43:26 +00:00
parent 1105b49c6e
commit a2f5ce1fc1
1 changed files with 21 additions and 0 deletions

View File

@ -113,6 +113,27 @@ func (b *bidDB) GetHighestBid(auctionId string) (*types.Bid, error) {
return bid, err return bid, err
} }
func (b *bidDB) GetBids(auctionId string) ([]*types.Bid, error) {
k := []byte(auctionId)
var bids []*types.Bid
err := b.db.View(func(txn *badger.Txn) error {
res, err := txn.Get(k)
if err != nil {
} else {
err := res.Value(func(val []byte) error {
dec := gob.NewDecoder(bytes.NewReader(val))
err := dec.Decode(&bids)
return err
})
return err
}
return err
})
return bids, err
}
func (b *bidDB) ClearAuction(auctionId string) error { func (b *bidDB) ClearAuction(auctionId string) error {
k := []byte(auctionId) k := []byte(auctionId)