MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / IsRelevantAndUpdate

Method IsRelevantAndUpdate

src/common/bloom.cpp:95–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

SendMessagesMethod · 0.80
CMerkleBlockMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
FUZZ_TARGETFunction · 0.80

Calls 9

insertFunction · 0.85
SolverFunction · 0.85
GetOpMethod · 0.80
COutPointClass · 0.70
emptyMethod · 0.45
GetHashMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.64
FUZZ_TARGETFunction · 0.64