Switch to new GCS builder interface
This commit is contained in:
parent
6d6677b797
commit
472141f88d
1 changed files with 13 additions and 25 deletions
|
@ -5,14 +5,13 @@
|
||||||
package indexers
|
package indexers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/blockchain"
|
"github.com/btcsuite/btcd/blockchain"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/database"
|
"github.com/btcsuite/btcd/database"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcutil/gcs"
|
"github.com/btcsuite/btcutil/gcs/builder"
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
@ -90,32 +89,21 @@ func (idx *CFIndex) Create(dbTx database.Tx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateFilterForBlock(block *btcutil.Block) ([]byte, error) {
|
func generateFilterForBlock(block *btcutil.Block) ([]byte, error) {
|
||||||
txSlice := block.Transactions() // XXX can this fail?
|
b := builder.WithKeyHash(block.Hash())
|
||||||
txHashes := make([][]byte, len(txSlice))
|
_, err := b.Key()
|
||||||
|
|
||||||
for i := 0; i < len(txSlice); i++ {
|
|
||||||
txHash, err := block.TxHash(i)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
txHashes = append(txHashes, txHash[:])
|
for _, tx := range block.Transactions() {
|
||||||
|
for _, txIn := range tx.MsgTx().TxIn {
|
||||||
|
b.AddOutPoint(txIn.PreviousOutPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
var key [gcs.KeySize]byte
|
|
||||||
P := uint8(20) // collision probability
|
|
||||||
|
|
||||||
for i := 0; i < gcs.KeySize; i += 4 {
|
|
||||||
binary.BigEndian.PutUint32(key[i:], uint32(0xcafebabe))
|
|
||||||
}
|
}
|
||||||
|
f, err := b.Build()
|
||||||
filter, err := gcs.BuildGCSFilter(P, key, txHashes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return f.Bytes(), nil
|
||||||
fmt.Fprintf(os.Stderr, "Generated CF for block %v", block.Hash())
|
|
||||||
|
|
||||||
return filter.Bytes(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectBlock is invoked by the index manager when a new block has been
|
// ConnectBlock is invoked by the index manager when a new block has been
|
||||||
|
|
Loading…
Add table
Reference in a new issue