@@ -86,6 +86,17 @@ static bool GetWalletAddressesForKey(CWallet * const pwallet, const CKeyID &keyi
86
86
return fLabelFound ;
87
87
}
88
88
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
+ }
89
100
90
101
UniValue importprivkey (const JSONRPCRequest& request)
91
102
{
@@ -172,13 +183,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
172
183
}
173
184
}
174
185
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);
182
187
}
183
188
184
189
return NullUniValue;
@@ -318,13 +323,7 @@ UniValue importaddress(const JSONRPCRequest& request)
318
323
}
319
324
if (fRescan )
320
325
{
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);
328
327
pwallet->ReacceptWalletTransactions ();
329
328
}
330
329
@@ -496,13 +495,7 @@ UniValue importpubkey(const JSONRPCRequest& request)
496
495
}
497
496
if (fRescan )
498
497
{
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);
506
499
pwallet->ReacceptWalletTransactions ();
507
500
}
508
501
@@ -630,13 +623,7 @@ UniValue importwallet(const JSONRPCRequest& request)
630
623
pwallet->UpdateTimeFirstKey (nTimeBegin);
631
624
}
632
625
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 */ );
640
627
pwallet->MarkDirty ();
641
628
642
629
if (!fGood )
0 commit comments