From 05144c4e0629c3dad7399945d5c42a221fc271bb Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Wed, 31 Aug 2022 18:43:45 +0000 Subject: [PATCH] auction key iterator --- x/cosmostest/memdb/biddb.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 +}