diff --git a/x/cosmostest/memdb/biddb.go b/x/cosmostest/memdb/biddb.go index f5c173e..5eaf13a 100644 --- a/x/cosmostest/memdb/biddb.go +++ b/x/cosmostest/memdb/biddb.go @@ -152,3 +152,23 @@ func (b *bidDB) ClearAuction(auctionId string) error { return err } + +// Iterate over all auction keys in memory. VIEW-ONLY. +func (b *bidDB) ForEachAuction(viewFunc func(string) error) error { + err := b.db.View(func(txn *badger.Txn) error { + opts := badger.DefaultIteratorOptions + // can customize options down here if we want + iter := txn.NewIterator(opts) + defer iter.Close() + for iter.Rewind(); iter.Valid(); iter.Next() { + item := iter.Item() + key := string(item.Key()) + err := viewFunc(key) + if err != nil { + return err + } + } + return nil + }) + return err +}