@@ -1875,9 +1875,9 @@ static RPCHelpMan getchaintxstats()
18751875 }
18761876 }
18771877
1878- const CBlockIndex* pindexPast = pindex->GetAncestor (pindex->nHeight - blockcount);
1879- int nTimeDiff = pindex->GetMedianTimePast () - pindexPast-> GetMedianTimePast ();
1880- int nTxDiff = pindex->nChainTx - pindexPast-> nChainTx ;
1878+ const CBlockIndex& past_block{* CHECK_NONFATAL ( pindex->GetAncestor (pindex->nHeight - blockcount))} ;
1879+ const int64_t nTimeDiff{ pindex->GetMedianTimePast () - past_block. GetMedianTimePast ()} ;
1880+ const int nTxDiff = pindex->nChainTx - past_block. nChainTx ;
18811881
18821882 UniValue ret (UniValue::VOBJ);
18831883 ret.pushKV (" time" , (int64_t )pindex->nTime );
@@ -2018,8 +2018,7 @@ static RPCHelpMan getblockstats()
20182018
20192019 ChainstateManager& chainman = EnsureAnyChainman (request.context );
20202020 LOCK (cs_main);
2021- const CBlockIndex* pindex{ParseHashOrHeight (request.params [0 ], chainman)};
2022- CHECK_NONFATAL (pindex != nullptr );
2021+ const CBlockIndex& pindex{*CHECK_NONFATAL (ParseHashOrHeight (request.params [0 ], chainman))};
20232022
20242023 std::set<std::string> stats;
20252024 if (!request.params [1 ].isNull ()) {
@@ -2030,8 +2029,8 @@ static RPCHelpMan getblockstats()
20302029 }
20312030 }
20322031
2033- const CBlock block = GetBlockChecked (chainman.m_blockman , pindex);
2034- const CBlockUndo blockUndo = GetUndoChecked (chainman.m_blockman , pindex);
2032+ const CBlock& block = GetBlockChecked (chainman.m_blockman , & pindex);
2033+ const CBlockUndo& blockUndo = GetUndoChecked (chainman.m_blockman , & pindex);
20352034
20362035 const bool do_all = stats.size () == 0 ; // Calculate everything if nothing selected (default)
20372036 const bool do_mediantxsize = do_all || stats.count (" mediantxsize" ) != 0 ;
@@ -2137,22 +2136,22 @@ static RPCHelpMan getblockstats()
21372136 ret_all.pushKV (" avgfee" , (block.vtx .size () > 1 ) ? totalfee / (block.vtx .size () - 1 ) : 0 );
21382137 ret_all.pushKV (" avgfeerate" , total_size ? totalfee / total_size : 0 ); // Unit: sat/byte
21392138 ret_all.pushKV (" avgtxsize" , (block.vtx .size () > 1 ) ? total_size / (block.vtx .size () - 1 ) : 0 );
2140- ret_all.pushKV (" blockhash" , pindex-> GetBlockHash ().GetHex ());
2139+ ret_all.pushKV (" blockhash" , pindex. GetBlockHash ().GetHex ());
21412140 ret_all.pushKV (" feerate_percentiles" , feerates_res);
2142- ret_all.pushKV (" height" , (int64_t )pindex-> nHeight );
2141+ ret_all.pushKV (" height" , (int64_t )pindex. nHeight );
21432142 ret_all.pushKV (" ins" , inputs);
21442143 ret_all.pushKV (" maxfee" , maxfee);
21452144 ret_all.pushKV (" maxfeerate" , maxfeerate);
21462145 ret_all.pushKV (" maxtxsize" , maxtxsize);
21472146 ret_all.pushKV (" medianfee" , CalculateTruncatedMedian (fee_array));
2148- ret_all.pushKV (" mediantime" , pindex-> GetMedianTimePast ());
2147+ ret_all.pushKV (" mediantime" , pindex. GetMedianTimePast ());
21492148 ret_all.pushKV (" mediantxsize" , CalculateTruncatedMedian (txsize_array));
21502149 ret_all.pushKV (" minfee" , (minfee == MAX_MONEY) ? 0 : minfee);
21512150 ret_all.pushKV (" minfeerate" , (minfeerate == MAX_MONEY) ? 0 : minfeerate);
21522151 ret_all.pushKV (" mintxsize" , mintxsize == MaxBlockSize () ? 0 : mintxsize);
21532152 ret_all.pushKV (" outs" , outputs);
2154- ret_all.pushKV (" subsidy" , GetBlockSubsidy (pindex, Params ().GetConsensus ()));
2155- ret_all.pushKV (" time" , pindex-> GetBlockTime ());
2153+ ret_all.pushKV (" subsidy" , GetBlockSubsidy (& pindex, Params ().GetConsensus ()));
2154+ ret_all.pushKV (" time" , pindex. GetBlockTime ());
21562155 ret_all.pushKV (" total_out" , total_out);
21572156 ret_all.pushKV (" total_size" , total_size);
21582157 ret_all.pushKV (" totalfee" , totalfee);
0 commit comments