Roll in a dbFetchCBFIndexEntry()

This commit is contained in:
pedro martelletto 2017-01-12 13:25:45 +00:00 committed by Olaoluwa Osuntokun
parent 3b0038093a
commit 76926f8904

View file

@ -10,6 +10,7 @@ import (
"fmt"
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/database"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/gcs"
@ -32,6 +33,18 @@ var (
errCBFEntry = errors.New("no entry in the block ID index")
)
func dbFetchCBFIndexEntry(dbTx database.Tx, blockHash *chainhash.Hash) ([]byte,
error) {
// Load the record from the database and return now if it doesn't exist.
index := dbTx.Metadata().Bucket(cbfIndexKey)
serializedFilter := index.Get(blockHash.CloneBytes())
if len(serializedFilter) == 0 {
return nil, nil
}
return serializedFilter, nil
}
// The serialized format for keys and values in the block hash to CBF bucket is:
// <hash> = <CBF>
//