@@ -56,13 +56,13 @@ static std::string DecodeDumpString(const std::string &str) {
56
56
return ret.str ();
57
57
}
58
58
59
- static bool GetWalletAddressesForKey (LegacyScriptPubKeyMan* spk_man, const CWallet* const pwallet , const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet-> cs_wallet)
59
+ static bool GetWalletAddressesForKey (LegacyScriptPubKeyMan* spk_man, const CWallet& wallet , const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(wallet. cs_wallet)
60
60
{
61
61
bool fLabelFound = false ;
62
62
CKey key;
63
63
spk_man->GetKey (keyid, key);
64
64
for (const auto & dest : GetAllDestinationsForKey (key.GetPubKey ())) {
65
- const auto * address_book_entry = pwallet-> FindAddressBookEntry (dest);
65
+ const auto * address_book_entry = wallet. FindAddressBookEntry (dest);
66
66
if (address_book_entry) {
67
67
if (!strAddr.empty ()) {
68
68
strAddr += " ," ;
@@ -73,7 +73,7 @@ static bool GetWalletAddressesForKey(LegacyScriptPubKeyMan* spk_man, const CWall
73
73
}
74
74
}
75
75
if (!fLabelFound ) {
76
- strAddr = EncodeDestination (GetDestinationForKey (key.GetPubKey (), pwallet-> m_default_address_type ));
76
+ strAddr = EncodeDestination (GetDestinationForKey (key.GetPubKey (), wallet. m_default_address_type ));
77
77
}
78
78
return fLabelFound ;
79
79
}
@@ -118,22 +118,21 @@ RPCHelpMan importprivkey()
118
118
},
119
119
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
120
120
{
121
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
122
- if (!wallet) return NullUniValue;
123
- CWallet* const pwallet = wallet.get ();
121
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
122
+ if (!pwallet) return NullUniValue;
124
123
125
124
if (pwallet->IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
126
125
throw JSONRPCError (RPC_WALLET_ERROR, " Cannot import private keys to a wallet with private keys disabled" );
127
126
}
128
127
129
- EnsureLegacyScriptPubKeyMan (*wallet , true );
128
+ EnsureLegacyScriptPubKeyMan (*pwallet , true );
130
129
131
130
WalletRescanReserver reserver (*pwallet);
132
131
bool fRescan = true ;
133
132
{
134
133
LOCK (pwallet->cs_wallet );
135
134
136
- EnsureWalletIsUnlocked (pwallet);
135
+ EnsureWalletIsUnlocked (* pwallet);
137
136
138
137
std::string strSecret = request.params [0 ].get_str ();
139
138
std::string strLabel = " " ;
@@ -210,9 +209,8 @@ RPCHelpMan abortrescan()
210
209
},
211
210
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
212
211
{
213
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
214
- if (!wallet) return NullUniValue;
215
- CWallet* const pwallet = wallet.get ();
212
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
213
+ if (!pwallet) return NullUniValue;
216
214
217
215
if (!pwallet->IsScanning () || pwallet->IsAbortingRescan ()) return false ;
218
216
pwallet->AbortRescan ();
@@ -249,9 +247,8 @@ RPCHelpMan importaddress()
249
247
},
250
248
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
251
249
{
252
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
253
- if (!wallet) return NullUniValue;
254
- CWallet* const pwallet = wallet.get ();
250
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
251
+ if (!pwallet) return NullUniValue;
255
252
256
253
EnsureLegacyScriptPubKeyMan (*pwallet, true );
257
254
@@ -335,9 +332,8 @@ RPCHelpMan importprunedfunds()
335
332
RPCExamples{" " },
336
333
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
337
334
{
338
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
339
- if (!wallet) return NullUniValue;
340
- CWallet* const pwallet = wallet.get ();
335
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
336
+ if (!pwallet) return NullUniValue;
341
337
342
338
CMutableTransaction tx;
343
339
if (!DecodeHexTx (tx, request.params [0 ].get_str ())) {
@@ -397,9 +393,8 @@ RPCHelpMan removeprunedfunds()
397
393
},
398
394
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
399
395
{
400
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
401
- if (!wallet) return NullUniValue;
402
- CWallet* const pwallet = wallet.get ();
396
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
397
+ if (!pwallet) return NullUniValue;
403
398
404
399
LOCK (pwallet->cs_wallet );
405
400
@@ -445,11 +440,10 @@ RPCHelpMan importpubkey()
445
440
},
446
441
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
447
442
{
448
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
449
- if (!wallet) return NullUniValue;
450
- CWallet* const pwallet = wallet.get ();
443
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
444
+ if (!pwallet) return NullUniValue;
451
445
452
- EnsureLegacyScriptPubKeyMan (*wallet , true );
446
+ EnsureLegacyScriptPubKeyMan (*pwallet , true );
453
447
454
448
std::string strLabel;
455
449
if (!request.params [1 ].isNull ())
@@ -527,11 +521,10 @@ RPCHelpMan importwallet()
527
521
},
528
522
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
529
523
{
530
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
531
- if (!wallet) return NullUniValue;
532
- CWallet* const pwallet = wallet.get ();
524
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
525
+ if (!pwallet) return NullUniValue;
533
526
534
- EnsureLegacyScriptPubKeyMan (*wallet , true );
527
+ EnsureLegacyScriptPubKeyMan (*pwallet , true );
535
528
536
529
if (pwallet->chain ().havePruned ()) {
537
530
// Exit early and print an error.
@@ -550,7 +543,7 @@ RPCHelpMan importwallet()
550
543
{
551
544
LOCK (pwallet->cs_wallet );
552
545
553
- EnsureWalletIsUnlocked (pwallet);
546
+ EnsureWalletIsUnlocked (* pwallet);
554
547
555
548
fsbridge::ifstream file;
556
549
file.open (request.params [0 ].get_str (), std::ios::in | std::ios::ate);
@@ -684,15 +677,14 @@ RPCHelpMan dumpprivkey()
684
677
},
685
678
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
686
679
{
687
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (request);
688
- if (!wallet) return NullUniValue;
689
- const CWallet* const pwallet = wallet.get ();
680
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (request);
681
+ if (!pwallet) return NullUniValue;
690
682
691
- LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (*wallet );
683
+ LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan (*pwallet );
692
684
693
685
LOCK2 (pwallet->cs_wallet , spk_man.cs_KeyStore );
694
686
695
- EnsureWalletIsUnlocked (pwallet);
687
+ EnsureWalletIsUnlocked (* pwallet);
696
688
697
689
std::string strAddress = request.params [0 ].get_str ();
698
690
CTxDestination dest = DecodeDestination (strAddress);
@@ -747,7 +739,7 @@ RPCHelpMan dumpwallet()
747
739
748
740
LOCK2 (wallet.cs_wallet , spk_man.cs_KeyStore );
749
741
750
- EnsureWalletIsUnlocked (& wallet);
742
+ EnsureWalletIsUnlocked (wallet);
751
743
752
744
fs::path filepath = request.params [0 ].get_str ();
753
745
filepath = fs::absolute (filepath);
@@ -809,7 +801,7 @@ RPCHelpMan dumpwallet()
809
801
CKey key;
810
802
if (spk_man.GetKey (keyid, key)) {
811
803
file << strprintf (" %s %s " , EncodeSecret (key), strTime);
812
- if (GetWalletAddressesForKey (&spk_man, & wallet, keyid, strAddr, strLabel)) {
804
+ if (GetWalletAddressesForKey (&spk_man, wallet, keyid, strAddr, strLabel)) {
813
805
file << strprintf (" label=%s" , strLabel);
814
806
} else if (keyid == seed_id) {
815
807
file << " hdseed=1" ;
@@ -1169,7 +1161,7 @@ static UniValue ProcessImportDescriptor(ImportData& import_data, std::map<CKeyID
1169
1161
return warnings;
1170
1162
}
1171
1163
1172
- static UniValue ProcessImport (CWallet * const pwallet , const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet-> cs_wallet)
1164
+ static UniValue ProcessImport (CWallet& wallet , const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(wallet. cs_wallet)
1173
1165
{
1174
1166
UniValue warnings (UniValue::VARR);
1175
1167
UniValue result (UniValue::VOBJ);
@@ -1184,7 +1176,7 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
1184
1176
const bool add_keypool = data.exists (" keypool" ) ? data[" keypool" ].get_bool () : false ;
1185
1177
1186
1178
// Add to keypool only works with privkeys disabled
1187
- if (add_keypool && !pwallet-> IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
1179
+ if (add_keypool && !wallet. IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
1188
1180
throw JSONRPCError (RPC_INVALID_PARAMETER, " Keys can only be imported to the keypool when private keys are disabled" );
1189
1181
}
1190
1182
@@ -1206,29 +1198,29 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
1206
1198
}
1207
1199
1208
1200
// If private keys are disabled, abort if private keys are being imported
1209
- if (pwallet-> IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !privkey_map.empty ()) {
1201
+ if (wallet. IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !privkey_map.empty ()) {
1210
1202
throw JSONRPCError (RPC_WALLET_ERROR, " Cannot import private keys to a wallet with private keys disabled" );
1211
1203
}
1212
1204
1213
1205
// Check whether we have any work to do
1214
1206
for (const CScript& script : script_pub_keys) {
1215
- if (pwallet-> IsMine (script) & ISMINE_SPENDABLE) {
1207
+ if (wallet. IsMine (script) & ISMINE_SPENDABLE) {
1216
1208
throw JSONRPCError (RPC_WALLET_ERROR, " The wallet already contains the private key for this address or script (\" " + HexStr (script) + " \" )" );
1217
1209
}
1218
1210
}
1219
1211
1220
1212
// All good, time to import
1221
- pwallet-> MarkDirty ();
1222
- if (!pwallet-> ImportScripts (import_data.import_scripts , timestamp)) {
1213
+ wallet. MarkDirty ();
1214
+ if (!wallet. ImportScripts (import_data.import_scripts , timestamp)) {
1223
1215
throw JSONRPCError (RPC_WALLET_ERROR, " Error adding script to wallet" );
1224
1216
}
1225
- if (!pwallet-> ImportPrivKeys (privkey_map, timestamp)) {
1217
+ if (!wallet. ImportPrivKeys (privkey_map, timestamp)) {
1226
1218
throw JSONRPCError (RPC_WALLET_ERROR, " Error adding key to wallet" );
1227
1219
}
1228
- if (!pwallet-> ImportPubKeys (ordered_pubkeys, pubkey_map, import_data.key_origins , add_keypool, internal, timestamp)) {
1220
+ if (!wallet. ImportPubKeys (ordered_pubkeys, pubkey_map, import_data.key_origins , add_keypool, internal, timestamp)) {
1229
1221
throw JSONRPCError (RPC_WALLET_ERROR, " Error adding address to wallet" );
1230
1222
}
1231
- if (!pwallet-> ImportScriptPubKeys (label, script_pub_keys, have_solving_data, !internal, timestamp)) {
1223
+ if (!wallet. ImportScriptPubKeys (label, script_pub_keys, have_solving_data, !internal, timestamp)) {
1232
1224
throw JSONRPCError (RPC_WALLET_ERROR, " Error adding address to wallet" );
1233
1225
}
1234
1226
@@ -1336,13 +1328,12 @@ RPCHelpMan importmulti()
1336
1328
},
1337
1329
[&](const RPCHelpMan& self, const JSONRPCRequest& mainRequest) -> UniValue
1338
1330
{
1339
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (mainRequest);
1340
- if (!wallet) return NullUniValue;
1341
- CWallet* const pwallet = wallet.get ();
1331
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (mainRequest);
1332
+ if (!pwallet) return NullUniValue;
1342
1333
1343
1334
RPCTypeCheck (mainRequest.params , {UniValue::VARR, UniValue::VOBJ});
1344
1335
1345
- EnsureLegacyScriptPubKeyMan (*wallet , true );
1336
+ EnsureLegacyScriptPubKeyMan (*pwallet , true );
1346
1337
1347
1338
const UniValue& requests = mainRequest.params [0 ];
1348
1339
@@ -1368,7 +1359,7 @@ RPCHelpMan importmulti()
1368
1359
UniValue response (UniValue::VARR);
1369
1360
{
1370
1361
LOCK (pwallet->cs_wallet );
1371
- EnsureWalletIsUnlocked (pwallet);
1362
+ EnsureWalletIsUnlocked (* pwallet);
1372
1363
1373
1364
// Verify all timestamps are present before importing any keys.
1374
1365
CHECK_NONFATAL (pwallet->chain ().findBlock (pwallet->GetLastBlockHash (), FoundBlock ().time (nLowestTimestamp).mtpTime (now)));
@@ -1380,7 +1371,7 @@ RPCHelpMan importmulti()
1380
1371
1381
1372
for (const UniValue& data : requests.getValues ()) {
1382
1373
const int64_t timestamp = std::max (GetImportTimestamp (data, now), minimumTimestamp);
1383
- const UniValue result = ProcessImport (pwallet, data, timestamp);
1374
+ const UniValue result = ProcessImport (* pwallet, data, timestamp);
1384
1375
response.push_back (result);
1385
1376
1386
1377
if (!fRescan ) {
@@ -1447,7 +1438,7 @@ RPCHelpMan importmulti()
1447
1438
};
1448
1439
}
1449
1440
1450
- static UniValue ProcessDescriptorImport (CWallet * const pwallet , const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(pwallet-> cs_wallet)
1441
+ static UniValue ProcessDescriptorImport (CWallet& wallet , const UniValue& data, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(wallet. cs_wallet)
1451
1442
{
1452
1443
UniValue warnings (UniValue::VARR);
1453
1444
UniValue result (UniValue::VOBJ);
@@ -1516,7 +1507,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
1516
1507
}
1517
1508
1518
1509
// If the wallet disabled private keys, abort if private keys exist
1519
- if (pwallet-> IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !keys.keys .empty ()) {
1510
+ if (wallet. IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !keys.keys .empty ()) {
1520
1511
throw JSONRPCError (RPC_WALLET_ERROR, " Cannot import private keys to a wallet with private keys disabled" );
1521
1512
}
1522
1513
@@ -1540,7 +1531,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
1540
1531
}
1541
1532
1542
1533
// If private keys are enabled, check some things.
1543
- if (!pwallet-> IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
1534
+ if (!wallet. IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
1544
1535
if (keys.keys .empty ()) {
1545
1536
throw JSONRPCError (RPC_WALLET_ERROR, " Cannot import descriptor without private keys to a wallet with private keys enabled" );
1546
1537
}
@@ -1552,7 +1543,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
1552
1543
WalletDescriptor w_desc (std::move (parsed_desc), timestamp, range_start, range_end, next_index);
1553
1544
1554
1545
// Check if the wallet already contains the descriptor
1555
- auto existing_spk_manager = pwallet-> GetDescriptorScriptPubKeyMan (w_desc);
1546
+ auto existing_spk_manager = wallet. GetDescriptorScriptPubKeyMan (w_desc);
1556
1547
if (existing_spk_manager) {
1557
1548
LOCK (existing_spk_manager->cs_desc_man );
1558
1549
if (range_start > existing_spk_manager->GetWalletDescriptor ().range_start ) {
@@ -1561,7 +1552,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
1561
1552
}
1562
1553
1563
1554
// Add descriptor to the wallet
1564
- auto spk_manager = pwallet-> AddWalletDescriptor (w_desc, keys, label, internal);
1555
+ auto spk_manager = wallet. AddWalletDescriptor (w_desc, keys, label, internal);
1565
1556
if (spk_manager == nullptr ) {
1566
1557
throw JSONRPCError (RPC_WALLET_ERROR, strprintf (" Could not add descriptor '%s'" , descriptor));
1567
1558
}
@@ -1571,7 +1562,7 @@ static UniValue ProcessDescriptorImport(CWallet * const pwallet, const UniValue&
1571
1562
if (!w_desc.descriptor ->GetOutputType ()) {
1572
1563
warnings.push_back (" Unknown output type, cannot set descriptor to active." );
1573
1564
} else {
1574
- pwallet-> AddActiveScriptPubKeyMan (spk_manager->GetID (), *w_desc.descriptor ->GetOutputType (), internal);
1565
+ wallet. AddActiveScriptPubKeyMan (spk_manager->GetID (), *w_desc.descriptor ->GetOutputType (), internal);
1575
1566
}
1576
1567
}
1577
1568
@@ -1641,9 +1632,8 @@ RPCHelpMan importdescriptors()
1641
1632
},
1642
1633
[&](const RPCHelpMan& self, const JSONRPCRequest& main_request) -> UniValue
1643
1634
{
1644
- std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest (main_request);
1645
- if (!wallet) return NullUniValue;
1646
- CWallet* const pwallet = wallet.get ();
1635
+ std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest (main_request);
1636
+ if (!pwallet) return NullUniValue;
1647
1637
1648
1638
// Make sure wallet is a descriptor wallet
1649
1639
if (!pwallet->IsWalletFlagSet (WALLET_FLAG_DESCRIPTORS)) {
@@ -1665,15 +1655,15 @@ RPCHelpMan importdescriptors()
1665
1655
UniValue response (UniValue::VARR);
1666
1656
{
1667
1657
LOCK (pwallet->cs_wallet );
1668
- EnsureWalletIsUnlocked (pwallet);
1658
+ EnsureWalletIsUnlocked (* pwallet);
1669
1659
1670
1660
CHECK_NONFATAL (pwallet->chain ().findBlock (pwallet->GetLastBlockHash (), FoundBlock ().time (lowest_timestamp).mtpTime (now)));
1671
1661
1672
1662
// Get all timestamps and extract the lowest timestamp
1673
1663
for (const UniValue& request : requests.getValues ()) {
1674
1664
// This throws an error if "timestamp" doesn't exist
1675
1665
const int64_t timestamp = std::max (GetImportTimestamp (request, now), minimum_timestamp);
1676
- const UniValue result = ProcessDescriptorImport (pwallet, request, timestamp);
1666
+ const UniValue result = ProcessDescriptorImport (* pwallet, request, timestamp);
1677
1667
response.push_back (result);
1678
1668
1679
1669
if (lowest_timestamp > timestamp ) {
@@ -1775,7 +1765,7 @@ RPCHelpMan listdescriptors()
1775
1765
throw JSONRPCError (RPC_WALLET_ERROR, " listdescriptors is not available for non-descriptor wallets" );
1776
1766
}
1777
1767
1778
- EnsureWalletIsUnlocked (wallet. get () );
1768
+ EnsureWalletIsUnlocked (* wallet);
1779
1769
1780
1770
LOCK (wallet->cs_wallet );
1781
1771
0 commit comments