Skip to content

Commit ae1d2b0

Browse files
committed
Give an error when rescan is aborted by the user
1 parent 69b01e6 commit ae1d2b0

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/wallet/rpcdump.cpp

Lines changed: 32 additions & 4 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

@@ -604,7 +622,14 @@ UniValue importwallet(const JSONRPCRequest& request)
604622
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
605623
pwallet->UpdateTimeFirstKey(nTimeBegin);
606624
}
607-
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+
}
608633
pwallet->MarkDirty();
609634

610635
if (!fGood)
@@ -1214,6 +1239,9 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
12141239
int64_t scannedTime = pwallet->RescanFromTime(nLowestTimestamp, reserver, true /* update */);
12151240
pwallet->ReacceptWalletTransactions();
12161241

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

0 commit comments

Comments
 (0)