Skip to content

Commit

Permalink
Merge #13658: [moveonly] Extract RescanWallet to handle a simple rescan
Browse files Browse the repository at this point in the history
Summary:
3fe836b [moveonly] Extract RescanWallet to handle a simple rescan (Ben Woosley)

Pull request description:

  Where the outcome does not depend on the result, apart from a simple
  success check.

Tree-SHA512: e0d29c6fc0c7f99a730289e5a80deb586b2848aead56b5198a71ef01f65374812468dfd57be0b8b076eb9be4090d5101d28d979a1d5c3d2f1caeca77b303e90e

Backport of Core PR12658
bitcoin/bitcoin#13658

Test Plan:
  make check
  ./bitcoin-qt -> help -> debug -> console -> rescanblockchain
  ./bitcoind
  ./bitcoin-cli rescanblockchain

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4020
  • Loading branch information
laanwj authored and Nico Guiton committed Sep 6, 2019
1 parent cbabd40 commit be3bf60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
59 changes: 19 additions & 40 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ bool GetWalletAddressesForKey(const Config &config, CWallet *const pwallet,
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)) {
Expand Down Expand Up @@ -192,16 +207,7 @@ UniValue importprivkey(const Config &config, const JSONRPCRequest &request) {
}
}
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;
Expand Down Expand Up @@ -370,16 +376,7 @@ UniValue importaddress(const Config &config, const JSONRPCRequest &request) {
}
}
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();
}

Expand Down Expand Up @@ -591,16 +588,7 @@ UniValue importpubkey(const Config &config, const JSONRPCRequest &request) {
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();
}

Expand Down Expand Up @@ -753,16 +741,7 @@ UniValue importwallet(const Config &config, const JSONRPCRequest &request) {
}
// 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) {
Expand Down
2 changes: 0 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ static const bool DEFAULT_AVOIDPARTIALSPENDS = false;
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;
Expand Down

0 comments on commit be3bf60

Please sign in to comment.