mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Add FindScriptPubKey() to search the UTXO set
This commit is contained in:
parent
56f69360dc
commit
9048575511
1 changed files with 29 additions and 0 deletions
|
@ -1916,6 +1916,35 @@ static UniValue savemempool(const JSONRPCRequest& request)
|
|||
return NullUniValue;
|
||||
}
|
||||
|
||||
//! Search for a given set of pubkey scripts
|
||||
bool 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) {
|
||||
scan_progress = 0;
|
||||
count = 0;
|
||||
while (cursor->Valid()) {
|
||||
COutPoint key;
|
||||
Coin coin;
|
||||
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
|
||||
if (++count % 8192 == 0) {
|
||||
boost::this_thread::interruption_point();
|
||||
if (should_abort) {
|
||||
// allow to abort the scan via the abort reference
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (count % 256 == 0) {
|
||||
// update progress reference every 256 item
|
||||
uint32_t high = 0x100 * *key.hash.begin() + *(key.hash.begin() + 1);
|
||||
scan_progress = (int)(high * 100.0 / 65536.0 + 0.5);
|
||||
}
|
||||
if (needles.count(coin.out.scriptPubKey)) {
|
||||
out_results.emplace(key, coin);
|
||||
}
|
||||
cursor->Next();
|
||||
}
|
||||
scan_progress = 100;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
{ // category name actor (function) argNames
|
||||
// --------------------- ------------------------ ----------------------- ----------
|
||||
|
|
Loading…
Reference in a new issue