mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-06 02:14:24 -08:00
link up bid txs and memdb storage + key fixes
lfg it works
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"log"
|
||||
"math/big"
|
||||
|
||||
@@ -36,7 +37,7 @@ func (b *bidDB) AddBid(auctionId string, bid *types.Bid) error {
|
||||
err := b.db.Update(func(txn *badger.Txn) error {
|
||||
var bids []*types.Bid
|
||||
bidsOld, err := txn.Get(k)
|
||||
if err == badger.ErrKeyNotFound {
|
||||
if errors.Is(err, badger.ErrKeyNotFound) {
|
||||
// key not found -> just create a new Bid array
|
||||
bids = []*types.Bid{}
|
||||
} else {
|
||||
@@ -81,7 +82,11 @@ func (b *bidDB) GetHighestBid(auctionId string) (*types.Bid, error) {
|
||||
err := b.db.View(func(txn *badger.Txn) error {
|
||||
bidData, err := txn.Get(k)
|
||||
if err != nil {
|
||||
return err
|
||||
if !errors.Is(err, badger.ErrKeyNotFound) {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
err = bidData.Value(func(val []byte) error {
|
||||
@@ -91,6 +96,10 @@ func (b *bidDB) GetHighestBid(auctionId string) (*types.Bid, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if bids == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
amt := big.NewInt(0)
|
||||
rAmt := big.NewInt(0)
|
||||
for _, rBid := range bids {
|
||||
|
||||
Reference in New Issue
Block a user