Skip to content

Commit 2d41af1

Browse files
committed
Merge #13658: [moveonly] Extract RescanWallet to handle a simple rescan
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
2 parents 9f23c16 + 3fe836b commit 2d41af1

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

src/wallet/rpcdump.cpp

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

90101
UniValue 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)

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ static const bool DEFAULT_WALLET_RBF = false;
6464
static const bool DEFAULT_WALLETBROADCAST = true;
6565
static const bool DEFAULT_DISABLE_WALLET = false;
6666

67-
static const int64_t TIMESTAMP_MIN = 0;
68-
6967
class CBlockIndex;
7068
class CCoinControl;
7169
class COutput;

0 commit comments

Comments
 (0)