Skip to content

Commit 896520e

Browse files
kallewooffurszy
authored andcommitted
[rpc] Add abortrescan command to RPC interface.
1 parent ab41ad8 commit 896520e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/wallet/rpcdump.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ UniValue importprivkey(const JSONRPCRequest& request)
151151
return NullUniValue;
152152
}
153153

154+
UniValue abortrescan(const JSONRPCRequest& request)
155+
{
156+
if (request.fHelp || request.params.size() > 0)
157+
throw std::runtime_error(
158+
"abortrescan\n"
159+
"\nStops current wallet rescan triggered e.g. by an importprivkey call.\n"
160+
"\nExamples:\n"
161+
"\nImport a private key\n"
162+
+ HelpExampleCli("importprivkey", "\"mykey\"") +
163+
"\nAbort the running wallet rescan\n"
164+
+ HelpExampleCli("abortrescan", "") +
165+
"\nAs a JSON-RPC call\n"
166+
+ HelpExampleRpc("abortrescan", "")
167+
);
168+
169+
EnsureWallet();
170+
if (!pwalletMain->IsScanning() || pwalletMain->IsAbortingRescan()) return false;
171+
pwalletMain->AbortRescan();
172+
return true;
173+
}
174+
154175
void ImportAddress(const CTxDestination& dest, const std::string& strLabel, const std::string& strPurpose);
155176

156177
void ImportScript(const CScript& script, const std::string& strLabel, bool isRedeemScript)

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,6 +4239,7 @@ UniValue rescanblockchain(const JSONRPCRequest& request)
42394239
return response;
42404240
}
42414241

4242+
extern UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
42424243
extern UniValue dumpprivkey(const JSONRPCRequest& request); // in rpcdump.cpp
42434244
extern UniValue importprivkey(const JSONRPCRequest& request);
42444245
extern UniValue importaddress(const JSONRPCRequest& request);
@@ -4259,6 +4260,7 @@ static const CRPCCommand commands[] =
42594260
{ "wallet", "getaddressinfo", &getaddressinfo, true },
42604261
{ "wallet", "autocombinerewards", &autocombinerewards, false },
42614262
{ "wallet", "abandontransaction", &abandontransaction, false },
4263+
{ "wallet", "abortrescan", &abortrescan, false },
42624264
{ "wallet", "addmultisigaddress", &addmultisigaddress, true },
42634265
{ "wallet", "backupwallet", &backupwallet, true },
42644266
{ "wallet", "delegatestake", &delegatestake, false },

0 commit comments

Comments
 (0)