mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
rpc: Refactor blockhash parse in getchaintxstats
This commit is contained in:
parent
3fa556aee2
commit
501b43921c
1 changed files with 12 additions and 18 deletions
|
@ -1542,25 +1542,19 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
|
||||||
const CBlockIndex* pindex;
|
const CBlockIndex* pindex;
|
||||||
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
|
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
|
||||||
|
|
||||||
bool havehash = !request.params[1].isNull();
|
if (request.params[1].isNull()) {
|
||||||
uint256 hash;
|
|
||||||
if (havehash) {
|
|
||||||
hash = uint256S(request.params[1].get_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
if (havehash) {
|
pindex = chainActive.Tip();
|
||||||
auto it = mapBlockIndex.find(hash);
|
} else {
|
||||||
if (it == mapBlockIndex.end()) {
|
uint256 hash = uint256S(request.params[1].get_str());
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
LOCK(cs_main);
|
||||||
}
|
auto it = mapBlockIndex.find(hash);
|
||||||
pindex = it->second;
|
if (it == mapBlockIndex.end()) {
|
||||||
if (!chainActive.Contains(pindex)) {
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block is not in main chain");
|
}
|
||||||
}
|
pindex = it->second;
|
||||||
} else {
|
if (!chainActive.Contains(pindex)) {
|
||||||
pindex = chainActive.Tip();
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block is not in main chain");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue