Skip to content

Commit 6fb65b4

Browse files
committed
scripted-diff: rest/rpc: Use renamed EnsureAny*()
-BEGIN VERIFY SCRIPT- sed -i -E 's@Ensure([^(]+)(\((request\.|)context\))@EnsureAny\1\2@g' \ -- src/rest.cpp src/rpc/*.cpp -END VERIFY SCRIPT-
1 parent 1570c7e commit 6fb65b4

File tree

5 files changed

+80
-80
lines changed

5 files changed

+80
-80
lines changed

src/rest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static bool rest_headers(const std::any& context,
181181
headers.reserve(count);
182182
{
183183
LOCK(cs_main);
184-
ChainstateManager& chainman = EnsureChainman(context);
184+
ChainstateManager& chainman = EnsureAnyChainman(context);
185185
tip = chainman.ActiveChain().Tip();
186186
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
187187
while (pindex != nullptr && chainman.ActiveChain().Contains(pindex)) {
@@ -251,7 +251,7 @@ static bool rest_block(const std::any& context,
251251
CBlockIndex* tip = nullptr;
252252
{
253253
LOCK(cs_main);
254-
ChainstateManager& chainman = EnsureChainman(context);
254+
ChainstateManager& chainman = EnsureAnyChainman(context);
255255
tip = chainman.ActiveChain().Tip();
256256
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
257257
if (!pblockindex) {
@@ -538,7 +538,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
538538
std::string bitmapStringRepresentation;
539539
std::vector<bool> hits;
540540
bitmap.resize((vOutPoints.size() + 7) / 8);
541-
ChainstateManager& chainman = EnsureChainman(context);
541+
ChainstateManager& chainman = EnsureAnyChainman(context);
542542
{
543543
auto process_utxos = [&vOutPoints, &outs, &hits](const CCoinsView& view, const CTxMemPool& mempool) {
544544
for (const COutPoint& vOutPoint : vOutPoints) {
@@ -642,7 +642,7 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
642642
CBlockIndex* pblockindex = nullptr;
643643
{
644644
LOCK(cs_main);
645-
const CChain& active_chain = EnsureChainman(context).ActiveChain();
645+
const CChain& active_chain = EnsureAnyChainman(context).ActiveChain();
646646
if (blockheight > active_chain.Height()) {
647647
return RESTERR(req, HTTP_NOT_FOUND, "Block height out of range");
648648
}

src/rpc/blockchain.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ CTxMemPool& EnsureMemPool(const NodeContext& node)
8282

8383
CTxMemPool& EnsureAnyMemPool(const std::any& context)
8484
{
85-
return EnsureMemPool(EnsureNodeContext(context));
85+
return EnsureMemPool(EnsureAnyNodeContext(context));
8686
}
8787

8888
ChainstateManager& EnsureChainman(const std::any& ctx) {
@@ -100,7 +100,7 @@ ChainstateManager& EnsureChainman(const NodeContext& node)
100100

101101
ChainstateManager& EnsureAnyChainman(const std::any& context)
102102
{
103-
return EnsureChainman(EnsureNodeContext(context));
103+
return EnsureChainman(EnsureAnyNodeContext(context));
104104
}
105105

106106
CBlockPolicyEstimator& EnsureFeeEstimator(const std::any& ctx) {
@@ -117,7 +117,7 @@ CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node)
117117

118118
CBlockPolicyEstimator& EnsureAnyFeeEstimator(const std::any& context)
119119
{
120-
return EnsureFeeEstimator(EnsureNodeContext(context));
120+
return EnsureFeeEstimator(EnsureAnyNodeContext(context));
121121
}
122122

123123
/* Calculate the difficulty for a given block index.
@@ -227,7 +227,7 @@ static RPCHelpMan getblockcount()
227227
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
228228
{
229229
LOCK(cs_main);
230-
return EnsureChainman(request.context).ActiveChain().Height();
230+
return EnsureAnyChainman(request.context).ActiveChain().Height();
231231
},
232232
};
233233
}
@@ -246,7 +246,7 @@ static RPCHelpMan getbestblockhash()
246246
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
247247
{
248248
LOCK(cs_main);
249-
return EnsureChainman(request.context).ActiveChain().Tip()->GetBlockHash().GetHex();
249+
return EnsureAnyChainman(request.context).ActiveChain().Tip()->GetBlockHash().GetHex();
250250
},
251251
};
252252
}
@@ -427,7 +427,7 @@ static RPCHelpMan getdifficulty()
427427
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
428428
{
429429
LOCK(cs_main);
430-
return GetDifficulty(EnsureChainman(request.context).ActiveChain().Tip());
430+
return GetDifficulty(EnsureAnyChainman(request.context).ActiveChain().Tip());
431431
},
432432
};
433433
}
@@ -609,7 +609,7 @@ static RPCHelpMan getrawmempool()
609609
include_mempool_sequence = request.params[1].get_bool();
610610
}
611611

612-
return MempoolToJSON(EnsureMemPool(request.context), fVerbose, include_mempool_sequence);
612+
return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
613613
},
614614
};
615615
}
@@ -644,7 +644,7 @@ static RPCHelpMan getmempoolancestors()
644644

645645
uint256 hash = ParseHashV(request.params[0], "parameter 1");
646646

647-
const CTxMemPool& mempool = EnsureMemPool(request.context);
647+
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
648648
LOCK(mempool.cs);
649649

650650
CTxMemPool::txiter it = mempool.mapTx.find(hash);
@@ -708,7 +708,7 @@ static RPCHelpMan getmempooldescendants()
708708

709709
uint256 hash = ParseHashV(request.params[0], "parameter 1");
710710

711-
const CTxMemPool& mempool = EnsureMemPool(request.context);
711+
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
712712
LOCK(mempool.cs);
713713

714714
CTxMemPool::txiter it = mempool.mapTx.find(hash);
@@ -760,7 +760,7 @@ static RPCHelpMan getmempoolentry()
760760
{
761761
uint256 hash = ParseHashV(request.params[0], "parameter 1");
762762

763-
const CTxMemPool& mempool = EnsureMemPool(request.context);
763+
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
764764
LOCK(mempool.cs);
765765

766766
CTxMemPool::txiter it = mempool.mapTx.find(hash);
@@ -792,7 +792,7 @@ static RPCHelpMan getblockhash()
792792
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
793793
{
794794
LOCK(cs_main);
795-
const CChain& active_chain = EnsureChainman(request.context).ActiveChain();
795+
const CChain& active_chain = EnsureAnyChainman(request.context).ActiveChain();
796796

797797
int nHeight = request.params[0].get_int();
798798
if (nHeight < 0 || nHeight > active_chain.Height())
@@ -852,7 +852,7 @@ static RPCHelpMan getblockheader()
852852
const CBlockIndex* tip;
853853
{
854854
LOCK(cs_main);
855-
ChainstateManager& chainman = EnsureChainman(request.context);
855+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
856856
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
857857
tip = chainman.ActiveChain().Tip();
858858
}
@@ -977,7 +977,7 @@ static RPCHelpMan getblock()
977977
const CBlockIndex* tip;
978978
{
979979
LOCK(cs_main);
980-
ChainstateManager& chainman = EnsureChainman(request.context);
980+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
981981
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
982982
tip = chainman.ActiveChain().Tip();
983983

@@ -1020,7 +1020,7 @@ static RPCHelpMan pruneblockchain()
10201020
throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode.");
10211021

10221022
LOCK(cs_main);
1023-
ChainstateManager& chainman = EnsureChainman(request.context);
1023+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
10241024

10251025
int heightParam = request.params[0].get_int();
10261026
if (heightParam < 0)
@@ -1102,7 +1102,7 @@ static RPCHelpMan gettxoutsetinfo()
11021102
UniValue ret(UniValue::VOBJ);
11031103

11041104
CCoinsStats stats;
1105-
CChainState& active_chainstate = EnsureChainman(request.context).ActiveChainstate();
1105+
CChainState& active_chainstate = EnsureAnyChainman(request.context).ActiveChainstate();
11061106
active_chainstate.ForceFlushStateToDisk();
11071107

11081108
const CoinStatsHashType hash_type{request.params[0].isNull() ? CoinStatsHashType::HASH_SERIALIZED : ParseHashType(request.params[0].get_str())};
@@ -1114,7 +1114,7 @@ static RPCHelpMan gettxoutsetinfo()
11141114
coins_view = &active_chainstate.CoinsDB();
11151115
blockman = &active_chainstate.m_blockman;
11161116
}
1117-
NodeContext& node = EnsureNodeContext(request.context);
1117+
NodeContext& node = EnsureAnyNodeContext(request.context);
11181118
if (GetUTXOStats(coins_view, *blockman, stats, hash_type, node.rpc_interruption_point)) {
11191119
ret.pushKV("height", (int64_t)stats.nHeight);
11201120
ret.pushKV("bestblock", stats.hashBlock.GetHex());
@@ -1186,11 +1186,11 @@ static RPCHelpMan gettxout()
11861186
fMempool = request.params[2].get_bool();
11871187

11881188
Coin coin;
1189-
CChainState& active_chainstate = EnsureChainman(request.context).ActiveChainstate();
1189+
CChainState& active_chainstate = EnsureAnyChainman(request.context).ActiveChainstate();
11901190
CCoinsViewCache* coins_view = &active_chainstate.CoinsTip();
11911191

11921192
if (fMempool) {
1193-
const CTxMemPool& mempool = EnsureMemPool(request.context);
1193+
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
11941194
LOCK(mempool.cs);
11951195
CCoinsViewMemPool view(coins_view, mempool);
11961196
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) {
@@ -1242,7 +1242,7 @@ static RPCHelpMan verifychain()
12421242

12431243
LOCK(cs_main);
12441244

1245-
CChainState& active_chainstate = EnsureChainman(request.context).ActiveChainstate();
1245+
CChainState& active_chainstate = EnsureAnyChainman(request.context).ActiveChainstate();
12461246
return CVerifyDB().VerifyDB(Params(), active_chainstate, &active_chainstate.CoinsTip(), check_level, check_depth);
12471247
},
12481248
};
@@ -1370,7 +1370,7 @@ RPCHelpMan getblockchaininfo()
13701370
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
13711371
{
13721372
LOCK(cs_main);
1373-
ChainstateManager& chainman = EnsureChainman(request.context);
1373+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
13741374

13751375
const CBlockIndex* tip = chainman.ActiveChain().Tip();
13761376
CHECK_NONFATAL(tip);
@@ -1463,7 +1463,7 @@ static RPCHelpMan getchaintips()
14631463
},
14641464
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
14651465
{
1466-
ChainstateManager& chainman = EnsureChainman(request.context);
1466+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
14671467
LOCK(cs_main);
14681468

14691469
/*
@@ -1575,7 +1575,7 @@ static RPCHelpMan getmempoolinfo()
15751575
},
15761576
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
15771577
{
1578-
return MempoolInfoToJSON(EnsureMemPool(request.context));
1578+
return MempoolInfoToJSON(EnsureAnyMemPool(request.context));
15791579
},
15801580
};
15811581
}
@@ -1599,7 +1599,7 @@ static RPCHelpMan preciousblock()
15991599
uint256 hash(ParseHashV(request.params[0], "blockhash"));
16001600
CBlockIndex* pblockindex;
16011601

1602-
ChainstateManager& chainman = EnsureChainman(request.context);
1602+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
16031603
{
16041604
LOCK(cs_main);
16051605
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
@@ -1637,7 +1637,7 @@ static RPCHelpMan invalidateblock()
16371637
uint256 hash(ParseHashV(request.params[0], "blockhash"));
16381638
BlockValidationState state;
16391639

1640-
ChainstateManager& chainman = EnsureChainman(request.context);
1640+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
16411641
CBlockIndex* pblockindex;
16421642
{
16431643
LOCK(cs_main);
@@ -1676,7 +1676,7 @@ static RPCHelpMan reconsiderblock()
16761676
},
16771677
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
16781678
{
1679-
ChainstateManager& chainman = EnsureChainman(request.context);
1679+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
16801680
uint256 hash(ParseHashV(request.params[0], "blockhash"));
16811681

16821682
{
@@ -1727,7 +1727,7 @@ static RPCHelpMan getchaintxstats()
17271727
},
17281728
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
17291729
{
1730-
ChainstateManager& chainman = EnsureChainman(request.context);
1730+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
17311731
const CBlockIndex* pindex;
17321732
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
17331733

@@ -1910,7 +1910,7 @@ static RPCHelpMan getblockstats()
19101910
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
19111911
{
19121912
LOCK(cs_main);
1913-
ChainstateManager& chainman = EnsureChainman(request.context);
1913+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
19141914

19151915
CBlockIndex* pindex;
19161916
if (request.params[0].isNum()) {
@@ -2121,7 +2121,7 @@ static RPCHelpMan savemempool()
21212121
},
21222122
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
21232123
{
2124-
const CTxMemPool& mempool = EnsureMemPool(request.context);
2124+
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
21252125

21262126
if (!mempool.IsLoaded()) {
21272127
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
@@ -2313,14 +2313,14 @@ static RPCHelpMan scantxoutset()
23132313
CBlockIndex* tip;
23142314
{
23152315
LOCK(cs_main);
2316-
ChainstateManager& chainman = EnsureChainman(request.context);
2316+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
23172317
chainman.ActiveChainstate().ForceFlushStateToDisk();
23182318
pcursor = std::unique_ptr<CCoinsViewCursor>(chainman.ActiveChainstate().CoinsDB().Cursor());
23192319
CHECK_NONFATAL(pcursor);
23202320
tip = chainman.ActiveChain().Tip();
23212321
CHECK_NONFATAL(tip);
23222322
}
2323-
NodeContext& node = EnsureNodeContext(request.context);
2323+
NodeContext& node = EnsureAnyNodeContext(request.context);
23242324
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins, node.rpc_interruption_point);
23252325
result.pushKV("success", res);
23262326
result.pushKV("txouts", count);
@@ -2394,7 +2394,7 @@ static RPCHelpMan getblockfilter()
23942394
bool block_was_connected;
23952395
{
23962396
LOCK(cs_main);
2397-
block_index = EnsureChainman(request.context).m_blockman.LookupBlockIndex(block_hash);
2397+
block_index = EnsureAnyChainman(request.context).m_blockman.LookupBlockIndex(block_hash);
23982398
if (!block_index) {
23992399
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
24002400
}
@@ -2477,7 +2477,7 @@ static RPCHelpMan dumptxoutset()
24772477

24782478
FILE* file{fsbridge::fopen(temppath, "wb")};
24792479
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
2480-
NodeContext& node = EnsureNodeContext(request.context);
2480+
NodeContext& node = EnsureAnyNodeContext(request.context);
24812481
UniValue result = CreateUTXOSnapshot(node, node.chainman->ActiveChainstate(), afile);
24822482
fs::rename(temppath, path);
24832483

0 commit comments

Comments
 (0)