Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 1,757 Lines • ▼ Show 20 Lines | UniValue getchaintxstats(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
const CBlockIndex *pindex; | const CBlockIndex *pindex; | ||||
// By default: 1 month | // By default: 1 month | ||||
int blockcount = 30 * 24 * 60 * 60 / | int blockcount = 30 * 24 * 60 * 60 / | ||||
config.GetChainParams().GetConsensus().nPowTargetSpacing; | config.GetChainParams().GetConsensus().nPowTargetSpacing; | ||||
bool havehash = !request.params[1].isNull(); | if (request.params[1].isNull()) { | ||||
uint256 hash; | LOCK(cs_main); | ||||
if (havehash) { | pindex = chainActive.Tip(); | ||||
hash = uint256S(request.params[1].get_str()); | } else { | ||||
} | uint256 hash = uint256S(request.params[1].get_str()); | ||||
{ | |||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (havehash) { | |||||
auto it = mapBlockIndex.find(hash); | auto it = mapBlockIndex.find(hash); | ||||
if (it == mapBlockIndex.end()) { | if (it == mapBlockIndex.end()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
"Block not found"); | |||||
} | } | ||||
pindex = it->second; | pindex = it->second; | ||||
if (!chainActive.Contains(pindex)) { | if (!chainActive.Contains(pindex)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Block is not in main chain"); | "Block is not in main chain"); | ||||
} | } | ||||
} else { | |||||
pindex = chainActive.Tip(); | |||||
} | |||||
} | } | ||||
assert(pindex != nullptr); | assert(pindex != nullptr); | ||||
if (request.params[0].isNull()) { | if (request.params[0].isNull()) { | ||||
blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1)); | blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1)); | ||||
} else { | } else { | ||||
blockcount = request.params[0].get_int(); | blockcount = request.params[0].get_int(); | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |