Skip to content

Commit fad889c

Browse files
author
MarcoFalke
committed
wallet: Make RPC help compile-time static
1 parent 7a24cca commit fad889c

File tree

3 files changed

+218
-212
lines changed

3 files changed

+218
-212
lines changed

src/wallet/rpcdump.cpp

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver,
9292

9393
UniValue importprivkey(const JSONRPCRequest& request)
9494
{
95-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
96-
if (!wallet) return NullUniValue;
97-
CWallet* const pwallet = wallet.get();
98-
9995
RPCHelpMan{"importprivkey",
10096
"\nAdds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup.\n"
10197
"Hint: use importmulti to import more than one private key.\n"
@@ -122,6 +118,10 @@ UniValue importprivkey(const JSONRPCRequest& request)
122118
},
123119
}.Check(request);
124120

121+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
122+
if (!wallet) return NullUniValue;
123+
CWallet* const pwallet = wallet.get();
124+
125125
if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
126126
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled");
127127
}
@@ -193,10 +193,6 @@ UniValue importprivkey(const JSONRPCRequest& request)
193193

194194
UniValue abortrescan(const JSONRPCRequest& request)
195195
{
196-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
197-
if (!wallet) return NullUniValue;
198-
CWallet* const pwallet = wallet.get();
199-
200196
RPCHelpMan{"abortrescan",
201197
"\nStops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n"
202198
"Note: Use \"getwalletinfo\" to query the scanning progress.\n",
@@ -212,17 +208,17 @@ UniValue abortrescan(const JSONRPCRequest& request)
212208
},
213209
}.Check(request);
214210

211+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
212+
if (!wallet) return NullUniValue;
213+
CWallet* const pwallet = wallet.get();
214+
215215
if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) return false;
216216
pwallet->AbortRescan();
217217
return true;
218218
}
219219

220220
UniValue importaddress(const JSONRPCRequest& request)
221221
{
222-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
223-
if (!wallet) return NullUniValue;
224-
CWallet* const pwallet = wallet.get();
225-
226222
RPCHelpMan{"importaddress",
227223
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
228224
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
@@ -249,6 +245,10 @@ UniValue importaddress(const JSONRPCRequest& request)
249245
},
250246
}.Check(request);
251247

248+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
249+
if (!wallet) return NullUniValue;
250+
CWallet* const pwallet = wallet.get();
251+
252252
EnsureLegacyScriptPubKeyMan(*pwallet, true);
253253

254254
std::string strLabel;
@@ -319,10 +319,6 @@ UniValue importaddress(const JSONRPCRequest& request)
319319

320320
UniValue importprunedfunds(const JSONRPCRequest& request)
321321
{
322-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
323-
if (!wallet) return NullUniValue;
324-
CWallet* const pwallet = wallet.get();
325-
326322
RPCHelpMan{"importprunedfunds",
327323
"\nImports funds without rescan. Corresponding address or script must previously be included in wallet. Aimed towards pruned wallets. The end-user is responsible to import additional transactions that subsequently spend the imported outputs or rescan after the point in the blockchain the transaction is included.\n",
328324
{
@@ -333,6 +329,10 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
333329
RPCExamples{""},
334330
}.Check(request);
335331

332+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
333+
if (!wallet) return NullUniValue;
334+
CWallet* const pwallet = wallet.get();
335+
336336
CMutableTransaction tx;
337337
if (!DecodeHexTx(tx, request.params[0].get_str()))
338338
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
@@ -375,10 +375,6 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
375375

376376
UniValue removeprunedfunds(const JSONRPCRequest& request)
377377
{
378-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
379-
if (!wallet) return NullUniValue;
380-
CWallet* const pwallet = wallet.get();
381-
382378
RPCHelpMan{"removeprunedfunds",
383379
"\nDeletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet balances.\n",
384380
{
@@ -392,6 +388,10 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
392388
},
393389
}.Check(request);
394390

391+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
392+
if (!wallet) return NullUniValue;
393+
CWallet* const pwallet = wallet.get();
394+
395395
LOCK(pwallet->cs_wallet);
396396

397397
uint256 hash(ParseHashV(request.params[0], "txid"));
@@ -412,10 +412,6 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
412412

413413
UniValue importpubkey(const JSONRPCRequest& request)
414414
{
415-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
416-
if (!wallet) return NullUniValue;
417-
CWallet* const pwallet = wallet.get();
418-
419415
RPCHelpMan{"importpubkey",
420416
"\nAdds a public key (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
421417
"Hint: use importmulti to import more than one public key.\n"
@@ -438,6 +434,10 @@ UniValue importpubkey(const JSONRPCRequest& request)
438434
},
439435
}.Check(request);
440436

437+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
438+
if (!wallet) return NullUniValue;
439+
CWallet* const pwallet = wallet.get();
440+
441441
EnsureLegacyScriptPubKeyMan(*wallet, true);
442442

443443
std::string strLabel;
@@ -497,10 +497,6 @@ UniValue importpubkey(const JSONRPCRequest& request)
497497

498498
UniValue importwallet(const JSONRPCRequest& request)
499499
{
500-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
501-
if (!wallet) return NullUniValue;
502-
CWallet* const pwallet = wallet.get();
503-
504500
RPCHelpMan{"importwallet",
505501
"\nImports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup to include imported keys.\n"
506502
"Note: Use \"getwalletinfo\" to query the scanning progress.\n",
@@ -518,6 +514,10 @@ UniValue importwallet(const JSONRPCRequest& request)
518514
},
519515
}.Check(request);
520516

517+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
518+
if (!wallet) return NullUniValue;
519+
CWallet* const pwallet = wallet.get();
520+
521521
EnsureLegacyScriptPubKeyMan(*wallet, true);
522522

523523
if (pwallet->chain().havePruned()) {
@@ -653,10 +653,6 @@ UniValue importwallet(const JSONRPCRequest& request)
653653

654654
UniValue dumpprivkey(const JSONRPCRequest& request)
655655
{
656-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
657-
if (!wallet) return NullUniValue;
658-
const CWallet* const pwallet = wallet.get();
659-
660656
RPCHelpMan{"dumpprivkey",
661657
"\nReveals the private key corresponding to 'address'.\n"
662658
"Then the importprivkey can be used with this output\n",
@@ -673,6 +669,10 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
673669
},
674670
}.Check(request);
675671

672+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
673+
if (!wallet) return NullUniValue;
674+
const CWallet* const pwallet = wallet.get();
675+
676676
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*wallet);
677677

678678
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
@@ -698,9 +698,6 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
698698

699699
UniValue dumpwallet(const JSONRPCRequest& request)
700700
{
701-
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
702-
if (!pwallet) return NullUniValue;
703-
704701
RPCHelpMan{"dumpwallet",
705702
"\nDumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n"
706703
"Imported scripts are included in the dumpfile, but corresponding BIP173 addresses, etc. may not be added automatically by importwallet.\n"
@@ -721,6 +718,9 @@ UniValue dumpwallet(const JSONRPCRequest& request)
721718
},
722719
}.Check(request);
723720

721+
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
722+
if (!pwallet) return NullUniValue;
723+
724724
CWallet& wallet = *pwallet;
725725
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(wallet);
726726

@@ -1241,10 +1241,6 @@ static int64_t GetImportTimestamp(const UniValue& data, int64_t now)
12411241

12421242
UniValue importmulti(const JSONRPCRequest& mainRequest)
12431243
{
1244-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(mainRequest);
1245-
if (!wallet) return NullUniValue;
1246-
CWallet* const pwallet = wallet.get();
1247-
12481244
RPCHelpMan{"importmulti",
12491245
"\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.\n"
12501246
"If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.\n"
@@ -1320,6 +1316,9 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
13201316
},
13211317
}.Check(mainRequest);
13221318

1319+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(mainRequest);
1320+
if (!wallet) return NullUniValue;
1321+
CWallet* const pwallet = wallet.get();
13231322

13241323
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
13251324

@@ -1565,12 +1564,8 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
15651564
return result;
15661565
}
15671566

1568-
UniValue importdescriptors(const JSONRPCRequest& main_request) {
1569-
// Acquire the wallet
1570-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(main_request);
1571-
if (!wallet) return NullUniValue;
1572-
CWallet* const pwallet = wallet.get();
1573-
1567+
UniValue importdescriptors(const JSONRPCRequest& main_request)
1568+
{
15741569
RPCHelpMan{"importdescriptors",
15751570
"\nImport descriptors. This will trigger a rescan of the blockchain based on the earliest timestamp of all descriptors being imported. Requires a new wallet backup.\n"
15761571
"\nNote: This call can take over an hour to complete if using an early timestamp; during that time, other rpc calls\n"
@@ -1622,6 +1617,10 @@ UniValue importdescriptors(const JSONRPCRequest& main_request) {
16221617
},
16231618
}.Check(main_request);
16241619

1620+
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(main_request);
1621+
if (!wallet) return NullUniValue;
1622+
CWallet* const pwallet = wallet.get();
1623+
16251624
// Make sure wallet is a descriptor wallet
16261625
if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
16271626
throw JSONRPCError(RPC_WALLET_ERROR, "importdescriptors is not available for non-descriptor wallets");

0 commit comments

Comments
 (0)