[moveonly] Extract RescanWallet to handle a simple rescan

Where the outcome does not depend on the result, apart from a simple
success check.
This commit is contained in:
Ben Woosley 2018-07-13 11:49:24 -04:00
parent b25a4c2284
commit 3fe836b78d
No known key found for this signature in database
GPG Key ID: 6EE5F3785F78B345
2 changed files with 15 additions and 30 deletions

View File

@ -86,6 +86,17 @@ static bool GetWalletAddressesForKey(CWallet * const pwallet, const CKeyID &keyi
return fLabelFound; 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 JSONRPCRequest& request) UniValue importprivkey(const JSONRPCRequest& request)
{ {
@ -172,13 +183,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
} }
} }
if (fRescan) { if (fRescan) {
int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); RescanWallet(*pwallet, reserver);
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.");
}
} }
return NullUniValue; return NullUniValue;
@ -318,13 +323,7 @@ UniValue importaddress(const JSONRPCRequest& request)
} }
if (fRescan) if (fRescan)
{ {
int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); RescanWallet(*pwallet, reserver);
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.");
}
pwallet->ReacceptWalletTransactions(); pwallet->ReacceptWalletTransactions();
} }
@ -496,13 +495,7 @@ UniValue importpubkey(const JSONRPCRequest& request)
} }
if (fRescan) if (fRescan)
{ {
int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); RescanWallet(*pwallet, reserver);
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.");
}
pwallet->ReacceptWalletTransactions(); pwallet->ReacceptWalletTransactions();
} }
@ -630,13 +623,7 @@ UniValue importwallet(const JSONRPCRequest& request)
pwallet->UpdateTimeFirstKey(nTimeBegin); pwallet->UpdateTimeFirstKey(nTimeBegin);
} }
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
int64_t scanned_time = pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */); RescanWallet(*pwallet, reserver, nTimeBegin, 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.");
}
pwallet->MarkDirty(); pwallet->MarkDirty();
if (!fGood) if (!fGood)

View File

@ -62,8 +62,6 @@ static const bool DEFAULT_WALLET_RBF = false;
static const bool DEFAULT_WALLETBROADCAST = true; static const bool DEFAULT_WALLETBROADCAST = true;
static const bool DEFAULT_DISABLE_WALLET = false; static const bool DEFAULT_DISABLE_WALLET = false;
static const int64_t TIMESTAMP_MIN = 0;
class CBlockIndex; class CBlockIndex;
class CCoinControl; class CCoinControl;
class COutput; class COutput;