Ejemplo n.º 1
0
// ... or I'm gonna fade away
func (t *TxStore) GimmeFilter() (*bloom.Filter, error) {
	if len(t.Adrs) == 0 {
		return nil, fmt.Errorf("no address to filter for")
	}

	// get all utxos to add outpoints to filter
	allUtxos, err := t.GetAllUtxos()
	if err != nil {
		return nil, err
	}

	elem := uint32(len(t.Adrs) + len(allUtxos))
	f := bloom.NewFilter(elem, 0, 0.000001, wire.BloomUpdateAll)

	// note there could be false positives since we're just looking
	// for the 20 byte PKH without the opcodes.
	for _, a := range t.Adrs { // add 20-byte pubkeyhash
		f.Add(a.PkhAdr.ScriptAddress())
	}

	for _, u := range allUtxos {
		f.AddOutPoint(&u.Op)
	}

	return f, nil
}
Ejemplo n.º 2
0
func (ts *TxStore) Refilter() error {
	allUtxos, err := ts.GetAllUtxos()
	if err != nil {
		return err
	}
	filterElements := uint32(len(allUtxos) + len(ts.Adrs))

	ts.localFilter = bloom.NewFilter(filterElements, 0, 0, wire.BloomUpdateAll)

	for _, u := range allUtxos {
		ts.localFilter.AddOutPoint(&u.Op)
	}
	for _, a := range ts.Adrs {
		ts.localFilter.Add(a.PkhAdr.ScriptAddress())
	}

	msg := ts.localFilter.MsgFilterLoad()
	fmt.Printf("made %d element filter: %x\n", filterElements, msg.Filter)
	return nil
}