Skip to content

Commit 9048575

Browse files
committed
Add FindScriptPubKey() to search the UTXO set
1 parent 56f6936 commit 9048575

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/rpc/blockchain.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,35 @@ static UniValue savemempool(const JSONRPCRequest& request)
19161916
return NullUniValue;
19171917
}
19181918

1919+
//! Search for a given set of pubkey scripts
1920+
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) {
1921+
scan_progress = 0;
1922+
count = 0;
1923+
while (cursor->Valid()) {
1924+
COutPoint key;
1925+
Coin coin;
1926+
if (!cursor->GetKey(key) || !cursor->GetValue(coin)) return false;
1927+
if (++count % 8192 == 0) {
1928+
boost::this_thread::interruption_point();
1929+
if (should_abort) {
1930+
// allow to abort the scan via the abort reference
1931+
return false;
1932+
}
1933+
}
1934+
if (count % 256 == 0) {
1935+
// update progress reference every 256 item
1936+
uint32_t high = 0x100 * *key.hash.begin() + *(key.hash.begin() + 1);
1937+
scan_progress = (int)(high * 100.0 / 65536.0 + 0.5);
1938+
}
1939+
if (needles.count(coin.out.scriptPubKey)) {
1940+
out_results.emplace(key, coin);
1941+
}
1942+
cursor->Next();
1943+
}
1944+
scan_progress = 100;
1945+
return true;
1946+
}
1947+
19191948
static const CRPCCommand commands[] =
19201949
{ // category name actor (function) argNames
19211950
// --------------------- ------------------------ ----------------------- ----------

0 commit comments

Comments
 (0)