Skip to content

Commit d0b1984

Browse files
committed
rpc: remove remnant BlockIndex global invocations
1 parent da5db57 commit d0b1984

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

910-
if (::BlockIndex().count(hash) == 0)
910+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
911+
if (!pblockindex) {
911912
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
913+
}
912914

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

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

928928
if (!fVerbose)
@@ -1001,7 +1001,8 @@ static UniValue getmerkleblocks(const JSONRPCRequest& request)
10011001
std::string strHash = request.params[1].get_str();
10021002
uint256 hash(uint256S(strHash));
10031003

1004-
if (::BlockIndex().count(hash) == 0) {
1004+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
1005+
if (!pblockindex) {
10051006
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
10061007
}
10071008

@@ -1013,7 +1014,6 @@ static UniValue getmerkleblocks(const JSONRPCRequest& request)
10131014
throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range");
10141015
}
10151016

1016-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
10171017
CBlock block = GetBlockChecked(pblockindex);
10181018

10191019
UniValue arrMerkleBlocks(UniValue::VARR);
@@ -2060,13 +2060,11 @@ static UniValue getblockstats(const JSONRPCRequest& request)
20602060
pindex = ::ChainActive()[height];
20612061
} else {
20622062
const uint256 hash = ParseHashV(request.params[0], "parameter 1");
2063-
if (::BlockIndex().count(hash) == 0)
2063+
2064+
pindex = LookupBlockIndex(hash);
2065+
if (!pindex) {
20642066
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2065-
pindex = ::BlockIndex()[hash];
2066-
// pindex = LookupBlockIndex(hash);
2067-
// if (!pindex) {
2068-
// throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2069-
// }
2067+
}
20702068
if (!::ChainActive().Contains(pindex)) {
20712069
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Block is not in chain %s", Params().NetworkIDString()));
20722070
}
@@ -2290,11 +2288,11 @@ static UniValue getspecialtxes(const JSONRPCRequest& request)
22902288
throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbosity must be in range 0..2");
22912289
}
22922290
}
2293-
2294-
if (::BlockIndex().count(hash) == 0)
2291+
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
2292+
if (!pblockindex) {
22952293
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2294+
}
22962295

2297-
CBlockIndex* pblockindex = ::BlockIndex()[hash];
22982296
const CBlock block = GetBlockChecked(pblockindex);
22992297

23002298
int nTxNum = 0;

0 commit comments

Comments
 (0)