@@ -533,7 +533,8 @@ UniValue importwallet(const JSONRPCRequest& request)
533533
534534UniValue importelectrumwallet (const JSONRPCRequest& request)
535535{
536- if (!EnsureWalletIsAvailable (request.fHelp ))
536+ CWallet* const pwallet = GetWalletForJSONRPCRequest (request);
537+ if (!EnsureWalletIsAvailable (pwallet, request.fHelp ))
537538 return NullUniValue;
538539
539540 if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
@@ -555,9 +556,9 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
555556 if (fPruneMode )
556557 throw JSONRPCError (RPC_WALLET_ERROR, " Importing wallets is disabled in pruned mode" );
557558
558- LOCK2 (cs_main, pwalletMain ->cs_wallet );
559+ LOCK2 (cs_main, pwallet ->cs_wallet );
559560
560- EnsureWalletIsUnlocked ();
561+ EnsureWalletIsUnlocked (pwallet );
561562
562563 std::ifstream file;
563564 std::string strFileName = request.params [0 ].get_str ();
@@ -578,11 +579,11 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
578579 int64_t nFilesize = std::max ((int64_t )1 , (int64_t )file.tellg ());
579580 file.seekg (0 , file.beg );
580581
581- pwalletMain ->ShowProgress (_ (" Importing..." ), 0 ); // show progress dialog in GUI
582+ pwallet ->ShowProgress (_ (" Importing..." ), 0 ); // show progress dialog in GUI
582583
583584 if (strFileExt == " csv" ) {
584585 while (file.good ()) {
585- pwalletMain ->ShowProgress (" " , std::max (1 , std::min (99 , (int )(((double )file.tellg () / (double )nFilesize) * 100 ))));
586+ pwallet ->ShowProgress (" " , std::max (1 , std::min (99 , (int )(((double )file.tellg () / (double )nFilesize) * 100 ))));
586587 std::string line;
587588 std::getline (file, line);
588589 if (line.empty () || line == " address,private_key" )
@@ -598,12 +599,12 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
598599 CPubKey pubkey = key.GetPubKey ();
599600 assert (key.VerifyPubKey (pubkey));
600601 CKeyID keyid = pubkey.GetID ();
601- if (pwalletMain ->HaveKey (keyid)) {
602+ if (pwallet ->HaveKey (keyid)) {
602603 LogPrintf (" Skipping import of %s (key already present)\n " , CBitcoinAddress (keyid).ToString ());
603604 continue ;
604605 }
605606 LogPrintf (" Importing %s...\n " , CBitcoinAddress (keyid).ToString ());
606- if (!pwalletMain ->AddKeyPubKey (key, pubkey)) {
607+ if (!pwallet ->AddKeyPubKey (key, pubkey)) {
607608 fGood = false ;
608609 continue ;
609610 }
@@ -620,7 +621,7 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
620621 std::vector<std::string> vKeys = data.getKeys ();
621622
622623 for (size_t i = 0 ; i < data.size (); i++) {
623- pwalletMain ->ShowProgress (" " , std::max (1 , std::min (99 , int (i*100 /data.size ()))));
624+ pwallet ->ShowProgress (" " , std::max (1 , std::min (99 , int (i*100 /data.size ()))));
624625 if (!data[vKeys[i]].isStr ())
625626 continue ;
626627 CBitcoinSecret vchSecret;
@@ -630,19 +631,19 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
630631 CPubKey pubkey = key.GetPubKey ();
631632 assert (key.VerifyPubKey (pubkey));
632633 CKeyID keyid = pubkey.GetID ();
633- if (pwalletMain ->HaveKey (keyid)) {
634+ if (pwallet ->HaveKey (keyid)) {
634635 LogPrintf (" Skipping import of %s (key already present)\n " , CBitcoinAddress (keyid).ToString ());
635636 continue ;
636637 }
637638 LogPrintf (" Importing %s...\n " , CBitcoinAddress (keyid).ToString ());
638- if (!pwalletMain ->AddKeyPubKey (key, pubkey)) {
639+ if (!pwallet ->AddKeyPubKey (key, pubkey)) {
639640 fGood = false ;
640641 continue ;
641642 }
642643 }
643644 }
644645 file.close ();
645- pwalletMain ->ShowProgress (" " , 100 ); // hide progress dialog in GUI
646+ pwallet ->ShowProgress (" " , 100 ); // hide progress dialog in GUI
646647
647648 // Whether to perform rescan after import
648649 int nStartHeight = 0 ;
@@ -653,10 +654,10 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
653654
654655 // Assume that electrum wallet was created at that block
655656 int nTimeBegin = chainActive[nStartHeight]->GetBlockTime ();
656- pwalletMain ->UpdateTimeFirstKey (nTimeBegin);
657+ pwallet ->UpdateTimeFirstKey (nTimeBegin);
657658
658659 LogPrintf (" Rescanning %i blocks\n " , chainActive.Height () - nStartHeight + 1 );
659- pwalletMain ->ScanForWalletTransactions (chainActive[nStartHeight], true );
660+ pwallet ->ScanForWalletTransactions (chainActive[nStartHeight], true );
660661
661662 if (!fGood )
662663 throw JSONRPCError (RPC_WALLET_ERROR, " Error adding some keys to wallet" );
@@ -706,6 +707,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
706707
707708UniValue dumphdinfo (const JSONRPCRequest& request)
708709{
710+ CWallet* const pwallet = GetWalletForJSONRPCRequest (request);
709711 if (!EnsureWalletIsAvailable (request.fHelp ))
710712 return NullUniValue;
711713
@@ -724,15 +726,15 @@ UniValue dumphdinfo(const JSONRPCRequest& request)
724726 + HelpExampleRpc (" dumphdinfo" , " " )
725727 );
726728
727- LOCK (pwalletMain ->cs_wallet );
729+ LOCK (pwallet ->cs_wallet );
728730
729- EnsureWalletIsUnlocked ();
731+ EnsureWalletIsUnlocked (pwallet );
730732
731733 CHDChain hdChainCurrent;
732- if (!pwalletMain ->GetHDChain (hdChainCurrent))
734+ if (!pwallet ->GetHDChain (hdChainCurrent))
733735 throw JSONRPCError (RPC_WALLET_ERROR, " This wallet is not a HD wallet." );
734736
735- if (!pwalletMain ->GetDecryptedHDChain (hdChainCurrent))
737+ if (!pwallet ->GetDecryptedHDChain (hdChainCurrent))
736738 throw JSONRPCError (RPC_INTERNAL_ERROR, " Cannot decrypt HD seed" );
737739
738740 SecureString ssMnemonic;
@@ -855,7 +857,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
855857 if (pwallet->GetKey (keyid, key)) {
856858 file << strprintf (" %s %s " , CBitcoinSecret (key).ToString (), strTime);
857859 if (pwallet->mapAddressBook .count (keyid)) {
858- file << strprintf (" label=%s" , EncodeDumpString (pwalletMain ->mapAddressBook [keyid].name ));
860+ file << strprintf (" label=%s" , EncodeDumpString (pwallet ->mapAddressBook [keyid].name ));
859861 } else if (setKeyPool.count (keyid)) {
860862 file << " reserve=1" ;
861863 } else {
0 commit comments