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

Function FindScriptPubKey

src/rpc/blockchain.cpp:2603–2630  ·  view source on GitHub ↗

Search for a given set of pubkey scripts

Source from the content-addressed store, hash-verified

2601namespace {
2602//! Search for a given set of pubkey scripts
2603bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>& should_abort, int64_t& count, CCoinsViewCursor* cursor, const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results, std::function<void()>& interruption_point)
2604{
2605 scan_progress = 0;
2606 count = 0;
2607 while (cursor->Valid()) {
2608 COutPoint key;
2609 Coin coin;
2610 if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
2611 if (++count % 8192 == 0) {
2612 interruption_point();
2613 if (should_abort) {
2614 // allow to abort the scan via the abort reference
2615 return false;
2616 }
2617 }
2618 if (count % 256 == 0) {
2619 // update progress reference every 256 item
2620 uint32_t high = 0x100 * *key.hash.begin() + *(key.hash.begin() + 1);
2621 scan_progress = (int)(high * 100.0 / 65536.0 + 0.5);
2622 }
2623 if (needles.count(coin.out.scriptPubKey)) {
2624 out_results.emplace(key, coin);
2625 }
2626 cursor->Next();
2627 }
2628 scan_progress = 100;
2629 return true;
2630}
2631} // namespace
2632
2633/** RAII object to prevent concurrency issue when scanning the txout set */

Callers 1

scantxoutsetFunction · 0.85

Calls 6

countMethod · 0.80
ValidMethod · 0.45
GetKeyMethod · 0.45
GetValueMethod · 0.45
beginMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected