Skip to content

Commit 5f2a399

Browse files
committed
Merge #11200: Allow for aborting rescans in the GUI
ae1d2b0 Give an error when rescan is aborted by the user (Andrew Chow) 69b01e6 Add cancel button to rescan progress dialog (Andrew Chow) Pull request description: A cancel button is added to the `showProgress` dialog that is used only for rescans. When clicked, `AbortRescan` is called directly to cancel the rescan. Rescans triggered from the debug console will now be cancelable by clicking the cancel button. Rescans triggered by a command (e.g. `importmulti`) will now give an error indicating that the rescan was aborted by the user (either by the `abortrescan` command or by clicking cancel). Tree-SHA512: 4bb14998766de686e2318fbc9805758eccf5dbe628a7257d072c9ae2fb4f61303a0876f49988d6e5eddb261969b8a307c81c0c2df0a42ae909a43d738af3dc1b
2 parents 23e7fe8 + ae1d2b0 commit 5f2a399

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

src/interfaces/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class WalletImpl : public Wallet
130130
{
131131
return m_wallet.ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
132132
}
133+
void abortRescan() override { m_wallet.AbortRescan(); }
133134
bool backupWallet(const std::string& filename) override { return m_wallet.BackupWallet(filename); }
134135
std::string getWalletName() override { return m_wallet.GetName(); }
135136
bool getKeyFromPool(bool internal, CPubKey& pub_key) override

src/interfaces/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class Wallet
6565
virtual bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
6666
const SecureString& new_wallet_passphrase) = 0;
6767

68+
//! Abort a rescan.
69+
virtual void abortRescan() = 0;
70+
6871
//! Back up wallet.
6972
virtual bool backupWallet(const std::string& filename) = 0;
7073

src/qt/walletview.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ void WalletView::showProgress(const QString &title, int nProgress)
315315
progressDialog = new QProgressDialog(title, "", 0, 100);
316316
progressDialog->setWindowModality(Qt::ApplicationModal);
317317
progressDialog->setMinimumDuration(0);
318-
progressDialog->setCancelButton(0);
319318
progressDialog->setAutoClose(false);
320319
progressDialog->setValue(0);
320+
progressDialog->setCancelButtonText(tr("Cancel"));
321321
}
322322
else if (nProgress == 100)
323323
{
@@ -327,8 +327,13 @@ void WalletView::showProgress(const QString &title, int nProgress)
327327
progressDialog->deleteLater();
328328
}
329329
}
330-
else if (progressDialog)
331-
progressDialog->setValue(nProgress);
330+
else if (progressDialog) {
331+
if (progressDialog->wasCanceled()) {
332+
getWalletModel()->wallet().abortRescan();
333+
} else {
334+
progressDialog->setValue(nProgress);
335+
}
336+
}
332337
}
333338

334339
void WalletView::requestedSyncWarningInfo()

src/wallet/rpcdump.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ UniValue importprivkey(const JSONRPCRequest& request)
172172
}
173173
}
174174
if (fRescan) {
175-
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */);
175+
int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */);
176+
if (pwallet->IsAbortingRescan()) {
177+
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user.");
178+
}
179+
if (scanned_time > TIMESTAMP_MIN) {
180+
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing.");
181+
}
176182
}
177183

178184
return NullUniValue;
@@ -310,7 +316,13 @@ UniValue importaddress(const JSONRPCRequest& request)
310316
}
311317
if (fRescan)
312318
{
313-
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */);
319+
int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */);
320+
if (pwallet->IsAbortingRescan()) {
321+
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user.");
322+
}
323+
if (scanned_time > TIMESTAMP_MIN) {
324+
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing.");
325+
}
314326
pwallet->ReacceptWalletTransactions();
315327
}
316328

@@ -479,7 +491,13 @@ UniValue importpubkey(const JSONRPCRequest& request)
479491
}
480492
if (fRescan)
481493
{
482-
pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */);
494+
int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */);
495+
if (pwallet->IsAbortingRescan()) {
496+
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user.");
497+
}
498+
if (scanned_time > TIMESTAMP_MIN) {
499+
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing.");
500+
}
483501
pwallet->ReacceptWalletTransactions();
484502
}
485503

@@ -534,9 +552,11 @@ UniValue importwallet(const JSONRPCRequest& request)
534552
int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg());
535553
file.seekg(0, file.beg);
536554

537-
pwallet->ShowProgress(_("Importing..."), 0); // show progress dialog in GUI
555+
// Use uiInterface.ShowProgress instead of pwallet.ShowProgress because pwallet.ShowProgress has a cancel button tied to AbortRescan which
556+
// we don't want for this progress bar shoing the import progress. uiInterface.ShowProgress does not have a cancel button.
557+
uiInterface.ShowProgress(_("Importing..."), 0, false); // show progress dialog in GUI
538558
while (file.good()) {
539-
pwallet->ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100))));
559+
uiInterface.ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100))), false);
540560
std::string line;
541561
std::getline(file, line);
542562
if (line.empty() || line[0] == '#')
@@ -599,10 +619,17 @@ UniValue importwallet(const JSONRPCRequest& request)
599619
}
600620
}
601621
file.close();
602-
pwallet->ShowProgress("", 100); // hide progress dialog in GUI
622+
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
603623
pwallet->UpdateTimeFirstKey(nTimeBegin);
604624
}
605-
pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */);
625+
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
626+
int64_t scanned_time = pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */);
627+
if (pwallet->IsAbortingRescan()) {
628+
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user.");
629+
}
630+
if (scanned_time > nTimeBegin) {
631+
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing.");
632+
}
606633
pwallet->MarkDirty();
607634

608635
if (!fGood)
@@ -1212,6 +1239,9 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
12121239
int64_t scannedTime = pwallet->RescanFromTime(nLowestTimestamp, reserver, true /* update */);
12131240
pwallet->ReacceptWalletTransactions();
12141241

1242+
if (pwallet->IsAbortingRescan()) {
1243+
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user.");
1244+
}
12151245
if (scannedTime > nLowestTimestamp) {
12161246
std::vector<UniValue> results = response.getValues();
12171247
response.clear();

0 commit comments

Comments
 (0)