mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-15 18:46:39 +00:00

* [NOD-1223] Move all network stuff into a new network package. * [NOD-1223] Delete the unused package testutil. * [NOD-1223] Move infrastructure stuff into a new instrastructure package. * [NOD-1223] Move domain stuff into a new domain package.
39 lines
732 B
Go
39 lines
732 B
Go
package dbaccess
|
|
|
|
import "github.com/kaspanet/kaspad/infrastructure/database"
|
|
|
|
func clearBucket(dbTx *TxContext, bucket *database.Bucket) error {
|
|
accessor, err := dbTx.accessor()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Collect all of the keys before deleting them. We do this
|
|
// as to not modify the cursor while we're still iterating
|
|
// over it.
|
|
keys := make([]*database.Key, 0)
|
|
cursor, err := accessor.Cursor(bucket)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer cursor.Close()
|
|
|
|
for cursor.Next() {
|
|
key, err := cursor.Key()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
keys = append(keys, key)
|
|
}
|
|
|
|
// Delete all of the keys
|
|
for _, key := range keys {
|
|
err := accessor.Delete(key)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|