mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 06:06:49 +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()
40 lines
974 B
Go
40 lines
974 B
Go
package dbaccess
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/database"
|
|
"github.com/kaspanet/kaspad/util/daghash"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
var feeBucket = database.MakeBucket([]byte("fees"))
|
|
|
|
func feeDataKey(hash *daghash.Hash) *database.Key {
|
|
return feeBucket.Key(hash[:])
|
|
}
|
|
|
|
// FetchFeeData returns the fee data of a block by its hash.
|
|
func FetchFeeData(context Context, blockHash *daghash.Hash) ([]byte, error) {
|
|
accessor, err := context.accessor()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
key := feeDataKey(blockHash)
|
|
feeData, err := accessor.Get(key)
|
|
if IsNotFoundError(err) {
|
|
return nil, errors.Wrapf(err, "couldn't find fee data for block %s", blockHash)
|
|
}
|
|
return feeData, err
|
|
}
|
|
|
|
// StoreFeeData stores the fee data of a block by its hash.
|
|
func StoreFeeData(context Context, blockHash *daghash.Hash, feeData []byte) error {
|
|
accessor, err := context.accessor()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
key := feeDataKey(blockHash)
|
|
return accessor.Put(key, feeData)
|
|
}
|