@@ -533,7 +533,8 @@ UniValue importwallet(const JSONRPCRequest& request)
533
533
534
534
UniValue importelectrumwallet (const JSONRPCRequest& request)
535
535
{
536
- if (!EnsureWalletIsAvailable (request.fHelp ))
536
+ CWallet* const pwallet = GetWalletForJSONRPCRequest (request);
537
+ if (!EnsureWalletIsAvailable (pwallet, request.fHelp ))
537
538
return NullUniValue;
538
539
539
540
if (request.fHelp || request.params .size () < 1 || request.params .size () > 2 )
@@ -555,9 +556,9 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
555
556
if (fPruneMode )
556
557
throw JSONRPCError (RPC_WALLET_ERROR, " Importing wallets is disabled in pruned mode" );
557
558
558
- LOCK2 (cs_main, pwalletMain ->cs_wallet );
559
+ LOCK2 (cs_main, pwallet ->cs_wallet );
559
560
560
- EnsureWalletIsUnlocked ();
561
+ EnsureWalletIsUnlocked (pwallet );
561
562
562
563
std::ifstream file;
563
564
std::string strFileName = request.params [0 ].get_str ();
@@ -578,11 +579,11 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
578
579
int64_t nFilesize = std::max ((int64_t )1 , (int64_t )file.tellg ());
579
580
file.seekg (0 , file.beg );
580
581
581
- pwalletMain ->ShowProgress (_ (" Importing..." ), 0 ); // show progress dialog in GUI
582
+ pwallet ->ShowProgress (_ (" Importing..." ), 0 ); // show progress dialog in GUI
582
583
583
584
if (strFileExt == " csv" ) {
584
585
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 ))));
586
587
std::string line;
587
588
std::getline (file, line);
588
589
if (line.empty () || line == " address,private_key" )
@@ -598,12 +599,12 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
598
599
CPubKey pubkey = key.GetPubKey ();
599
600
assert (key.VerifyPubKey (pubkey));
600
601
CKeyID keyid = pubkey.GetID ();
601
- if (pwalletMain ->HaveKey (keyid)) {
602
+ if (pwallet ->HaveKey (keyid)) {
602
603
LogPrintf (" Skipping import of %s (key already present)\n " , CBitcoinAddress (keyid).ToString ());
603
604
continue ;
604
605
}
605
606
LogPrintf (" Importing %s...\n " , CBitcoinAddress (keyid).ToString ());
606
- if (!pwalletMain ->AddKeyPubKey (key, pubkey)) {
607
+ if (!pwallet ->AddKeyPubKey (key, pubkey)) {
607
608
fGood = false ;
608
609
continue ;
609
610
}
@@ -620,7 +621,7 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
620
621
std::vector<std::string> vKeys = data.getKeys ();
621
622
622
623
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 ()))));
624
625
if (!data[vKeys[i]].isStr ())
625
626
continue ;
626
627
CBitcoinSecret vchSecret;
@@ -630,19 +631,19 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
630
631
CPubKey pubkey = key.GetPubKey ();
631
632
assert (key.VerifyPubKey (pubkey));
632
633
CKeyID keyid = pubkey.GetID ();
633
- if (pwalletMain ->HaveKey (keyid)) {
634
+ if (pwallet ->HaveKey (keyid)) {
634
635
LogPrintf (" Skipping import of %s (key already present)\n " , CBitcoinAddress (keyid).ToString ());
635
636
continue ;
636
637
}
637
638
LogPrintf (" Importing %s...\n " , CBitcoinAddress (keyid).ToString ());
638
- if (!pwalletMain ->AddKeyPubKey (key, pubkey)) {
639
+ if (!pwallet ->AddKeyPubKey (key, pubkey)) {
639
640
fGood = false ;
640
641
continue ;
641
642
}
642
643
}
643
644
}
644
645
file.close ();
645
- pwalletMain ->ShowProgress (" " , 100 ); // hide progress dialog in GUI
646
+ pwallet ->ShowProgress (" " , 100 ); // hide progress dialog in GUI
646
647
647
648
// Whether to perform rescan after import
648
649
int nStartHeight = 0 ;
@@ -653,10 +654,10 @@ UniValue importelectrumwallet(const JSONRPCRequest& request)
653
654
654
655
// Assume that electrum wallet was created at that block
655
656
int nTimeBegin = chainActive[nStartHeight]->GetBlockTime ();
656
- pwalletMain ->UpdateTimeFirstKey (nTimeBegin);
657
+ pwallet ->UpdateTimeFirstKey (nTimeBegin);
657
658
658
659
LogPrintf (" Rescanning %i blocks\n " , chainActive.Height () - nStartHeight + 1 );
659
- pwalletMain ->ScanForWalletTransactions (chainActive[nStartHeight], true );
660
+ pwallet ->ScanForWalletTransactions (chainActive[nStartHeight], true );
660
661
661
662
if (!fGood )
662
663
throw JSONRPCError (RPC_WALLET_ERROR, " Error adding some keys to wallet" );
@@ -706,6 +707,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
706
707
707
708
UniValue dumphdinfo (const JSONRPCRequest& request)
708
709
{
710
+ CWallet* const pwallet = GetWalletForJSONRPCRequest (request);
709
711
if (!EnsureWalletIsAvailable (request.fHelp ))
710
712
return NullUniValue;
711
713
@@ -724,15 +726,15 @@ UniValue dumphdinfo(const JSONRPCRequest& request)
724
726
+ HelpExampleRpc (" dumphdinfo" , " " )
725
727
);
726
728
727
- LOCK (pwalletMain ->cs_wallet );
729
+ LOCK (pwallet ->cs_wallet );
728
730
729
- EnsureWalletIsUnlocked ();
731
+ EnsureWalletIsUnlocked (pwallet );
730
732
731
733
CHDChain hdChainCurrent;
732
- if (!pwalletMain ->GetHDChain (hdChainCurrent))
734
+ if (!pwallet ->GetHDChain (hdChainCurrent))
733
735
throw JSONRPCError (RPC_WALLET_ERROR, " This wallet is not a HD wallet." );
734
736
735
- if (!pwalletMain ->GetDecryptedHDChain (hdChainCurrent))
737
+ if (!pwallet ->GetDecryptedHDChain (hdChainCurrent))
736
738
throw JSONRPCError (RPC_INTERNAL_ERROR, " Cannot decrypt HD seed" );
737
739
738
740
SecureString ssMnemonic;
@@ -855,7 +857,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
855
857
if (pwallet->GetKey (keyid, key)) {
856
858
file << strprintf (" %s %s " , CBitcoinSecret (key).ToString (), strTime);
857
859
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 ));
859
861
} else if (setKeyPool.count (keyid)) {
860
862
file << " reserve=1" ;
861
863
} else {
0 commit comments