builder

package
v0.0.0-...-1b3f31a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2019 License: ISC Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultP is the default collision probability (2^-19)
	DefaultP = 19

	// DefaultM is the default value used for the hash range.
	DefaultM uint64 = 784931
)

Variables

This section is empty.

Functions

func BuildBasicFilter

func BuildBasicFilter(block *wire.MsgBlock, prevOutScripts [][]byte) (*gcs.Filter, error)

BuildBasicFilter builds a basic GCS filter from a block. A basic GCS filter will contain all the previous output scripts spent by inputs within a block, as well as the data pushes within all the outputs created within a block.

func DeriveKey

func DeriveKey(keyHash *chainhash.Hash) [gcs.KeySize]byte

DeriveKey is a utility function that derives a key from a chainhash.Hash by truncating the bytes of the hash to the appopriate key size.

func GetFilterHash

func GetFilterHash(filter *gcs.Filter) (chainhash.Hash, error)

GetFilterHash returns the double-SHA256 of the filter.

func MakeHeaderForFilter

func MakeHeaderForFilter(filter *gcs.Filter, prevHeader chainhash.Hash) (chainhash.Hash, error)

MakeHeaderForFilter makes a filter chain header for a filter, given the filter and the previous filter chain header.

func RandomKey

func RandomKey() ([gcs.KeySize]byte, error)

RandomKey is a utility function that returns a cryptographically random [gcs.KeySize]byte usable as a key for a GCS filter.

Types

type GCSBuilder

type GCSBuilder struct {
	// contains filtered or unexported fields
}

GCSBuilder is a utility class that makes building GCS filters convenient.

func WithKey

func WithKey(key [gcs.KeySize]byte) *GCSBuilder

WithKey creates a GCSBuilder with specified key. Probability is set to 19 (2^-19 collision probability). Estimated filter size is set to zero, which means more reallocations are done when building the filter.

func WithKeyHash

func WithKeyHash(keyHash *chainhash.Hash) *GCSBuilder

WithKeyHash creates a GCSBuilder with key derived from the specified chainhash.Hash. Probability is set to 20 (2^-20 collision probability). Estimated filter size is set to zero, which means more reallocations are done when building the filter.

func WithKeyHashPM

func WithKeyHashPM(keyHash *chainhash.Hash, p uint8, m uint64) *GCSBuilder

WithKeyHashPM creates a GCSBuilder with key derived from the specified chainhash.Hash and the passed probability. Estimated filter size is set to zero, which means more reallocations are done when building the filter.

func WithKeyHashPNM

func WithKeyHashPNM(keyHash *chainhash.Hash, p uint8, n uint32,
	m uint64) *GCSBuilder

WithKeyHashPNM creates a GCSBuilder with key derived from the specified chainhash.Hash and the passed probability and estimated filter size.

func WithKeyPM

func WithKeyPM(key [gcs.KeySize]byte, p uint8, m uint64) *GCSBuilder

WithKeyPM creates a GCSBuilder with specified key and the passed probability. Estimated filter size is set to zero, which means more reallocations are done when building the filter.

func WithKeyPNM

func WithKeyPNM(key [gcs.KeySize]byte, p uint8, n uint32, m uint64) *GCSBuilder

WithKeyPNM creates a GCSBuilder with specified key and the passed probability, modulus and estimated filter size.

func WithRandomKey

func WithRandomKey() *GCSBuilder

WithRandomKey creates a GCSBuilder with a cryptographically random key. Probability is set to 20 (2^-20 collision probability). Estimated filter size is set to zero, which means more reallocations are done when building the filter.

func WithRandomKeyPM

func WithRandomKeyPM(p uint8, m uint64) *GCSBuilder

WithRandomKeyPM creates a GCSBuilder with a cryptographically random key and the passed probability. Estimated filter size is set to zero, which means more reallocations are done when building the filter.

func WithRandomKeyPNM

func WithRandomKeyPNM(p uint8, n uint32, m uint64) *GCSBuilder

WithRandomKeyPNM creates a GCSBuilder with a cryptographically random key and the passed probability and estimated filter size.

func (*GCSBuilder) AddEntries

func (b *GCSBuilder) AddEntries(data [][]byte) *GCSBuilder

AddEntries adds all the []byte entries in a [][]byte to the list of entries to be included in the GCS filter when it's built.

func (*GCSBuilder) AddEntry

func (b *GCSBuilder) AddEntry(data []byte) *GCSBuilder

AddEntry adds a []byte to the list of entries to be included in the GCS filter when it's built.

func (*GCSBuilder) AddHash

func (b *GCSBuilder) AddHash(hash *chainhash.Hash) *GCSBuilder

AddHash adds a chainhash.Hash to the list of entries to be included in the GCS filter when it's built.

func (*GCSBuilder) AddWitness

func (b *GCSBuilder) AddWitness(witness wire.TxWitness) *GCSBuilder

AddWitness adds each item of the passed filter stack to the filter, and then adds each item as a script.

func (*GCSBuilder) Build

func (b *GCSBuilder) Build() (*gcs.Filter, error)

Build returns a function which builds a GCS filter with the given parameters and data.

func (*GCSBuilder) Key

func (b *GCSBuilder) Key() ([gcs.KeySize]byte, error)

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 (*GCSBuilder) Preallocate

func (b *GCSBuilder) Preallocate(n uint32) *GCSBuilder

Preallocate sets the estimated filter size after calling Builder() to reduce the probability of memory reallocations. If the builder has already had data added to it, Preallocate has no effect.

func (*GCSBuilder) SetKey

func (b *GCSBuilder) SetKey(key [gcs.KeySize]byte) *GCSBuilder

SetKey sets the key with which the builder will build a filter to the passed [gcs.KeySize]byte.

func (*GCSBuilder) SetKeyFromHash

func (b *GCSBuilder) SetKeyFromHash(keyHash *chainhash.Hash) *GCSBuilder

SetKeyFromHash sets the key with which the builder will build a filter to a key derived from the passed chainhash.Hash using DeriveKey().

func (*GCSBuilder) SetM

func (b *GCSBuilder) SetM(m uint64) *GCSBuilder

SetM sets the filter's modulous value after calling Builder().

func (*GCSBuilder) SetP

func (b *GCSBuilder) SetP(p uint8) *GCSBuilder

SetP sets the filter's probability after calling Builder().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL