Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 2,426 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"end or [begin,end])"}, | "end or [begin,end])"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
"[scanobjects,...]"}, | "[scanobjects,...]"}, | ||||
}, | }, | ||||
RPCResult{ | RPCResult{ | ||||
"{\n" | "{\n" | ||||
" \"success\": true|false, (boolean) Whether the scan was " | |||||
"completed\n" | |||||
" \"txouts\": n, (numeric) The number of " | |||||
"unspent transaction outputs scanned\n" | |||||
" \"height\": n, (numeric) The current block " | |||||
"height (index)\n" | |||||
" \"bestblock\": \"hex\", (string) The hash of the " | |||||
"block at the tip of the chain\n" | |||||
" \"unspents\": [\n" | " \"unspents\": [\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\" : \"transactionid\", (string) The transaction id\n" | " \"txid\": \"hash\", (string) The transaction id\n" | ||||
" \"vout\": n, (numeric) the vout value\n" | " \"vout\": n, (numeric) The vout value\n" | ||||
" \"scriptPubKey\" : \"script\", (string) the script key\n" | " \"scriptPubKey\": \"script\", (string) The script key\n" | ||||
" \"desc\" : \"descriptor\", (string) A specialized " | " \"desc\": \"descriptor\", (string) A specialized " | ||||
"descriptor for the matched scriptPubKey\n" | "descriptor for the matched scriptPubKey\n" | ||||
" \"amount\" : x.xxx, (numeric) The total amount " | " \"amount\": x.xxx, (numeric) The total amount " | ||||
"in " + | "in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" of the unspent output\n" | " of the unspent output\n" | ||||
" \"height\" : n, (numeric) Height of the " | " \"height\": n, (numeric) Height of the " | ||||
"unspent transaction output\n" | "unspent transaction output\n" | ||||
" }\n" | " }\n" | ||||
" ,...], \n" | " ,...],\n" | ||||
" \"total_amount\" : x.xxx, (numeric) The total amount of " | " \"total_amount\": x.xxx, (numeric) The total amount of " | ||||
"all found unspent outputs in " + | "all found unspent outputs in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{""}, | RPCExamples{""}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (request.params[0].get_str() == "status") { | ||||
// Scan the unspent transaction output set for inputs | // Scan the unspent transaction output set for inputs | ||||
UniValue unspents(UniValue::VARR); | UniValue unspents(UniValue::VARR); | ||||
std::vector<CTxOut> input_txos; | std::vector<CTxOut> input_txos; | ||||
std::map<COutPoint, Coin> coins; | std::map<COutPoint, Coin> coins; | ||||
g_should_abort_scan = false; | g_should_abort_scan = false; | ||||
g_scan_progress = 0; | g_scan_progress = 0; | ||||
int64_t count = 0; | int64_t count = 0; | ||||
std::unique_ptr<CCoinsViewCursor> pcursor; | std::unique_ptr<CCoinsViewCursor> pcursor; | ||||
CBlockIndex *tip; | |||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
::ChainstateActive().ForceFlushStateToDisk(); | ::ChainstateActive().ForceFlushStateToDisk(); | ||||
pcursor = std::unique_ptr<CCoinsViewCursor>(pcoinsdbview->Cursor()); | pcursor = std::unique_ptr<CCoinsViewCursor>(pcoinsdbview->Cursor()); | ||||
assert(pcursor); | assert(pcursor); | ||||
tip = ::ChainActive().Tip(); | |||||
assert(tip); | |||||
} | } | ||||
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, | bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, | ||||
pcursor.get(), needles, coins); | pcursor.get(), needles, coins); | ||||
result.pushKV("success", res); | result.pushKV("success", res); | ||||
result.pushKV("searched_items", count); | result.pushKV("txouts", count); | ||||
result.pushKV("height", tip->nHeight); | |||||
result.pushKV("bestblock", tip->GetBlockHash().GetHex()); | |||||
for (const auto &it : coins) { | for (const auto &it : coins) { | ||||
const COutPoint &outpoint = it.first; | const COutPoint &outpoint = it.first; | ||||
const Coin &coin = it.second; | const Coin &coin = it.second; | ||||
const CTxOut &txo = coin.GetTxOut(); | const CTxOut &txo = coin.GetTxOut(); | ||||
input_txos.push_back(txo); | input_txos.push_back(txo); | ||||
total_in += txo.nValue; | total_in += txo.nValue; | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |