@@ -784,14 +784,18 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
784
784
ChainstateManager* maybe_chainman = GetChainman (context, req);
785
785
if (!maybe_chainman) return false ;
786
786
ChainstateManager& chainman = *maybe_chainman;
787
+ decltype (chainman.ActiveHeight ()) active_height;
788
+ uint256 active_hash;
787
789
{
788
- auto process_utxos = [&vOutPoints, &outs, &hits](const CCoinsView& view, const CTxMemPool* mempool) {
790
+ auto process_utxos = [&vOutPoints, &outs, &hits, &active_height, &active_hash, &chainman ](const CCoinsView& view, const CTxMemPool* mempool) EXCLUSIVE_LOCKS_REQUIRED (chainman. GetMutex () ) {
789
791
for (const COutPoint& vOutPoint : vOutPoints) {
790
792
Coin coin;
791
793
bool hit = (!mempool || !mempool->isSpent (vOutPoint)) && view.GetCoin (vOutPoint, coin);
792
794
hits.push_back (hit);
793
795
if (hit) outs.emplace_back (std::move (coin));
794
796
}
797
+ active_height = chainman.ActiveHeight ();
798
+ active_hash = chainman.ActiveTip ()->GetBlockHash ();
795
799
};
796
800
797
801
if (fCheckMemPool ) {
@@ -819,7 +823,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
819
823
// serialize data
820
824
// use exact same output as mentioned in Bip64
821
825
CDataStream ssGetUTXOResponse (SER_NETWORK, PROTOCOL_VERSION);
822
- ssGetUTXOResponse << chainman. ActiveChain (). Height () << chainman. ActiveChain (). Tip ()-> GetBlockHash () << bitmap << outs;
826
+ ssGetUTXOResponse << active_height << active_hash << bitmap << outs;
823
827
std::string ssGetUTXOResponseString = ssGetUTXOResponse.str ();
824
828
825
829
req->WriteHeader (" Content-Type" , " application/octet-stream" );
@@ -829,7 +833,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
829
833
830
834
case RESTResponseFormat::HEX: {
831
835
CDataStream ssGetUTXOResponse (SER_NETWORK, PROTOCOL_VERSION);
832
- ssGetUTXOResponse << chainman. ActiveChain (). Height () << chainman. ActiveChain (). Tip ()-> GetBlockHash () << bitmap << outs;
836
+ ssGetUTXOResponse << active_height << active_hash << bitmap << outs;
833
837
std::string strHex = HexStr (ssGetUTXOResponse) + " \n " ;
834
838
835
839
req->WriteHeader (" Content-Type" , " text/plain" );
@@ -842,8 +846,8 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
842
846
843
847
// pack in some essentials
844
848
// use more or less the same output as mentioned in Bip64
845
- objGetUTXOResponse.pushKV (" chainHeight" , chainman. ActiveChain (). Height () );
846
- objGetUTXOResponse.pushKV (" chaintipHash" , chainman. ActiveChain (). Tip ()-> GetBlockHash () .GetHex ());
849
+ objGetUTXOResponse.pushKV (" chainHeight" , active_height );
850
+ objGetUTXOResponse.pushKV (" chaintipHash" , active_hash .GetHex ());
847
851
objGetUTXOResponse.pushKV (" bitmap" , bitmapStringRepresentation);
848
852
849
853
UniValue utxos (UniValue::VARR);
0 commit comments