40
40
41
41
#include < univalue.h>
42
42
43
- static void TxToJSON (const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
43
+ static void TxToJSON (const CTransaction& tx, const uint256 hashBlock, UniValue& entry, CChainState& active_chainstate )
44
44
{
45
45
// Call into TxToUniv() in bitcoin-common to decode the transaction hex.
46
46
//
@@ -53,10 +53,10 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue&
53
53
LOCK (cs_main);
54
54
55
55
entry.pushKV (" blockhash" , hashBlock.GetHex ());
56
- CBlockIndex* pindex = g_chainman .m_blockman .LookupBlockIndex (hashBlock);
56
+ CBlockIndex* pindex = active_chainstate .m_blockman .LookupBlockIndex (hashBlock);
57
57
if (pindex) {
58
- if (:: ChainActive () .Contains (pindex)) {
59
- entry.pushKV (" confirmations" , 1 + :: ChainActive () .Height () - pindex->nHeight );
58
+ if (active_chainstate. m_chain .Contains (pindex)) {
59
+ entry.pushKV (" confirmations" , 1 + active_chainstate. m_chain .Height () - pindex->nHeight );
60
60
entry.pushKV (" time" , pindex->GetBlockTime ());
61
61
entry.pushKV (" blocktime" , pindex->GetBlockTime ());
62
62
}
@@ -158,6 +158,7 @@ static RPCHelpMan getrawtransaction()
158
158
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
159
159
{
160
160
const NodeContext& node = EnsureNodeContext (request.context );
161
+ ChainstateManager& chainman = EnsureChainman (request.context );
161
162
162
163
bool in_active_chain = true ;
163
164
uint256 hash = ParseHashV (request.params [0 ], " parameter 1" );
@@ -178,11 +179,11 @@ static RPCHelpMan getrawtransaction()
178
179
LOCK (cs_main);
179
180
180
181
uint256 blockhash = ParseHashV (request.params [2 ], " parameter 3" );
181
- blockindex = g_chainman .m_blockman .LookupBlockIndex (blockhash);
182
+ blockindex = chainman .m_blockman .LookupBlockIndex (blockhash);
182
183
if (!blockindex) {
183
184
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block hash not found" );
184
185
}
185
- in_active_chain = :: ChainActive ().Contains (blockindex);
186
+ in_active_chain = chainman. ActiveChain ().Contains (blockindex);
186
187
}
187
188
188
189
bool f_txindex_ready = false ;
@@ -215,7 +216,7 @@ static RPCHelpMan getrawtransaction()
215
216
216
217
UniValue result (UniValue::VOBJ);
217
218
if (blockindex) result.pushKV (" in_active_chain" , in_active_chain);
218
- TxToJSON (*tx, hash_block, result);
219
+ TxToJSON (*tx, hash_block, result, chainman. ActiveChainstate () );
219
220
return result;
220
221
},
221
222
};
@@ -257,10 +258,11 @@ static RPCHelpMan gettxoutproof()
257
258
258
259
CBlockIndex* pblockindex = nullptr ;
259
260
uint256 hashBlock;
261
+ ChainstateManager& chainman = EnsureChainman (request.context );
260
262
if (!request.params [1 ].isNull ()) {
261
263
LOCK (cs_main);
262
264
hashBlock = ParseHashV (request.params [1 ], " blockhash" );
263
- pblockindex = g_chainman .m_blockman .LookupBlockIndex (hashBlock);
265
+ pblockindex = chainman .m_blockman .LookupBlockIndex (hashBlock);
264
266
if (!pblockindex) {
265
267
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
266
268
}
@@ -269,9 +271,9 @@ static RPCHelpMan gettxoutproof()
269
271
270
272
// Loop through txids and try to find which block they're in. Exit loop once a block is found.
271
273
for (const auto & tx : setTxids) {
272
- const Coin& coin = AccessByTxid (:: ChainstateActive ().CoinsTip (), tx);
274
+ const Coin& coin = AccessByTxid (chainman. ActiveChainstate ().CoinsTip (), tx);
273
275
if (!coin.IsSpent ()) {
274
- pblockindex = :: ChainActive ()[coin.nHeight ];
276
+ pblockindex = chainman. ActiveChain ()[coin.nHeight ];
275
277
break ;
276
278
}
277
279
}
@@ -290,7 +292,7 @@ static RPCHelpMan gettxoutproof()
290
292
if (!tx || hashBlock.IsNull ()) {
291
293
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Transaction not yet in block" );
292
294
}
293
- pblockindex = g_chainman .m_blockman .LookupBlockIndex (hashBlock);
295
+ pblockindex = chainman .m_blockman .LookupBlockIndex (hashBlock);
294
296
if (!pblockindex) {
295
297
throw JSONRPCError (RPC_INTERNAL_ERROR, " Transaction index corrupt" );
296
298
}
@@ -350,8 +352,9 @@ static RPCHelpMan verifytxoutproof()
350
352
351
353
LOCK (cs_main);
352
354
353
- const CBlockIndex* pindex = g_chainman.m_blockman .LookupBlockIndex (merkleBlock.header .GetHash ());
354
- if (!pindex || !::ChainActive ().Contains (pindex) || pindex->nTx == 0 ) {
355
+ ChainstateManager& chainman = EnsureChainman (request.context );
356
+ const CBlockIndex* pindex = chainman.m_blockman .LookupBlockIndex (merkleBlock.header .GetHash ());
357
+ if (!pindex || !chainman.ActiveChain ().Contains (pindex) || pindex->nTx == 0 ) {
355
358
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found in chain" );
356
359
}
357
360
@@ -678,7 +681,7 @@ static RPCHelpMan combinerawtransaction()
678
681
const CTxMemPool& mempool = EnsureMemPool (request.context );
679
682
LOCK (cs_main);
680
683
LOCK (mempool.cs );
681
- CCoinsViewCache &viewChain = :: ChainstateActive ().CoinsTip ();
684
+ CCoinsViewCache &viewChain = EnsureChainman (request. context ). ActiveChainstate ().CoinsTip ();
682
685
CCoinsViewMemPool viewMempool (&viewChain, mempool);
683
686
view.SetBackend (viewMempool); // temporarily switch cache backend to db+mempool view
684
687
@@ -949,7 +952,7 @@ static RPCHelpMan testmempoolaccept()
949
952
result_0.pushKV (" txid" , tx->GetHash ().GetHex ());
950
953
result_0.pushKV (" wtxid" , tx->GetWitnessHash ().GetHex ());
951
954
952
- const MempoolAcceptResult accept_result = WITH_LOCK (cs_main, return AcceptToMemoryPool (:: ChainstateActive (), mempool, std::move (tx),
955
+ const MempoolAcceptResult accept_result = WITH_LOCK (cs_main, return AcceptToMemoryPool (EnsureChainman (request. context ). ActiveChainstate (), mempool, std::move (tx),
953
956
false /* bypass_limits */ , /* test_accept */ true ));
954
957
955
958
// Only return the fee and vsize if the transaction would pass ATMP.
@@ -1600,7 +1603,7 @@ static RPCHelpMan utxoupdatepsbt()
1600
1603
{
1601
1604
const CTxMemPool& mempool = EnsureMemPool (request.context );
1602
1605
LOCK2 (cs_main, mempool.cs );
1603
- CCoinsViewCache &viewChain = :: ChainstateActive ().CoinsTip ();
1606
+ CCoinsViewCache &viewChain = EnsureChainman (request. context ). ActiveChainstate ().CoinsTip ();
1604
1607
CCoinsViewMemPool viewMempool (&viewChain, mempool);
1605
1608
view.SetBackend (viewMempool); // temporarily switch cache backend to db+mempool view
1606
1609
0 commit comments