@@ -67,11 +67,11 @@ static std::string DecodeDumpString(const std::string &str) {
6767 return ret.str ();
6868}
6969
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)
7171{
7272 bool fLabelFound = false ;
7373 CKey key;
74- pwallet ->GetKey (keyid, key);
74+ spk_man ->GetKey (keyid, key);
7575 for (const auto & dest : GetAllDestinationsForKey (key.GetPubKey ())) {
7676 if (pwallet->mapAddressBook .count (dest)) {
7777 if (!strAddr.empty ()) {
@@ -138,6 +138,11 @@ UniValue importprivkey(const JSONRPCRequest& request)
138138 throw JSONRPCError (RPC_WALLET_ERROR, " Cannot import private keys to a wallet with private keys disabled" );
139139 }
140140
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+
141146 WalletRescanReserver reserver (pwallet);
142147 bool fRescan = true ;
143148 {
@@ -264,6 +269,10 @@ UniValue importaddress(const JSONRPCRequest& request)
264269 },
265270 }.Check (request);
266271
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+ }
267276
268277 std::string strLabel;
269278 if (!request.params [1 ].isNull ())
@@ -466,6 +475,10 @@ UniValue importpubkey(const JSONRPCRequest& request)
466475 },
467476 }.Check (request);
468477
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+ }
469482
470483 std::string strLabel;
471484 if (!request.params [1 ].isNull ())
@@ -549,6 +562,11 @@ UniValue importwallet(const JSONRPCRequest& request)
549562 },
550563 }.Check (request);
551564
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+
552570 if (pwallet->chain ().havePruned ()) {
553571 // Exit early and print an error.
554572 // If a block is pruned after this check, we will import the key(s),
@@ -706,6 +724,11 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
706724 },
707725 }.Check (request);
708726
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+
709732 auto locked_chain = pwallet->chain ().lock ();
710733 LOCK (pwallet->cs_wallet );
711734
@@ -716,12 +739,12 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
716739 if (!IsValidDestination (dest)) {
717740 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Invalid Bitcoin address" );
718741 }
719- auto keyid = GetKeyForDestination (*pwallet , dest);
742+ auto keyid = GetKeyForDestination (*spk_man , dest);
720743 if (keyid.IsNull ()) {
721744 throw JSONRPCError (RPC_TYPE_ERROR, " Address does not refer to a key" );
722745 }
723746 CKey vchSecret;
724- if (!pwallet ->GetKey (keyid, vchSecret)) {
747+ if (!spk_man ->GetKey (keyid, vchSecret)) {
725748 throw JSONRPCError (RPC_WALLET_ERROR, " Private key for address " + strAddress + " is not known" );
726749 }
727750 return EncodeSecret (vchSecret);
@@ -755,8 +778,14 @@ UniValue dumpwallet(const JSONRPCRequest& request)
755778 },
756779 }.Check (request);
757780
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+
758786 auto locked_chain = pwallet->chain ().lock ();
759787 LOCK (pwallet->cs_wallet );
788+ AssertLockHeld (spk_man->cs_wallet );
760789
761790 EnsureWalletIsUnlocked (pwallet);
762791
@@ -778,10 +807,10 @@ UniValue dumpwallet(const JSONRPCRequest& request)
778807 throw JSONRPCError (RPC_INVALID_PARAMETER, " Cannot open wallet dump file" );
779808
780809 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 ();
782811 pwallet->GetKeyBirthTimes (*locked_chain, mapKeyBirth);
783812
784- std::set<CScriptID> scripts = pwallet ->GetCScripts ();
813+ std::set<CScriptID> scripts = spk_man ->GetCScripts ();
785814
786815 // sort time/key pairs
787816 std::vector<std::pair<int64_t , CKeyID> > vKeyBirth;
@@ -800,11 +829,11 @@ UniValue dumpwallet(const JSONRPCRequest& request)
800829 file << " \n " ;
801830
802831 // 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 ;
804833 if (!seed_id.IsNull ())
805834 {
806835 CKey seed;
807- if (pwallet ->GetKey (seed_id, seed)) {
836+ if (spk_man ->GetKey (seed_id, seed)) {
808837 CExtKey masterKey;
809838 masterKey.SetSeed (seed.begin (), seed.size ());
810839
@@ -817,20 +846,20 @@ UniValue dumpwallet(const JSONRPCRequest& request)
817846 std::string strAddr;
818847 std::string strLabel;
819848 CKey key;
820- if (pwallet ->GetKey (keyid, key)) {
849+ if (spk_man ->GetKey (keyid, key)) {
821850 file << strprintf (" %s %s " , EncodeSecret (key), strTime);
822- if (GetWalletAddressesForKey (pwallet, keyid, strAddr, strLabel)) {
851+ if (GetWalletAddressesForKey (spk_man, pwallet, keyid, strAddr, strLabel)) {
823852 file << strprintf (" label=%s" , strLabel);
824853 } else if (keyid == seed_id) {
825854 file << " hdseed=1" ;
826855 } else if (mapKeyPool.count (keyid)) {
827856 file << " reserve=1" ;
828- } else if (pwallet ->mapKeyMetadata [keyid].hdKeypath == " s" ) {
857+ } else if (spk_man ->mapKeyMetadata [keyid].hdKeypath == " s" ) {
829858 file << " inactivehdseed=1" ;
830859 } else {
831860 file << " change=1" ;
832861 }
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 ) : " " ));
834863 }
835864 }
836865 file << " \n " ;
@@ -839,11 +868,11 @@ UniValue dumpwallet(const JSONRPCRequest& request)
839868 std::string create_time = " 0" ;
840869 std::string address = EncodeDestination (ScriptHash (scriptid));
841870 // 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 ()) {
844873 create_time = FormatISO8601DateTime (it->second .nCreateTime );
845874 }
846- if (pwallet ->GetCScript (scriptid, script)) {
875+ if (spk_man ->GetCScript (scriptid, script)) {
847876 file << strprintf (" %s %s script=1" , HexStr (script.begin (), script.end ()), create_time);
848877 file << strprintf (" # addr=%s\n " , address);
849878 }
@@ -1219,7 +1248,7 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con
12191248
12201249 // Check whether we have any work to do
12211250 for (const CScript& script : script_pub_keys) {
1222- if (:: IsMine (*pwallet, script) & ISMINE_SPENDABLE) {
1251+ if (pwallet-> IsMine (script) & ISMINE_SPENDABLE) {
12231252 throw JSONRPCError (RPC_WALLET_ERROR, " The wallet already contains the private key for this address or script (\" " + HexStr (script.begin (), script.end ()) + " \" )" );
12241253 }
12251254 }
@@ -1339,6 +1368,11 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
13391368
13401369 RPCTypeCheck (mainRequest.params , {UniValue::VARR, UniValue::VOBJ});
13411370
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+
13421376 const UniValue& requests = mainRequest.params [0 ];
13431377
13441378 // Default options
0 commit comments