wallet: Track current scanning progress

This commit is contained in:
João Barbosa 2019-04-03 17:05:52 +01:00
parent 2ee811e693
commit 90e27abe37
2 changed files with 5 additions and 1 deletions

View file

@ -1798,8 +1798,9 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
} }
double progress_current = progress_begin; double progress_current = progress_begin;
while (block_height && !fAbortRescan && !chain().shutdownRequested()) { while (block_height && !fAbortRescan && !chain().shutdownRequested()) {
m_scanning_progress = (progress_current - progress_begin) / (progress_end - progress_begin);
if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) { if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100)))); ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
} }
if (GetTime() >= nNow + 60) { if (GetTime() >= nNow + 60) {
nNow = GetTime(); nNow = GetTime();

View file

@ -597,6 +597,7 @@ private:
std::atomic<bool> fAbortRescan{false}; std::atomic<bool> fAbortRescan{false};
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
std::atomic<int64_t> m_scanning_start{0}; std::atomic<int64_t> m_scanning_start{0};
std::atomic<double> m_scanning_progress{0};
std::mutex mutexScanning; std::mutex mutexScanning;
friend class WalletRescanReserver; friend class WalletRescanReserver;
@ -822,6 +823,7 @@ public:
bool IsAbortingRescan() { return fAbortRescan; } bool IsAbortingRescan() { return fAbortRescan; }
bool IsScanning() { return fScanningWallet; } bool IsScanning() { return fScanningWallet; }
int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; } int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; }
double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
/** /**
* keystore implementation * keystore implementation
@ -1244,6 +1246,7 @@ public:
return false; return false;
} }
m_wallet->m_scanning_start = GetTimeMillis(); m_wallet->m_scanning_start = GetTimeMillis();
m_wallet->m_scanning_progress = 0;
m_wallet->fScanningWallet = true; m_wallet->fScanningWallet = true;
m_could_reserve = true; m_could_reserve = true;
return true; return true;