diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -92,6 +92,21 @@ return fLabelFound; } +static const int64_t TIMESTAMP_MIN = 0; + +static void RescanWallet(CWallet &wallet, const WalletRescanReserver &reserver, + int64_t time_begin = TIMESTAMP_MIN, + bool update = true) { + int64_t scanned_time = wallet.RescanFromTime(time_begin, reserver, update); + if (wallet.IsAbortingRescan()) { + throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); + } else if (scanned_time > time_begin) { + throw JSONRPCError(RPC_WALLET_ERROR, + "Rescan was unable to fully rescan the blockchain. " + "Some transactions may be missing."); + } +} + UniValue importprivkey(const Config &config, const JSONRPCRequest &request) { CWallet *const pwallet = GetWalletForJSONRPCRequest(request); if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { @@ -192,16 +207,7 @@ } } if (fRescan) { - int64_t scanned_time = - pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > TIMESTAMP_MIN) { - throw JSONRPCError(RPC_WALLET_ERROR, - "Rescan was unable to fully rescan the " - "blockchain. Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver); } return NullUniValue; @@ -370,16 +376,7 @@ } } if (fRescan) { - int64_t scanned_time = - pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > TIMESTAMP_MIN) { - throw JSONRPCError(RPC_WALLET_ERROR, - "Rescan was unable to fully rescan the " - "blockchain. Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver); pwallet->ReacceptWalletTransactions(); } @@ -591,16 +588,7 @@ pwallet->LearnAllRelatedScripts(pubKey); } if (fRescan) { - int64_t scanned_time = - pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > TIMESTAMP_MIN) { - throw JSONRPCError(RPC_WALLET_ERROR, - "Rescan was unable to fully rescan the " - "blockchain. Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver); pwallet->ReacceptWalletTransactions(); } @@ -753,16 +741,7 @@ } // hide progress dialog in GUI uiInterface.ShowProgress("", 100, false); - int64_t scanned_time = - pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > nTimeBegin) { - throw JSONRPCError(RPC_WALLET_ERROR, - "Rescan was unable to fully rescan the blockchain. " - "Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */); pwallet->MarkDirty(); if (!fGood) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -56,8 +56,6 @@ static const bool DEFAULT_WALLETBROADCAST = true; static const bool DEFAULT_DISABLE_WALLET = false; -static const int64_t TIMESTAMP_MIN = 0; - class CBlockIndex; class CChainParams; class CCoinControl;