| 92 | } |
| 93 | |
| 94 | bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx) |
| 95 | { |
| 96 | bool fFound = false; |
| 97 | // Match if the filter contains the hash of tx |
| 98 | // for finding tx when they appear in a block |
| 99 | if (vData.empty()) // zero-size = "match-all" filter |
| 100 | return true; |
| 101 | const uint256& hash = tx.GetHash(); |
| 102 | if (contains(hash)) |
| 103 | fFound = true; |
| 104 | |
| 105 | for (unsigned int i = 0; i < tx.vout.size(); i++) |
| 106 | { |
| 107 | const CTxOut& txout = tx.vout[i]; |
| 108 | // Match if the filter contains any arbitrary script data element in any scriptPubKey in tx |
| 109 | // If this matches, also add the specific output that was matched. |
| 110 | // This means clients don't have to update the filter themselves when a new relevant tx |
| 111 | // is discovered in order to find spending transactions, which avoids round-tripping and race conditions. |
| 112 | CScript::const_iterator pc = txout.scriptPubKey.begin(); |
| 113 | std::vector<unsigned char> data; |
| 114 | while (pc < txout.scriptPubKey.end()) |
| 115 | { |
| 116 | opcodetype opcode; |
| 117 | if (!txout.scriptPubKey.GetOp(pc, opcode, data)) |
| 118 | break; |
| 119 | if (data.size() != 0 && contains(data)) |
| 120 | { |
| 121 | fFound = true; |
| 122 | if ((nFlags & BLOOM_UPDATE_MASK) == BLOOM_UPDATE_ALL) |
| 123 | insert(COutPoint(hash, i)); |
| 124 | else if ((nFlags & BLOOM_UPDATE_MASK) == BLOOM_UPDATE_P2PUBKEY_ONLY) |
| 125 | { |
| 126 | std::vector<std::vector<unsigned char> > vSolutions; |
| 127 | TxoutType type = Solver(txout.scriptPubKey, vSolutions); |
| 128 | if (type == TxoutType::PUBKEY || type == TxoutType::MULTISIG) { |
| 129 | insert(COutPoint(hash, i)); |
| 130 | } |
| 131 | } |
| 132 | break; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (fFound) |
| 138 | return true; |
| 139 | |
| 140 | for (const CTxIn& txin : tx.vin) |
| 141 | { |
| 142 | // Match if the filter contains an outpoint tx spends |
| 143 | if (contains(txin.prevout)) |
| 144 | return true; |
| 145 | |
| 146 | // Match if the filter contains any arbitrary script data element in any scriptSig in tx |
| 147 | CScript::const_iterator pc = txin.scriptSig.begin(); |
| 148 | std::vector<unsigned char> data; |
| 149 | while (pc < txin.scriptSig.end()) |
| 150 | { |
| 151 | opcodetype opcode; |