aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/blockchain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r--src/rpc/blockchain.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index f2a1fd048f..2077723af5 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -709,10 +709,10 @@ UniValue getblockheader(const JSONRPCRequest& request)
if (!request.params[1].isNull())
fVerbose = request.params[1].get_bool();
- if (mapBlockIndex.count(hash) == 0)
+ const CBlockIndex* pblockindex = LookupBlockIndex(hash);
+ if (!pblockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
-
- CBlockIndex* pblockindex = mapBlockIndex[hash];
+ }
if (!fVerbose)
{
@@ -788,12 +788,12 @@ UniValue getblock(const JSONRPCRequest& request)
verbosity = request.params[1].get_bool() ? 1 : 0;
}
- if (mapBlockIndex.count(hash) == 0)
+ const CBlockIndex* pblockindex = LookupBlockIndex(hash);
+ if (!pblockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
+ }
CBlock block;
- CBlockIndex* pblockindex = mapBlockIndex[hash];
-
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
@@ -858,7 +858,7 @@ static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
stats.hashBlock = pcursor->GetBestBlock();
{
LOCK(cs_main);
- stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight;
+ stats.nHeight = LookupBlockIndex(stats.hashBlock)->nHeight;
}
ss << stats.hashBlock;
uint256 prevkey;
@@ -1041,8 +1041,7 @@ UniValue gettxout(const JSONRPCRequest& request)
}
}
- BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
- CBlockIndex *pindex = it->second;
+ const CBlockIndex* pindex = LookupBlockIndex(pcoinsTip->GetBestBlock());
ret.pushKV("bestblock", pindex->GetBlockHash().GetHex());
if (coin.nHeight == MEMPOOL_HEIGHT) {
ret.pushKV("confirmations", 0);
@@ -1436,10 +1435,10 @@ UniValue preciousblock(const JSONRPCRequest& request)
{
LOCK(cs_main);
- if (mapBlockIndex.count(hash) == 0)
+ pblockindex = LookupBlockIndex(hash);
+ if (!pblockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
-
- pblockindex = mapBlockIndex[hash];
+ }
}
CValidationState state;
@@ -1472,10 +1471,11 @@ UniValue invalidateblock(const JSONRPCRequest& request)
{
LOCK(cs_main);
- if (mapBlockIndex.count(hash) == 0)
+ CBlockIndex* pblockindex = LookupBlockIndex(hash);
+ if (!pblockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
+ }
- CBlockIndex* pblockindex = mapBlockIndex[hash];
InvalidateBlock(state, Params(), pblockindex);
}
@@ -1510,10 +1510,11 @@ UniValue reconsiderblock(const JSONRPCRequest& request)
{
LOCK(cs_main);
- if (mapBlockIndex.count(hash) == 0)
+ CBlockIndex* pblockindex = LookupBlockIndex(hash);
+ if (!pblockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
+ }
- CBlockIndex* pblockindex = mapBlockIndex[hash];
ResetBlockFailureFlags(pblockindex);
}
@@ -1560,11 +1561,10 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
} else {
uint256 hash = uint256S(request.params[1].get_str());
LOCK(cs_main);
- auto it = mapBlockIndex.find(hash);
- if (it == mapBlockIndex.end()) {
+ pindex = LookupBlockIndex(hash);
+ if (!pindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
}
- pindex = it->second;
if (!chainActive.Contains(pindex)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block is not in main chain");
}