Skip to content

Commit 9141622

Browse files
committed
[rpc] Add abortrescan command to RPC interface.
1 parent 75a08e7 commit 9141622

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/wallet/rpcdump.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,31 @@ UniValue importprivkey(const JSONRPCRequest& request)
154154
return NullUniValue;
155155
}
156156

157+
UniValue abortrescan(const JSONRPCRequest& request)
158+
{
159+
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
160+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
161+
return NullUniValue;
162+
}
163+
164+
if (request.fHelp || request.params.size() > 0)
165+
throw std::runtime_error(
166+
"abortrescan\n"
167+
"\nStops current wallet rescan triggered e.g. by an importprivkey call.\n"
168+
"\nExamples:\n"
169+
"\nImport a private key\n"
170+
+ HelpExampleCli("importprivkey", "\"mykey\"") +
171+
"\nAbort the running wallet rescan\n"
172+
+ HelpExampleCli("abortrescan", "") +
173+
"\nAs a JSON-RPC call\n"
174+
+ HelpExampleRpc("abortrescan", "")
175+
);
176+
177+
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) return false;
178+
pwallet->AbortRescan();
179+
return true;
180+
}
181+
157182
void ImportAddress(CWallet*, const CBitcoinAddress& address, const std::string& strLabel);
158183
void ImportScript(CWallet* const pwallet, const CScript& script, const std::string& strLabel, bool isRedeemScript)
159184
{

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,6 +2914,7 @@ UniValue bumpfee(const JSONRPCRequest& request)
29142914
return result;
29152915
}
29162916

2917+
extern UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
29172918
extern UniValue dumpprivkey(const JSONRPCRequest& request); // in rpcdump.cpp
29182919
extern UniValue importprivkey(const JSONRPCRequest& request);
29192920
extern UniValue importaddress(const JSONRPCRequest& request);
@@ -2930,6 +2931,7 @@ static const CRPCCommand commands[] =
29302931
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, false, {"hexstring","options"} },
29312932
{ "hidden", "resendwallettransactions", &resendwallettransactions, true, {} },
29322933
{ "wallet", "abandontransaction", &abandontransaction, false, {"txid"} },
2934+
{ "wallet", "abortrescan", &abortrescan, false, {} },
29332935
{ "wallet", "addmultisigaddress", &addmultisigaddress, true, {"nrequired","keys","account"} },
29342936
{ "wallet", "addwitnessaddress", &addwitnessaddress, true, {"address"} },
29352937
{ "wallet", "backupwallet", &backupwallet, true, {"destination"} },

0 commit comments

Comments
 (0)