Skip to content

Commit a9aa5d0

Browse files
committed
rpc: remove remnant BlockIndex global invocations
1 parent bcc25dc commit a9aa5d0

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
@@ -964,8 +964,10 @@ static UniValue getblockheaders(const JSONRPCRequest& request)
964964
std::string strHash = request.params[0].get_str();
965965
uint256 hash(uint256S(strHash));
966966

967-
if (::BlockIndex().count(hash) == 0)
967+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
968+
if (!pblockindex) {
968969
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
970+
}
969971

970972
int nCount = MAX_HEADERS_RESULTS;
971973
if (!request.params[1].isNull())
@@ -978,8 +980,6 @@ static UniValue getblockheaders(const JSONRPCRequest& request)
978980
if (!request.params[2].isNull())
979981
fVerbose = request.params[2].get_bool();
980982

981-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
982-
983983
UniValue arrHeaders(UniValue::VARR);
984984

985985
if (!fVerbose)
@@ -1063,7 +1063,8 @@ static UniValue getmerkleblocks(const JSONRPCRequest& request)
10631063
std::string strHash = request.params[1].get_str();
10641064
uint256 hash(uint256S(strHash));
10651065

1066-
if (::BlockIndex().count(hash) == 0) {
1066+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
1067+
if (!pblockindex) {
10671068
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
10681069
}
10691070

@@ -1075,7 +1076,6 @@ static UniValue getmerkleblocks(const JSONRPCRequest& request)
10751076
throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range");
10761077
}
10771078

1078-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
10791079
CBlock block = GetBlockChecked(pblockindex);
10801080

10811081
UniValue arrMerkleBlocks(UniValue::VARR);
@@ -2150,13 +2150,11 @@ static UniValue getblockstats(const JSONRPCRequest& request)
21502150
pindex = ::ChainActive()[height];
21512151
} else {
21522152
const uint256 hash = ParseHashV(request.params[0], "parameter 1");
2153-
if (::BlockIndex().count(hash) == 0)
2153+
2154+
pindex = LookupBlockIndex(hash);
2155+
if (!pindex) {
21542156
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2155-
pindex = ::BlockIndex()[hash];
2156-
// pindex = LookupBlockIndex(hash);
2157-
// if (!pindex) {
2158-
// throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2159-
// }
2157+
}
21602158
if (!::ChainActive().Contains(pindex)) {
21612159
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Block is not in chain %s", Params().NetworkIDString()));
21622160
}
@@ -2385,11 +2383,11 @@ static UniValue getspecialtxes(const JSONRPCRequest& request)
23852383
throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbosity must be in range 0..2");
23862384
}
23872385
}
2388-
2389-
if (::BlockIndex().count(hash) == 0)
2386+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
2387+
if (!pblockindex) {
23902388
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2389+
}
23912390

2392-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
23932391
const CBlock block = GetBlockChecked(pblockindex);
23942392

23952393
int nTxNum = 0;

0 commit comments

Comments
 (0)