From 700c42b85d20e624bef4228eef062c93084efab5 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Thu, 27 Jul 2017 10:08:31 -0400 Subject: Add height, depth, and hash methods to the Chain interface And use them to remove uses of chainActive and mapBlockIndex in wallet code This commit does not change behavior. Co-authored-by: Ben Woosley --- src/wallet/rpcwallet.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/wallet/rpcwallet.cpp') diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 39c17743ec..c835d2928d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1607,7 +1607,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request) bool include_removed = (request.params[3].isNull() || request.params[3].get_bool()); - int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; + const Optional tip_height = locked_chain->getHeight(); + int depth = tip_height && pindex ? (1 + *tip_height - pindex->nHeight) : -1; UniValue transactions(UniValue::VARR); @@ -1638,8 +1639,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request) paltindex = paltindex->pprev; } - CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms]; - uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256(); + int last_height = tip_height ? *tip_height + 1 - target_confirms : -1; + uint256 lastblock = last_height >= 0 ? locked_chain->getBlockHash(last_height) : uint256(); UniValue ret(UniValue::VOBJ); ret.pushKV("transactions", transactions); -- cgit v1.2.3