// MatchAndUpdate returns whether the transaction matches against the filter.
// When the tx contains any matching outputs, all these outputs are added to the
// filter as outpoints for matching further spends of these outputs.
// All matching outpoints are removed from the filter.
MatchAndUpdate returns whether the transaction matches against the filter.
When the tx contains any matching outputs, all these outputs are added to the
filter as outpoints for matching further spends of these outputs.
All matching outpoints are removed from the filter.
// MatchAndUpdate returns whether the transaction matches against the filter . // When the tx contains any matching outputs all these outputs are added to the // filter as outpoints for matching further spends of these outputs . // All matching outpoints are removed from the filter .
func (f *txFilter) MatchAndUpdate(tx *bchutil.Tx, params *chaincfg.Params) bool {
	matched := f.matchAll
	for _, txin := range tx.MsgTx().TxIn {
		if _, ok := f.outpoints[txin.PreviousOutPoint]; ok {
			delete(f.outpoints, txin.PreviousOutPoint)
			matched = true
		}
	}
	for txOutIdx, txout := range tx.MsgTx().TxOut {
		outputMatch := false
		_, addrs, _, _ := txscript.ExtractPkScriptAddrs(txout.PkScript, params)
		for _, addr := range addrs {
			switch a := addr.(type) {
			case *bchutil.AddressPubKeyHash:
				if _, ok := f.pubKeyHashes[*a.Hash160()]; !ok {
					continue
				}
			case *bchutil.AddressScriptHash:
				if _, ok := f.scriptHashes[*a.Hash160()]; !ok {
					continue
				}
			case *bchutil.AddressPubKey:
				found := false
				switch sa := a.ScriptAddress(); len(sa) {
				case 33: 
					var key [33]byte
					copy(key[:], sa)
					if _, ok := f.compressedPubKeys[key]; ok {
						found = true
					}
				case 65: 
					var key [65]byte
					copy(key[:], sa)
					if _, ok := f.uncompressedPubKeys[key]; ok {
						found = true
					}
				default:
					log.Warnf("Skipping rescanned pubkey of unknown "+
						"serialized length %d", len(sa))
					continue
				}
				if !found {
					pkh := a.AddressPubKeyHash()
					if _, ok := f.pubKeyHashes[*pkh.Hash160()]; !ok {
						continue
					}
				}
			default:
				addrStr := addr.EncodeAddress()
				_, ok := f.fallbacks[addrStr]
				if !ok {
					continue
				}
			}
			outputMatch = true
			break
		}
		dataElements, err := txscript.ExtractDataElements(txout.PkScript)
		if err == nil && len(dataElements) > 0 {
			for _, dataElement := range dataElements {
				_, ok := f.dataElements[hex.EncodeToString(dataElement)]
				if ok {
					outputMatch = true
					break
				}
			}
		}
		if outputMatch {
			outpoint := wire.OutPoint{
				Hash:  *tx.Hash(),
				Index: uint32(txOutIdx),
			}
			f.outpoints[outpoint] = struct{}{}
			matched = true
		}
	}
	return matched
}
func ( f * txFilter ) MatchAndUpdate ( tx * bchutil . Tx , params * chaincfg . Params ) bool { matched := f . matchAll for _ , txin := range tx . MsgTx ( ) . TxIn { if _ , ok := f . outpoints [ txin . PreviousOutPoint ] ; ok { delete ( f . outpoints , txin . PreviousOutPoint ) matched = true } } for txOutIdx , txout := range tx . MsgTx ( ) . TxOut { outputMatch := false _ , addrs , _ , _ := txscript . ExtractPkScriptAddrs ( txout . PkScript , params ) for _ , addr := range addrs { switch a := addr . ( type ) { case * bchutil . AddressPubKeyHash : if _ , ok := f . pubKeyHashes [ * a . Hash160 ( ) ] ; ! ok { continue } case * bchutil . AddressScriptHash : if _ , ok := f . scriptHashes [ * a . Hash160 ( ) ] ; ! ok { continue } case * bchutil . AddressPubKey : found := false switch sa := a . ScriptAddress ( ) ; len ( sa ) { case 33 : var key [ 33 ] byte copy ( key [ : ] , sa ) if _ , ok := f . compressedPubKeys [ key ] ; ok { found = true } case 65 : var key [ 65 ] byte copy ( key [ : ] , sa ) if _ , ok := f . uncompressedPubKeys [ key ] ; ok { found = true } default : log . Warnf ( " " + " " , len ( sa ) ) continue } if ! found { pkh := a . AddressPubKeyHash ( ) if _ , ok := f . pubKeyHashes [ * pkh . Hash160 ( ) ] ; ! ok { continue } } default : addrStr := addr . EncodeAddress ( ) _ , ok := f . fallbacks [ addrStr ] if ! ok { continue } } outputMatch = true break } dataElements , err := txscript . ExtractDataElements ( txout . PkScript ) if err == nil && len ( dataElements ) > 0 { for _ , dataElement := range dataElements { _ , ok := f . dataElements [ hex . EncodeToString ( dataElement ) ] if ok { outputMatch = true break } } } if outputMatch { outpoint := wire . OutPoint { Hash : * tx . Hash ( ) , Index : uint32 ( txOutIdx ) , } f . outpoints [ outpoint ] = struct { } { } matched = true } } return matched }
MatchAndUpdate returns whether the transaction matches against the filter.
MatchAndUpdate returns whether the transaction matches against the filter .
// We don't return early on a match because we prefer full processing: // - all matching outputs need to be added to the filter for later matching // - all matching inputs can be removed from the filter for later efficiency // Compressed // Uncompressed // If the transaction output pays to the pubkey of // a rescanned P2PKH address, include it as well. // A new address type must have been added.  Encode as a // payment address string and check the fallback map. // Matching address. // Matching output should be added to filter.