Skip to content

Commit 08bb4c3

Browse files
committed
Merge #16285: rpc: Improve scantxoutset response and help message
bdd6a4f qa: Check scantxoutset result against gettxoutsetinfo (João Barbosa) fc0c410 rpc: Improve scantxoutset response and help message (João Barbosa) Pull request description: The new response keys `height` and `bestblock` allow the client to know at what point the scan took place. The help message now has all the response keys (`result` and `txouts` were missing) and it's improved a bit. Note that `searched_items` key is renamed to `txouts`, considering `scantxoutset` is marked experimental. ACKs for top commit: laanwj: ACK bdd6a4f Tree-SHA512: 6bb7c3464b19857b756b8bc491ab7c58b0d948aad8c005b26ed27c55a1278f5639217e11a315bb505b4f44ebe86f413068c1e539c8a5f7a4007735586cc6443c
2 parents 91fcb9f + bdd6a4f commit 08bb4c3

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/rpc/blockchain.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,17 +2064,21 @@ UniValue scantxoutset(const JSONRPCRequest& request)
20642064
},
20652065
RPCResult{
20662066
"{\n"
2067+
" \"success\": true|false, (boolean) Whether the scan was completed\n"
2068+
" \"txouts\": n, (numeric) The number of unspent transaction outputs scanned\n"
2069+
" \"height\": n, (numeric) The current block height (index)\n"
2070+
" \"bestblock\": \"hex\", (string) The hash of the block at the tip of the chain\n"
20672071
" \"unspents\": [\n"
2068-
" {\n"
2069-
" \"txid\" : \"transactionid\", (string) The transaction id\n"
2070-
" \"vout\": n, (numeric) the vout value\n"
2071-
" \"scriptPubKey\" : \"script\", (string) the script key\n"
2072-
" \"desc\" : \"descriptor\", (string) A specialized descriptor for the matched scriptPubKey\n"
2073-
" \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " of the unspent output\n"
2074-
" \"height\" : n, (numeric) Height of the unspent transaction output\n"
2072+
" {\n"
2073+
" \"txid\": \"hash\", (string) The transaction id\n"
2074+
" \"vout\": n, (numeric) The vout value\n"
2075+
" \"scriptPubKey\": \"script\", (string) The script key\n"
2076+
" \"desc\": \"descriptor\", (string) A specialized descriptor for the matched scriptPubKey\n"
2077+
" \"amount\": x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " of the unspent output\n"
2078+
" \"height\": n, (numeric) Height of the unspent transaction output\n"
20752079
" }\n"
2076-
" ,...], \n"
2077-
" \"total_amount\" : x.xxx, (numeric) The total amount of all found unspent outputs in " + CURRENCY_UNIT + "\n"
2080+
" ,...],\n"
2081+
" \"total_amount\": x.xxx, (numeric) The total amount of all found unspent outputs in " + CURRENCY_UNIT + "\n"
20782082
"]\n"
20792083
},
20802084
RPCExamples{""},
@@ -2128,15 +2132,20 @@ UniValue scantxoutset(const JSONRPCRequest& request)
21282132
g_scan_progress = 0;
21292133
int64_t count = 0;
21302134
std::unique_ptr<CCoinsViewCursor> pcursor;
2135+
CBlockIndex* tip;
21312136
{
21322137
LOCK(cs_main);
21332138
::ChainstateActive().ForceFlushStateToDisk();
21342139
pcursor = std::unique_ptr<CCoinsViewCursor>(::ChainstateActive().CoinsDB().Cursor());
21352140
assert(pcursor);
2141+
tip = ::ChainActive().Tip();
2142+
assert(tip);
21362143
}
21372144
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins);
21382145
result.pushKV("success", res);
2139-
result.pushKV("searched_items", count);
2146+
result.pushKV("txouts", count);
2147+
result.pushKV("height", tip->nHeight);
2148+
result.pushKV("bestblock", tip->GetBlockHash().GetHex());
21402149

21412150
for (const auto& it : coins) {
21422151
const COutPoint& outpoint = it.first;

test/functional/rpc_scantxoutset.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def run_test(self):
5858
self.start_node(0)
5959
self.nodes[0].generate(110)
6060

61+
scan = self.nodes[0].scantxoutset("start", [])
62+
info = self.nodes[0].gettxoutsetinfo()
63+
assert_equal(scan['success'], True)
64+
assert_equal(scan['height'], info['height'])
65+
assert_equal(scan['txouts'], info['txouts'])
66+
assert_equal(scan['bestblock'], info['bestblock'])
67+
6168
self.restart_node(0, ['-nowallet'])
6269
self.log.info("Test if we have found the non HD unspent outputs.")
6370
assert_equal(self.nodes[0].scantxoutset("start", [ "pkh(" + pubk1 + ")", "pkh(" + pubk2 + ")", "pkh(" + pubk3 + ")"])['total_amount'], Decimal("0.002"))

0 commit comments

Comments
 (0)