MCPcopy Create free account
hub / github.com/ElementsProject/elements / IsRelevantAndUpdate

Method IsRelevantAndUpdate

src/common/bloom.cpp:94–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94bool 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;

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