@@ -67,11 +67,11 @@ static std::string DecodeDumpString(const std::string &str) {
67
67
return ret.str ();
68
68
}
69
69
70
- static bool GetWalletAddressesForKey (CWallet* const pwallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
70
+ static bool GetWalletAddressesForKey (LegacyScriptPubKeyMan* spk_man, CWallet* const pwallet, const CKeyID& keyid, std::string& strAddr, std::string& strLabel) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
71
71
{
72
72
bool fLabelFound = false ;
73
73
CKey key;
74
- pwallet ->GetKey (keyid, key);
74
+ spk_man ->GetKey (keyid, key);
75
75
for (const auto & dest : GetAllDestinationsForKey (key.GetPubKey ())) {
76
76
if (pwallet->mapAddressBook .count (dest)) {
77
77
if (!strAddr.empty ()) {
@@ -138,6 +138,11 @@ UniValue importprivkey(const JSONRPCRequest& request)
138
138
throw JSONRPCError (RPC_WALLET_ERROR, " Cannot import private keys to a wallet with private keys disabled" );
139
139
}
140
140
141
+ LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
142
+ if (!spk_man) {
143
+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
144
+ }
145
+
141
146
WalletRescanReserver reserver (pwallet);
142
147
bool fRescan = true ;
143
148
{
@@ -264,6 +269,10 @@ UniValue importaddress(const JSONRPCRequest& request)
264
269
},
265
270
}.Check (request);
266
271
272
+ LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
273
+ if (!spk_man) {
274
+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
275
+ }
267
276
268
277
std::string strLabel;
269
278
if (!request.params [1 ].isNull ())
@@ -466,6 +475,10 @@ UniValue importpubkey(const JSONRPCRequest& request)
466
475
},
467
476
}.Check (request);
468
477
478
+ LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
479
+ if (!spk_man) {
480
+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
481
+ }
469
482
470
483
std::string strLabel;
471
484
if (!request.params [1 ].isNull ())
@@ -549,6 +562,11 @@ UniValue importwallet(const JSONRPCRequest& request)
549
562
},
550
563
}.Check (request);
551
564
565
+ LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
566
+ if (!spk_man) {
567
+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
568
+ }
569
+
552
570
if (pwallet->chain ().havePruned ()) {
553
571
// Exit early and print an error.
554
572
// If a block is pruned after this check, we will import the key(s),
@@ -706,6 +724,11 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
706
724
},
707
725
}.Check (request);
708
726
727
+ LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
728
+ if (!spk_man) {
729
+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
730
+ }
731
+
709
732
auto locked_chain = pwallet->chain ().lock ();
710
733
LOCK (pwallet->cs_wallet );
711
734
@@ -716,12 +739,12 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
716
739
if (!IsValidDestination (dest)) {
717
740
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid Bitcoin address" );
718
741
}
719
- auto keyid = GetKeyForDestination (*pwallet , dest);
742
+ auto keyid = GetKeyForDestination (*spk_man , dest);
720
743
if (keyid.IsNull ()) {
721
744
throw JSONRPCError (RPC_TYPE_ERROR, " Address does not refer to a key" );
722
745
}
723
746
CKey vchSecret;
724
- if (!pwallet ->GetKey (keyid, vchSecret)) {
747
+ if (!spk_man ->GetKey (keyid, vchSecret)) {
725
748
throw JSONRPCError (RPC_WALLET_ERROR, " Private key for address " + strAddress + " is not known" );
726
749
}
727
750
return EncodeSecret (vchSecret);
@@ -755,8 +778,14 @@ UniValue dumpwallet(const JSONRPCRequest& request)
755
778
},
756
779
}.Check (request);
757
780
781
+ LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
782
+ if (!spk_man) {
783
+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
784
+ }
785
+
758
786
auto locked_chain = pwallet->chain ().lock ();
759
787
LOCK (pwallet->cs_wallet );
788
+ AssertLockHeld (spk_man->cs_wallet );
760
789
761
790
EnsureWalletIsUnlocked (pwallet);
762
791
@@ -778,10 +807,10 @@ UniValue dumpwallet(const JSONRPCRequest& request)
778
807
throw JSONRPCError (RPC_INVALID_PARAMETER, " Cannot open wallet dump file" );
779
808
780
809
std::map<CKeyID, int64_t > mapKeyBirth;
781
- const std::map<CKeyID, int64_t >& mapKeyPool = pwallet ->GetAllReserveKeys ();
810
+ const std::map<CKeyID, int64_t >& mapKeyPool = spk_man ->GetAllReserveKeys ();
782
811
pwallet->GetKeyBirthTimes (*locked_chain, mapKeyBirth);
783
812
784
- std::set<CScriptID> scripts = pwallet ->GetCScripts ();
813
+ std::set<CScriptID> scripts = spk_man ->GetCScripts ();
785
814
786
815
// sort time/key pairs
787
816
std::vector<std::pair<int64_t , CKeyID> > vKeyBirth;
@@ -800,11 +829,11 @@ UniValue dumpwallet(const JSONRPCRequest& request)
800
829
file << " \n " ;
801
830
802
831
// add the base58check encoded extended master if the wallet uses HD
803
- CKeyID seed_id = pwallet ->GetHDChain ().seed_id ;
832
+ CKeyID seed_id = spk_man ->GetHDChain ().seed_id ;
804
833
if (!seed_id.IsNull ())
805
834
{
806
835
CKey seed;
807
- if (pwallet ->GetKey (seed_id, seed)) {
836
+ if (spk_man ->GetKey (seed_id, seed)) {
808
837
CExtKey masterKey;
809
838
masterKey.SetSeed (seed.begin (), seed.size ());
810
839
@@ -817,20 +846,20 @@ UniValue dumpwallet(const JSONRPCRequest& request)
817
846
std::string strAddr;
818
847
std::string strLabel;
819
848
CKey key;
820
- if (pwallet ->GetKey (keyid, key)) {
849
+ if (spk_man ->GetKey (keyid, key)) {
821
850
file << strprintf (" %s %s " , EncodeSecret (key), strTime);
822
- if (GetWalletAddressesForKey (pwallet, keyid, strAddr, strLabel)) {
851
+ if (GetWalletAddressesForKey (spk_man, pwallet, keyid, strAddr, strLabel)) {
823
852
file << strprintf (" label=%s" , strLabel);
824
853
} else if (keyid == seed_id) {
825
854
file << " hdseed=1" ;
826
855
} else if (mapKeyPool.count (keyid)) {
827
856
file << " reserve=1" ;
828
- } else if (pwallet ->mapKeyMetadata [keyid].hdKeypath == " s" ) {
857
+ } else if (spk_man ->mapKeyMetadata [keyid].hdKeypath == " s" ) {
829
858
file << " inactivehdseed=1" ;
830
859
} else {
831
860
file << " change=1" ;
832
861
}
833
- file << strprintf (" # addr=%s%s\n " , strAddr, (pwallet ->mapKeyMetadata [keyid].has_key_origin ? " hdkeypath=" +WriteHDKeypath (pwallet ->mapKeyMetadata [keyid].key_origin .path ) : " " ));
862
+ file << strprintf (" # addr=%s%s\n " , strAddr, (spk_man ->mapKeyMetadata [keyid].has_key_origin ? " hdkeypath=" +WriteHDKeypath (spk_man ->mapKeyMetadata [keyid].key_origin .path ) : " " ));
834
863
}
835
864
}
836
865
file << " \n " ;
@@ -839,11 +868,11 @@ UniValue dumpwallet(const JSONRPCRequest& request)
839
868
std::string create_time = " 0" ;
840
869
std::string address = EncodeDestination (ScriptHash (scriptid));
841
870
// get birth times for scripts with metadata
842
- auto it = pwallet ->m_script_metadata .find (scriptid);
843
- if (it != pwallet ->m_script_metadata .end ()) {
871
+ auto it = spk_man ->m_script_metadata .find (scriptid);
872
+ if (it != spk_man ->m_script_metadata .end ()) {
844
873
create_time = FormatISO8601DateTime (it->second .nCreateTime );
845
874
}
846
- if (pwallet ->GetCScript (scriptid, script)) {
875
+ if (spk_man ->GetCScript (scriptid, script)) {
847
876
file << strprintf (" %s %s script=1" , HexStr (script.begin (), script.end ()), create_time);
848
877
file << strprintf (" # addr=%s\n " , address);
849
878
}
@@ -1219,7 +1248,7 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
1219
1248
1220
1249
// Check whether we have any work to do
1221
1250
for (const CScript& script : script_pub_keys) {
1222
- if (:: IsMine (*pwallet, script) & ISMINE_SPENDABLE) {
1251
+ if (pwallet-> IsMine (script) & ISMINE_SPENDABLE) {
1223
1252
throw JSONRPCError (RPC_WALLET_ERROR, " The wallet already contains the private key for this address or script (\" " + HexStr (script.begin (), script.end ()) + " \" )" );
1224
1253
}
1225
1254
}
@@ -1339,6 +1368,11 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
1339
1368
1340
1369
RPCTypeCheck (mainRequest.params , {UniValue::VARR, UniValue::VOBJ});
1341
1370
1371
+ LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan ();
1372
+ if (!spk_man) {
1373
+ throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
1374
+ }
1375
+
1342
1376
const UniValue& requests = mainRequest.params [0 ];
1343
1377
1344
1378
// Default options
0 commit comments