Skip to content

Commit

Permalink
Merge pull request #161 from DeFiCh/fix/accounthistorycount
Browse files Browse the repository at this point in the history
Fix accounthistorycount count on wallet txs
  • Loading branch information
monstrobishi authored Jan 7, 2021
2 parents ab0b606 + d1eb2ce commit 578f4f7
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/masternodes/mn_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3577,7 +3577,7 @@ UniValue accounthistorycount(const JSONRPCRequest& request) {
UniValue ret(UniValue::VARR);

uint64_t count = 0;
const auto currentHeight = uint32_t(::ChainActive().Height() + 1);
const auto currentHeight = uint32_t(::ChainActive().Height());

auto shouldContinueToNextAccountHistory = [&](AccountHistoryKey const & key, CLazySerialize<AccountHistoryValue> valueLazy) -> bool {
if (!owner.empty() && owner != key.owner) {
Expand All @@ -3597,7 +3597,7 @@ UniValue accounthistorycount(const JSONRPCRequest& request) {
return true;
};

AccountHistoryKey startAccountKey{owner, currentHeight, 0};
AccountHistoryKey startAccountKey{owner, currentHeight, std::numeric_limits<uint32_t>::max()};

if (isMine) {
pcustomcsview->ForEachMineAccountHistory(shouldContinueToNextAccountHistory, startAccountKey);
Expand All @@ -3607,7 +3607,22 @@ UniValue accounthistorycount(const JSONRPCRequest& request) {

if (shouldSearchInWallet) {
auto incCount = [&count](COutputEntry const &) { ++count; return true; };
searchInWallet(pwallet, owner, [&](CWalletTx const *) -> bool {
searchInWallet(pwallet, owner, [&](CWalletTx const * pwtx) -> bool {
if (txs.count(pwtx->GetHash())) {
return true;
}

auto index = LookupBlockIndex(pwtx->hashBlock);

// Check we have index before progressing, wallet might be reindexing.
if (!index) {
return true;
}

if (index->height > currentHeight) {
return true;
}

return false;
}, incCount, incCount);
}
Expand Down

0 comments on commit 578f4f7

Please sign in to comment.