mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-885] Create database.Key type * [NOD-885] Rename FullKey()->FullKeyBytes() and Key()->KeyBytes() * [NOD-885] Make Key.String return a hex string * [NOD-885] Rename key parts * [NOD-885] Rename separator->bucketSeparator * [NOD-885] Rename SuffixBytes->Suffix and PrefixBytes->Prefix * [NOD-885] Change comments * [NOD-885] Change key prefix to bucket * [NOD-885] Don't use database.NewKey inside dbaccess * [NOD-885] Fix nil bug in Bucket.Path() * [NOD-885] Rename helpers.go -> keys.go * [NOD-885] Unexport database.NewKey * [NOD-885] Remove redundant code in Bucket.Path()
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package dbaccess
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/database"
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
)
|
|
|
|
var reachabilityDataBucket = database.MakeBucket([]byte("reachability"))
|
|
|
|
func reachabilityKey(hash *daghash.Hash) *database.Key {
|
|
return reachabilityDataBucket.Key(hash[:])
|
|
}
|
|
|
|
// ReachabilityDataCursor opens a cursor over all the
|
|
// reachability data entries.
|
|
func ReachabilityDataCursor(context Context) (database.Cursor, error) {
|
|
accessor, err := context.accessor()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return accessor.Cursor(reachabilityDataBucket)
|
|
}
|
|
|
|
// StoreReachabilityData stores the reachability data of a block by its hash.
|
|
func StoreReachabilityData(context Context, blockHash *daghash.Hash, reachabilityData []byte) error {
|
|
accessor, err := context.accessor()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
key := reachabilityKey(blockHash)
|
|
return accessor.Put(key, reachabilityData)
|
|
}
|
|
|
|
// ClearReachabilityData clears the reachability data
|
|
// from database.
|
|
func ClearReachabilityData(dbTx *TxContext) error {
|
|
return clearBucket(dbTx, reachabilityDataBucket)
|
|
}
|