mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-14 10:06:40 +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.
40 lines
989 B
Go
40 lines
989 B
Go
package dbaccess
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/infrastructure/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)
|
|
}
|