Skip to content

Commit 7f2cfae

Browse files
committed
rpc: remove remnant BlockIndex global invocations
1 parent 761305d commit 7f2cfae

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/rpc/blockchain.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,10 @@ static UniValue getblockheaders(const JSONRPCRequest& request)
908908
std::string strHash = request.params[0].get_str();
909909
uint256 hash(uint256S(strHash));
910910

911-
if (::BlockIndex().count(hash) == 0)
911+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
912+
if (!pblockindex) {
912913
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
914+
}
913915

914916
int nCount = MAX_HEADERS_RESULTS;
915917
if (!request.params[1].isNull())
@@ -922,8 +924,6 @@ static UniValue getblockheaders(const JSONRPCRequest& request)
922924
if (!request.params[2].isNull())
923925
fVerbose = request.params[2].get_bool();
924926

925-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
926-
927927
UniValue arrHeaders(UniValue::VARR);
928928

929929
if (!fVerbose)
@@ -1015,7 +1015,8 @@ static UniValue getmerkleblocks(const JSONRPCRequest& request)
10151015
std::string strHash = request.params[1].get_str();
10161016
uint256 hash(uint256S(strHash));
10171017

1018-
if (::BlockIndex().count(hash) == 0) {
1018+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
1019+
if (!pblockindex) {
10191020
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
10201021
}
10211022

@@ -1027,7 +1028,6 @@ static UniValue getmerkleblocks(const JSONRPCRequest& request)
10271028
throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range");
10281029
}
10291030

1030-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
10311031
CBlock block = GetBlockChecked(pblockindex);
10321032

10331033
UniValue arrMerkleBlocks(UniValue::VARR);
@@ -2073,13 +2073,11 @@ static UniValue getblockstats(const JSONRPCRequest& request)
20732073
pindex = ::ChainActive()[height];
20742074
} else {
20752075
const uint256 hash = ParseHashV(request.params[0], "parameter 1");
2076-
if (::BlockIndex().count(hash) == 0)
2076+
2077+
pindex = LookupBlockIndex(hash);
2078+
if (!pindex) {
20772079
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2078-
pindex = ::BlockIndex()[hash];
2079-
// pindex = LookupBlockIndex(hash);
2080-
// if (!pindex) {
2081-
// throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2082-
// }
2080+
}
20832081
if (!::ChainActive().Contains(pindex)) {
20842082
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Block is not in chain %s", Params().NetworkIDString()));
20852083
}
@@ -2296,11 +2294,11 @@ static UniValue getspecialtxes(const JSONRPCRequest& request)
22962294
throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbosity must be in range 0..2");
22972295
}
22982296
}
2299-
2300-
if (::BlockIndex().count(hash) == 0)
2297+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
2298+
if (!pblockindex) {
23012299
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2300+
}
23022301

2303-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
23042302
const CBlock block = GetBlockChecked(pblockindex);
23052303

23062304
int nTxNum = 0;

0 commit comments

Comments
 (0)