@@ -92,10 +92,6 @@ static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver,
92
92
93
93
UniValue importprivkey (const JSONRPCRequest& request)
94
94
{
95
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
96
- if (!wallet) return NullUniValue;
97
- CWallet* const pwallet = wallet.get ();
98
-
99
95
RPCHelpMan{" importprivkey" ,
100
96
" \n Adds a private key (as returned by dumpprivkey) to your wallet. Requires a new wallet backup.\n "
101
97
" Hint: use importmulti to import more than one private key.\n "
@@ -122,6 +118,10 @@ UniValue importprivkey(const JSONRPCRequest& request)
122
118
},
123
119
}.Check (request);
124
120
121
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
122
+ if (!wallet) return NullUniValue;
123
+ CWallet* const pwallet = wallet.get ();
124
+
125
125
if (pwallet->IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
126
126
throw JSONRPCError (RPC_WALLET_ERROR, " Cannot import private keys to a wallet with private keys disabled" );
127
127
}
@@ -193,10 +193,6 @@ UniValue importprivkey(const JSONRPCRequest& request)
193
193
194
194
UniValue abortrescan (const JSONRPCRequest& request)
195
195
{
196
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
197
- if (!wallet) return NullUniValue;
198
- CWallet* const pwallet = wallet.get ();
199
-
200
196
RPCHelpMan{" abortrescan" ,
201
197
" \n Stops current wallet rescan triggered by an RPC call, e.g. by an importprivkey call.\n "
202
198
" Note: Use \" getwalletinfo\" to query the scanning progress.\n " ,
@@ -212,17 +208,17 @@ UniValue abortrescan(const JSONRPCRequest& request)
212
208
},
213
209
}.Check (request);
214
210
211
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
212
+ if (!wallet) return NullUniValue;
213
+ CWallet* const pwallet = wallet.get ();
214
+
215
215
if (!pwallet->IsScanning () || pwallet->IsAbortingRescan ()) return false ;
216
216
pwallet->AbortRescan ();
217
217
return true ;
218
218
}
219
219
220
220
UniValue importaddress (const JSONRPCRequest& request)
221
221
{
222
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
223
- if (!wallet) return NullUniValue;
224
- CWallet* const pwallet = wallet.get ();
225
-
226
222
RPCHelpMan{" importaddress" ,
227
223
" \n Adds 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 "
228
224
" \n Note: 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)
249
245
},
250
246
}.Check (request);
251
247
248
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
249
+ if (!wallet) return NullUniValue;
250
+ CWallet* const pwallet = wallet.get ();
251
+
252
252
EnsureLegacyScriptPubKeyMan (*pwallet, true );
253
253
254
254
std::string strLabel;
@@ -319,10 +319,6 @@ UniValue importaddress(const JSONRPCRequest& request)
319
319
320
320
UniValue importprunedfunds (const JSONRPCRequest& request)
321
321
{
322
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
323
- if (!wallet) return NullUniValue;
324
- CWallet* const pwallet = wallet.get ();
325
-
326
322
RPCHelpMan{" importprunedfunds" ,
327
323
" \n Imports 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 " ,
328
324
{
@@ -333,6 +329,10 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
333
329
RPCExamples{" " },
334
330
}.Check (request);
335
331
332
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
333
+ if (!wallet) return NullUniValue;
334
+ CWallet* const pwallet = wallet.get ();
335
+
336
336
CMutableTransaction tx;
337
337
if (!DecodeHexTx (tx, request.params [0 ].get_str ()))
338
338
throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " TX decode failed" );
@@ -375,10 +375,6 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
375
375
376
376
UniValue removeprunedfunds (const JSONRPCRequest& request)
377
377
{
378
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
379
- if (!wallet) return NullUniValue;
380
- CWallet* const pwallet = wallet.get ();
381
-
382
378
RPCHelpMan{" removeprunedfunds" ,
383
379
" \n Deletes the specified transaction from the wallet. Meant for use with pruned wallets and as a companion to importprunedfunds. This will affect wallet balances.\n " ,
384
380
{
@@ -392,6 +388,10 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
392
388
},
393
389
}.Check (request);
394
390
391
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
392
+ if (!wallet) return NullUniValue;
393
+ CWallet* const pwallet = wallet.get ();
394
+
395
395
LOCK (pwallet->cs_wallet );
396
396
397
397
uint256 hash (ParseHashV (request.params [0 ], " txid" ));
@@ -412,10 +412,6 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
412
412
413
413
UniValue importpubkey (const JSONRPCRequest& request)
414
414
{
415
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
416
- if (!wallet) return NullUniValue;
417
- CWallet* const pwallet = wallet.get ();
418
-
419
415
RPCHelpMan{" importpubkey" ,
420
416
" \n Adds 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 "
421
417
" Hint: use importmulti to import more than one public key.\n "
@@ -438,6 +434,10 @@ UniValue importpubkey(const JSONRPCRequest& request)
438
434
},
439
435
}.Check (request);
440
436
437
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
438
+ if (!wallet) return NullUniValue;
439
+ CWallet* const pwallet = wallet.get ();
440
+
441
441
EnsureLegacyScriptPubKeyMan (*wallet, true );
442
442
443
443
std::string strLabel;
@@ -497,10 +497,6 @@ UniValue importpubkey(const JSONRPCRequest& request)
497
497
498
498
UniValue importwallet (const JSONRPCRequest& request)
499
499
{
500
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
501
- if (!wallet) return NullUniValue;
502
- CWallet* const pwallet = wallet.get ();
503
-
504
500
RPCHelpMan{" importwallet" ,
505
501
" \n Imports keys from a wallet dump file (see dumpwallet). Requires a new wallet backup to include imported keys.\n "
506
502
" Note: Use \" getwalletinfo\" to query the scanning progress.\n " ,
@@ -518,6 +514,10 @@ UniValue importwallet(const JSONRPCRequest& request)
518
514
},
519
515
}.Check (request);
520
516
517
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
518
+ if (!wallet) return NullUniValue;
519
+ CWallet* const pwallet = wallet.get ();
520
+
521
521
EnsureLegacyScriptPubKeyMan (*wallet, true );
522
522
523
523
if (pwallet->chain ().havePruned ()) {
@@ -653,10 +653,6 @@ UniValue importwallet(const JSONRPCRequest& request)
653
653
654
654
UniValue dumpprivkey (const JSONRPCRequest& request)
655
655
{
656
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
657
- if (!wallet) return NullUniValue;
658
- const CWallet* const pwallet = wallet.get ();
659
-
660
656
RPCHelpMan{" dumpprivkey" ,
661
657
" \n Reveals the private key corresponding to 'address'.\n "
662
658
" Then the importprivkey can be used with this output\n " ,
@@ -673,6 +669,10 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
673
669
},
674
670
}.Check (request);
675
671
672
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
673
+ if (!wallet) return NullUniValue;
674
+ const CWallet* const pwallet = wallet.get ();
675
+
676
676
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (*wallet);
677
677
678
678
LOCK2 (pwallet->cs_wallet , spk_man.cs_KeyStore );
@@ -698,9 +698,6 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
698
698
699
699
UniValue dumpwallet (const JSONRPCRequest& request)
700
700
{
701
- std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
702
- if (!pwallet) return NullUniValue;
703
-
704
701
RPCHelpMan{" dumpwallet" ,
705
702
" \n Dumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.\n "
706
703
" 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)
721
718
},
722
719
}.Check (request);
723
720
721
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
722
+ if (!pwallet) return NullUniValue;
723
+
724
724
CWallet& wallet = *pwallet;
725
725
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (wallet);
726
726
@@ -1241,10 +1241,6 @@ static int64_t GetImportTimestamp(const UniValue& data, int64_t now)
1241
1241
1242
1242
UniValue importmulti (const JSONRPCRequest& mainRequest)
1243
1243
{
1244
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (mainRequest);
1245
- if (!wallet) return NullUniValue;
1246
- CWallet* const pwallet = wallet.get ();
1247
-
1248
1244
RPCHelpMan{" importmulti" ,
1249
1245
" \n Import 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 "
1250
1246
" 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)
1320
1316
},
1321
1317
}.Check (mainRequest);
1322
1318
1319
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (mainRequest);
1320
+ if (!wallet) return NullUniValue;
1321
+ CWallet* const pwallet = wallet.get ();
1323
1322
1324
1323
RPCTypeCheck (mainRequest.params , {UniValue::VARR, UniValue::VOBJ});
1325
1324
@@ -1565,12 +1564,8 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
1565
1564
return result;
1566
1565
}
1567
1566
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
+ {
1574
1569
RPCHelpMan{" importdescriptors" ,
1575
1570
" \n Import 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 "
1576
1571
" \n Note: 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) {
1622
1617
},
1623
1618
}.Check (main_request);
1624
1619
1620
+ std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (main_request);
1621
+ if (!wallet) return NullUniValue;
1622
+ CWallet* const pwallet = wallet.get ();
1623
+
1625
1624
// Make sure wallet is a descriptor wallet
1626
1625
if (!pwallet->IsWalletFlagSet (WALLET_FLAG_DESCRIPTORS)) {
1627
1626
throw JSONRPCError (RPC_WALLET_ERROR, " importdescriptors is not available for non-descriptor wallets" );
0 commit comments