@@ -86,6 +86,17 @@ static bool GetWalletAddressesForKey(CWallet * const pwallet, const CKeyID &keyi
8686 return fLabelFound ;
8787}
8888
89+ static const int64_t TIMESTAMP_MIN = 0 ;
90+
91+ static void RescanWallet (CWallet& wallet, const WalletRescanReserver& reserver, int64_t time_begin = TIMESTAMP_MIN, bool update = true )
92+ {
93+ int64_t scanned_time = wallet.RescanFromTime (time_begin, reserver, update);
94+ if (wallet.IsAbortingRescan ()) {
95+ throw JSONRPCError (RPC_MISC_ERROR, " Rescan aborted by user." );
96+ } else if (scanned_time > time_begin) {
97+ throw JSONRPCError (RPC_WALLET_ERROR, " Rescan was unable to fully rescan the blockchain. Some transactions may be missing." );
98+ }
99+ }
89100
90101UniValue importprivkey (const JSONRPCRequest& request)
91102{
@@ -172,13 +183,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
172183 }
173184 }
174185 if (fRescan ) {
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- }
186+ RescanWallet (*pwallet, reserver);
182187 }
183188
184189 return NullUniValue;
@@ -318,13 +323,7 @@ UniValue importaddress(const JSONRPCRequest& request)
318323 }
319324 if (fRescan )
320325 {
321- int64_t scanned_time = pwallet->RescanFromTime (TIMESTAMP_MIN, reserver, true /* update */ );
322- if (pwallet->IsAbortingRescan ()) {
323- throw JSONRPCError (RPC_MISC_ERROR, " Rescan aborted by user." );
324- }
325- if (scanned_time > TIMESTAMP_MIN) {
326- throw JSONRPCError (RPC_WALLET_ERROR, " Rescan was unable to fully rescan the blockchain. Some transactions may be missing." );
327- }
326+ RescanWallet (*pwallet, reserver);
328327 pwallet->ReacceptWalletTransactions ();
329328 }
330329
@@ -496,13 +495,7 @@ UniValue importpubkey(const JSONRPCRequest& request)
496495 }
497496 if (fRescan )
498497 {
499- int64_t scanned_time = pwallet->RescanFromTime (TIMESTAMP_MIN, reserver, true /* update */ );
500- if (pwallet->IsAbortingRescan ()) {
501- throw JSONRPCError (RPC_MISC_ERROR, " Rescan aborted by user." );
502- }
503- if (scanned_time > TIMESTAMP_MIN) {
504- throw JSONRPCError (RPC_WALLET_ERROR, " Rescan was unable to fully rescan the blockchain. Some transactions may be missing." );
505- }
498+ RescanWallet (*pwallet, reserver);
506499 pwallet->ReacceptWalletTransactions ();
507500 }
508501
@@ -630,13 +623,7 @@ UniValue importwallet(const JSONRPCRequest& request)
630623 pwallet->UpdateTimeFirstKey (nTimeBegin);
631624 }
632625 uiInterface.ShowProgress (" " , 100 , false ); // hide progress dialog in GUI
633- int64_t scanned_time = pwallet->RescanFromTime (nTimeBegin, reserver, false /* update */ );
634- if (pwallet->IsAbortingRescan ()) {
635- throw JSONRPCError (RPC_MISC_ERROR, " Rescan aborted by user." );
636- }
637- if (scanned_time > nTimeBegin) {
638- throw JSONRPCError (RPC_WALLET_ERROR, " Rescan was unable to fully rescan the blockchain. Some transactions may be missing." );
639- }
626+ RescanWallet (*pwallet, reserver, nTimeBegin, false /* update */ );
640627 pwallet->MarkDirty ();
641628
642629 if (!fGood )
0 commit comments