@@ -149,7 +149,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
149
149
pwallet->UpdateTimeFirstKey (1 );
150
150
151
151
if (fRescan ) {
152
- pwallet->ScanForWalletTransactions (chainActive. Genesis () , true );
152
+ pwallet->RescanFromTime (TIMESTAMP_MIN , true /* update */ );
153
153
}
154
154
}
155
155
@@ -279,7 +279,7 @@ UniValue importaddress(const JSONRPCRequest& request)
279
279
280
280
if (fRescan )
281
281
{
282
- pwallet->ScanForWalletTransactions (chainActive. Genesis () , true );
282
+ pwallet->RescanFromTime (TIMESTAMP_MIN , true /* update */ );
283
283
pwallet->ReacceptWalletTransactions ();
284
284
}
285
285
@@ -437,7 +437,7 @@ UniValue importpubkey(const JSONRPCRequest& request)
437
437
438
438
if (fRescan )
439
439
{
440
- pwallet->ScanForWalletTransactions (chainActive. Genesis () , true );
440
+ pwallet->RescanFromTime (TIMESTAMP_MIN , true /* update */ );
441
441
pwallet->ReacceptWalletTransactions ();
442
442
}
443
443
@@ -537,11 +537,7 @@ UniValue importwallet(const JSONRPCRequest& request)
537
537
file.close ();
538
538
pwallet->ShowProgress (" " , 100 ); // hide progress dialog in GUI
539
539
pwallet->UpdateTimeFirstKey (nTimeBegin);
540
-
541
- CBlockIndex *pindex = chainActive.FindEarliestAtLeast (nTimeBegin - TIMESTAMP_WINDOW);
542
-
543
- LogPrintf (" Rescanning last %i blocks\n " , pindex ? chainActive.Height () - pindex->nHeight + 1 : 0 );
544
- pwallet->ScanForWalletTransactions (pindex);
540
+ pwallet->RescanFromTime (nTimeBegin - TIMESTAMP_WINDOW, false /* update */ );
545
541
pwallet->MarkDirty ();
546
542
547
543
if (!fGood )
@@ -1117,14 +1113,10 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
1117
1113
}
1118
1114
1119
1115
if (fRescan && fRunScan && requests.size ()) {
1120
- CBlockIndex* pindex = nLowestTimestamp > minimumTimestamp ? chainActive.FindEarliestAtLeast (std::max<int64_t >(nLowestTimestamp - TIMESTAMP_WINDOW, 0 )) : chainActive.Genesis ();
1121
- CBlockIndex* scanFailed = nullptr ;
1122
- if (pindex) {
1123
- scanFailed = pwallet->ScanForWalletTransactions (pindex, true );
1124
- pwallet->ReacceptWalletTransactions ();
1125
- }
1116
+ int64_t scannedTime = pwallet->RescanFromTime (nLowestTimestamp - TIMESTAMP_WINDOW, true /* update */ );
1117
+ pwallet->ReacceptWalletTransactions ();
1126
1118
1127
- if (scanFailed ) {
1119
+ if (scannedTime > nLowestTimestamp - TIMESTAMP_WINDOW ) {
1128
1120
std::vector<UniValue> results = response.getValues ();
1129
1121
response.clear ();
1130
1122
response.setArray ();
@@ -1134,7 +1126,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
1134
1126
// range, or if the import result already has an error set, let
1135
1127
// the result stand unmodified. Otherwise replace the result
1136
1128
// with an error message.
1137
- if (GetImportTimestamp (request, now) - TIMESTAMP_WINDOW > scanFailed-> GetBlockTimeMax () || results.at (i).exists (" error" )) {
1129
+ if (scannedTime <= GetImportTimestamp (request, now) - TIMESTAMP_WINDOW || results.at (i).exists (" error" )) {
1138
1130
response.push_back (results.at (i));
1139
1131
} else {
1140
1132
UniValue result = UniValue (UniValue::VOBJ);
@@ -1150,7 +1142,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
1150
1142
" caused by pruning or data corruption (see bitcoind log for details) and could "
1151
1143
" be dealt with by downloading and rescanning the relevant blocks (see -reindex "
1152
1144
" and -rescan options)." ,
1153
- GetImportTimestamp (request, now), scanFailed-> GetBlockTimeMax () , TIMESTAMP_WINDOW)));
1145
+ GetImportTimestamp (request, now), scannedTime - 1 , TIMESTAMP_WINDOW)));
1154
1146
response.push_back (std::move (result));
1155
1147
}
1156
1148
++i;
0 commit comments