@@ -181,13 +181,14 @@ static bool rest_headers(const std::any& context,
181
181
headers.reserve (count);
182
182
{
183
183
LOCK (cs_main);
184
- tip = ::ChainActive ().Tip ();
185
- const CBlockIndex* pindex = g_chainman.m_blockman .LookupBlockIndex (hash);
186
- while (pindex != nullptr && ::ChainActive ().Contains (pindex)) {
184
+ ChainstateManager& chainman = EnsureChainman (context);
185
+ tip = chainman.ActiveChain ().Tip ();
186
+ const CBlockIndex* pindex = chainman.m_blockman .LookupBlockIndex (hash);
187
+ while (pindex != nullptr && chainman.ActiveChain ().Contains (pindex)) {
187
188
headers.push_back (pindex);
188
189
if (headers.size () == (unsigned long )count)
189
190
break ;
190
- pindex = :: ChainActive ().Next (pindex);
191
+ pindex = chainman. ActiveChain ().Next (pindex);
191
192
}
192
193
}
193
194
@@ -250,8 +251,9 @@ static bool rest_block(const std::any& context,
250
251
CBlockIndex* tip = nullptr ;
251
252
{
252
253
LOCK (cs_main);
253
- tip = ::ChainActive ().Tip ();
254
- pblockindex = g_chainman.m_blockman .LookupBlockIndex (hash);
254
+ ChainstateManager& chainman = EnsureChainman (context);
255
+ tip = chainman.ActiveChain ().Tip ();
256
+ pblockindex = chainman.m_blockman .LookupBlockIndex (hash);
255
257
if (!pblockindex) {
256
258
return RESTERR (req, HTTP_NOT_FOUND, hashStr + " not found" );
257
259
}
@@ -536,6 +538,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
536
538
std::string bitmapStringRepresentation;
537
539
std::vector<bool > hits;
538
540
bitmap.resize ((vOutPoints.size () + 7 ) / 8 );
541
+ ChainstateManager& chainman = EnsureChainman (context);
539
542
{
540
543
auto process_utxos = [&vOutPoints, &outs, &hits](const CCoinsView& view, const CTxMemPool& mempool) {
541
544
for (const COutPoint& vOutPoint : vOutPoints) {
@@ -551,12 +554,12 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
551
554
if (!mempool) return false ;
552
555
// use db+mempool as cache backend in case user likes to query mempool
553
556
LOCK2 (cs_main, mempool->cs );
554
- CCoinsViewCache& viewChain = :: ChainstateActive ().CoinsTip ();
557
+ CCoinsViewCache& viewChain = chainman. ActiveChainstate ().CoinsTip ();
555
558
CCoinsViewMemPool viewMempool (&viewChain, *mempool);
556
559
process_utxos (viewMempool, *mempool);
557
560
} else {
558
561
LOCK (cs_main); // no need to lock mempool!
559
- process_utxos (:: ChainstateActive ().CoinsTip (), CTxMemPool ());
562
+ process_utxos (chainman. ActiveChainstate ().CoinsTip (), CTxMemPool ());
560
563
}
561
564
562
565
for (size_t i = 0 ; i < hits.size (); ++i) {
@@ -571,7 +574,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
571
574
// serialize data
572
575
// use exact same output as mentioned in Bip64
573
576
CDataStream ssGetUTXOResponse (SER_NETWORK, PROTOCOL_VERSION);
574
- ssGetUTXOResponse << :: ChainActive ().Height () << :: ChainActive ().Tip ()->GetBlockHash () << bitmap << outs;
577
+ ssGetUTXOResponse << chainman. ActiveChain ().Height () << chainman. ActiveChain ().Tip ()->GetBlockHash () << bitmap << outs;
575
578
std::string ssGetUTXOResponseString = ssGetUTXOResponse.str ();
576
579
577
580
req->WriteHeader (" Content-Type" , " application/octet-stream" );
@@ -581,7 +584,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
581
584
582
585
case RetFormat::HEX: {
583
586
CDataStream ssGetUTXOResponse (SER_NETWORK, PROTOCOL_VERSION);
584
- ssGetUTXOResponse << :: ChainActive ().Height () << :: ChainActive ().Tip ()->GetBlockHash () << bitmap << outs;
587
+ ssGetUTXOResponse << chainman. ActiveChain ().Height () << chainman. ActiveChain ().Tip ()->GetBlockHash () << bitmap << outs;
585
588
std::string strHex = HexStr (ssGetUTXOResponse) + " \n " ;
586
589
587
590
req->WriteHeader (" Content-Type" , " text/plain" );
@@ -594,8 +597,8 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
594
597
595
598
// pack in some essentials
596
599
// use more or less the same output as mentioned in Bip64
597
- objGetUTXOResponse.pushKV (" chainHeight" , :: ChainActive ().Height ());
598
- objGetUTXOResponse.pushKV (" chaintipHash" , :: ChainActive ().Tip ()->GetBlockHash ().GetHex ());
600
+ objGetUTXOResponse.pushKV (" chainHeight" , chainman. ActiveChain ().Height ());
601
+ objGetUTXOResponse.pushKV (" chaintipHash" , chainman. ActiveChain ().Tip ()->GetBlockHash ().GetHex ());
599
602
objGetUTXOResponse.pushKV (" bitmap" , bitmapStringRepresentation);
600
603
601
604
UniValue utxos (UniValue::VARR);
@@ -639,10 +642,11 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
639
642
CBlockIndex* pblockindex = nullptr ;
640
643
{
641
644
LOCK (cs_main);
642
- if (blockheight > ::ChainActive ().Height ()) {
645
+ const CChain& active_chain = EnsureChainman (context).ActiveChain ();
646
+ if (blockheight > active_chain.Height ()) {
643
647
return RESTERR (req, HTTP_NOT_FOUND, " Block height out of range" );
644
648
}
645
- pblockindex = :: ChainActive () [blockheight];
649
+ pblockindex = active_chain [blockheight];
646
650
}
647
651
switch (rf) {
648
652
case RetFormat::BINARY: {
0 commit comments