Skip to content

Commit

Permalink
Merge pull request #716 from charlesrocket/backport-3784
Browse files Browse the repository at this point in the history
Merge #15730: rpc: Show scanning details in getwalletinfo
  • Loading branch information
charlesrocket committed Nov 6, 2020
2 parents d6a41d0 + 01dc45d commit 62a11ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2768,6 +2768,11 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
" }\n"
" ,...\n"
" ]\n"
" \"scanning\": (json object) current scanning details, or false if no scan is in progress\n"
" {\n"
" \"duration\" : xxxx (numeric) elapsed seconds since scan start\n"
" \"progress\" : x.xxxx, (numeric) scanning progress percentage [0.0, 1.0]\n"
" }\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getwalletinfo", "")
Expand Down Expand Up @@ -2821,6 +2826,14 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
}
obj.push_back(Pair("hdaccounts", accounts));
}
if (pwallet->IsScanning()) {
UniValue scanning(UniValue::VOBJ);
scanning.pushKV("duration", pwallet->ScanningDuration() / 1000);
scanning.pushKV("progress", pwallet->ScanningProgress());
obj.pushKV("scanning", scanning);
} else {
obj.pushKV("scanning", false);
}
return obj;
}

Expand Down
3 changes: 2 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
LOCK(cs_main);
gvp = GuessVerificationProgress(chainParams.TxData(), pindex);
}
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((gvp - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
m_scanning_progress = (gvp - dProgressStart) / (dProgressTip - dProgressStart);
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
}
if (GetTime() >= nNow + 60) {
nNow = GetTime();
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
private:
std::atomic<bool> fAbortRescan;
std::atomic<bool> fScanningWallet; //controlled by WalletRescanReserver
std::atomic<int64_t> m_scanning_start{0};
std::atomic<double> m_scanning_progress{0};
std::mutex mutexScanning;
friend class WalletRescanReserver;

Expand Down Expand Up @@ -977,6 +979,8 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
void AbortRescan() { fAbortRescan = true; }
bool IsAbortingRescan() { return fAbortRescan; }
bool IsScanning() { return fScanningWallet; }
int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; }
double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }

/**
* keystore implementation
Expand Down Expand Up @@ -1348,6 +1352,8 @@ class WalletRescanReserver
if (m_wallet->fScanningWallet) {
return false;
}
m_wallet->m_scanning_start = GetTimeMillis();
m_wallet->m_scanning_progress = 0;
m_wallet->fScanningWallet = true;
m_could_reserve = true;
return true;
Expand Down

0 comments on commit 62a11ca

Please sign in to comment.