builder: remove outpoint methods

This commit is contained in:
Olaoluwa Osuntokun 2018-06-14 18:49:05 -07:00
parent d3e82fcd5d
commit 98e65a007d
2 changed files with 2 additions and 39 deletions

View file

@ -7,7 +7,6 @@ package builder
import (
"crypto/rand"
"encoding/binary"
"fmt"
"math"
@ -67,17 +66,6 @@ func DeriveKey(keyHash *chainhash.Hash) [gcs.KeySize]byte {
return key
}
// OutPointToFilterEntry is a utility function that derives a filter entry from
// a wire.OutPoint in a standardized way for use with both building and
// querying filters.
func OutPointToFilterEntry(outpoint wire.OutPoint) []byte {
// Size of the hash plus size of int32 index
data := make([]byte, chainhash.HashSize+4)
copy(data[:], outpoint.Hash.CloneBytes()[:])
binary.LittleEndian.PutUint32(data[chainhash.HashSize:], outpoint.Index)
return data
}
// Key retrieves the key with which the builder will build a filter. This is
// useful if the builder is created with a random initial key.
func (b *GCSBuilder) Key() ([gcs.KeySize]byte, error) {
@ -188,17 +176,6 @@ func (b *GCSBuilder) AddEntries(data [][]byte) *GCSBuilder {
return b
}
// AddOutPoint adds a wire.OutPoint to the list of entries to be included in
// the GCS filter when it's built.
func (b *GCSBuilder) AddOutPoint(outpoint wire.OutPoint) *GCSBuilder {
// Do nothing if the builder's already errored out.
if b.err != nil {
return b
}
return b.AddEntry(OutPointToFilterEntry(outpoint))
}
// AddHash adds a chainhash.Hash to the list of entries to be included in the
// GCS filter when it's built.
func (b *GCSBuilder) AddHash(hash *chainhash.Hash) *GCSBuilder {

View file

@ -178,8 +178,8 @@ func TestUseBlockHash(t *testing.T) {
// Create a GCSBuilder with a known key and too-high P and ensure error
// works throughout all functions that use it.
b = builder.WithRandomKeyPM(33, 99).SetKeyFromHash(hash).SetKey(testKey)
b.SetP(30).AddEntry(hash.CloneBytes()).AddEntries(contents)
b.AddOutPoint(outPoint).AddHash(hash).AddScript(addrBytes)
b.SetP(30).AddEntry(hash.CloneBytes()).AddEntries(contents).
AddHash(hash).AddScript(addrBytes)
_, err = b.Key()
if err != gcs.ErrPTooBig {
t.Fatalf("No error on P too big!")
@ -239,20 +239,6 @@ func BuilderTest(b *builder.GCSBuilder, hash *chainhash.Hash, p uint8,
t.Fatal("Filter didn't match when it should have!")
}
// Add a wire.OutPoint, build a filter, and test matches
b.AddOutPoint(outPoint)
f, err = b.Build()
if err != nil {
t.Fatalf("Filter build failed: %s", err.Error())
}
match, err = f.Match(key, hash.CloneBytes())
if err != nil {
t.Fatalf("Filter match failed: %s", err)
}
if !match {
t.Fatal("Filter didn't match when it should have!")
}
// Add a script, build a filter, and test matches
b.AddEntry(addrBytes)
f, err = b.Build()