Skip to content

Commit b8736f1

Browse files
committed
Update getblockstats
- Fix segfault on genesis - Add powtype
1 parent b52220b commit b8736f1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/rpc/blockchain.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ UniValue getblockstats(const JSONRPCRequest& request)
313313
" \"ins\", (string) Selected statistic name\n"
314314
" \"outs\", (string) Selected statistic name\n"
315315
" \"subsidy\", (string) Selected statistic name\n"
316+
" \"powtype\", (string) Selected statistic name\n"
316317
" \"total_out\" (string) Selected statistic name\n"
317318
" ]\n"
318319
"\nResult:\n"
@@ -402,10 +403,13 @@ UniValue getblockstats(const JSONRPCRequest& request)
402403

403404
// Read block undo data to get input values
404405
CBlockUndo blockUndo;
405-
bool hasUndoData = UndoReadFromDisk(blockUndo, pindex->GetUndoPos(), pindex->pprev->GetBlockHash());
406-
if (!hasUndoData) {
407-
// If we can't read undo data, we'll calculate what we can without fees
408-
LogPrintf("Warning: Could not read block undo data for getblockstats\n");
406+
bool hasUndoData = false;
407+
if (pindex->pprev) {
408+
hasUndoData = UndoReadFromDisk(blockUndo, pindex->GetUndoPos(), pindex->pprev->GetBlockHash());
409+
if (!hasUndoData) {
410+
// If we can't read undo data, we'll calculate what we can without fees
411+
LogPrintf("Warning: Could not read block undo data for getblockstats\n");
412+
}
409413
}
410414

411415
// Process each transaction
@@ -535,6 +539,7 @@ UniValue getblockstats(const JSONRPCRequest& request)
535539
stats.push_back(Pair("avgfeerate", ValueFromAmount(avgfeerate)));
536540
stats.push_back(Pair("avgtxsize", avgtxsize));
537541
stats.push_back(Pair("blockhash", pindex->GetBlockHash().GetHex()));
542+
stats.push_back(Pair("powtype", pindex->GetBlockHeader().GetPoWTypeName()));
538543
stats.push_back(Pair("devfee", ValueFromAmount(devfee)));
539544
stats.push_back(Pair("feerate_percentiles", feerate_percentiles));
540545
stats.push_back(Pair("height", (int64_t)pindex->nHeight));

0 commit comments

Comments
 (0)