@@ -172,7 +172,13 @@ UniValue importprivkey(const JSONRPCRequest& request)
172
172
}
173
173
}
174
174
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
+ }
176
182
}
177
183
178
184
return NullUniValue;
@@ -310,7 +316,13 @@ UniValue importaddress(const JSONRPCRequest& request)
310
316
}
311
317
if (fRescan )
312
318
{
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
+ }
314
326
pwallet->ReacceptWalletTransactions ();
315
327
}
316
328
@@ -479,7 +491,13 @@ UniValue importpubkey(const JSONRPCRequest& request)
479
491
}
480
492
if (fRescan )
481
493
{
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
+ }
483
501
pwallet->ReacceptWalletTransactions ();
484
502
}
485
503
@@ -534,9 +552,11 @@ UniValue importwallet(const JSONRPCRequest& request)
534
552
int64_t nFilesize = std::max ((int64_t )1 , (int64_t )file.tellg ());
535
553
file.seekg (0 , file.beg );
536
554
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
538
558
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 );
540
560
std::string line;
541
561
std::getline (file, line);
542
562
if (line.empty () || line[0 ] == ' #' )
@@ -599,10 +619,17 @@ UniValue importwallet(const JSONRPCRequest& request)
599
619
}
600
620
}
601
621
file.close ();
602
- pwallet-> ShowProgress (" " , 100 ); // hide progress dialog in GUI
622
+ uiInterface. ShowProgress (" " , 100 , false ); // hide progress dialog in GUI
603
623
pwallet->UpdateTimeFirstKey (nTimeBegin);
604
624
}
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
+ }
606
633
pwallet->MarkDirty ();
607
634
608
635
if (!fGood )
@@ -1212,6 +1239,9 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
1212
1239
int64_t scannedTime = pwallet->RescanFromTime (nLowestTimestamp, reserver, true /* update */ );
1213
1240
pwallet->ReacceptWalletTransactions ();
1214
1241
1242
+ if (pwallet->IsAbortingRescan ()) {
1243
+ throw JSONRPCError (RPC_MISC_ERROR, " Rescan aborted by user." );
1244
+ }
1215
1245
if (scannedTime > nLowestTimestamp) {
1216
1246
std::vector<UniValue> results = response.getValues ();
1217
1247
response.clear ();
0 commit comments