aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-02-26 16:35:56 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2018-02-26 16:51:20 +0100
commit228b086b9a3de02b534474027353a80dead2c292 (patch)
tree8216f04c1463d6de3e5ddb69f9dfdb4a4aa85f19 /src
parentd3f4dd313e5fe58903caf2f4d04827e7f7944e17 (diff)
parent57e6786203ad2f8beb0d2ff34b0ff7626bc7e877 (diff)
downloadbitcoin-228b086b9a3de02b534474027353a80dead2c292.tar.xz
Merge #12083: Improve getchaintxstats test coverage
57e6786 qa: Improve getchaintxstats functional test (João Barbosa) 501b439 rpc: Refactor blockhash parse in getchaintxstats (João Barbosa) Pull request description: Tree-SHA512: 61dec5cb68122998df7ec7b5239830f3caf0fe7185c107a66f27653ab2531a800db19a09050671b6fa8dbb5b53181da861eb31199c79d8635f246ccfa0d10efd
Diffstat (limited to 'src')
-rw-r--r--src/rpc/blockchain.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index f1352a13cf..8007cebc37 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1542,25 +1542,19 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
const CBlockIndex* pindex;
int blockcount = 30 * 24 * 60 * 60 / Params().GetConsensus().nPowTargetSpacing; // By default: 1 month
- bool havehash = !request.params[1].isNull();
- uint256 hash;
- if (havehash) {
- hash = uint256S(request.params[1].get_str());
- }
-
- {
+ if (request.params[1].isNull()) {
LOCK(cs_main);
- if (havehash) {
- auto it = mapBlockIndex.find(hash);
- if (it == mapBlockIndex.end()) {
- 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");
- }
- } else {
- pindex = chainActive.Tip();
+ pindex = chainActive.Tip();
+ } else {
+ uint256 hash = uint256S(request.params[1].get_str());
+ LOCK(cs_main);
+ auto it = mapBlockIndex.find(hash);
+ if (it == mapBlockIndex.end()) {
+ 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");
}
}