Skip to content

Commit f914746

Browse files
remove other rpc references to pwalletMain
1 parent d7474fd commit f914746

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

src/wallet/rpcdump.cpp

+20-18
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ UniValue importwallet(const JSONRPCRequest& request)
533533

534534
UniValue 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

707708
UniValue 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 {

src/wallet/rpcwallet.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
453453

454454
UniValue instantsendtoaddress(const JSONRPCRequest& request)
455455
{
456-
if (!EnsureWalletIsAvailable(request.fHelp))
456+
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
457+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
457458
return NullUniValue;
458459

459460
if (request.fHelp || request.params.size() < 2 || request.params.size() > 5)
@@ -480,7 +481,7 @@ UniValue instantsendtoaddress(const JSONRPCRequest& request)
480481
+ HelpExampleRpc("instantsendtoaddress", "\"XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwG\", 0.1, \"donation\", \"seans outpost\"")
481482
);
482483

483-
LOCK2(cs_main, pwalletMain->cs_wallet);
484+
LOCK2(cs_main, pwallet->cs_wallet);
484485

485486
CBitcoinAddress address(request.params[0].get_str());
486487
if (!address.IsValid())
@@ -502,9 +503,9 @@ UniValue instantsendtoaddress(const JSONRPCRequest& request)
502503
if (request.params.size() > 4)
503504
fSubtractFeeFromAmount = request.params[4].get_bool();
504505

505-
EnsureWalletIsUnlocked();
506+
EnsureWalletIsUnlocked(pwallet);
506507

507-
SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, wtx, true);
508+
SendMoney(pwallet, address.Get(), nAmount, fSubtractFeeFromAmount, wtx, true);
508509

509510
return wtx.GetHash().GetHex();
510511
}
@@ -564,7 +565,8 @@ UniValue listaddressgroupings(const JSONRPCRequest& request)
564565

565566
UniValue listaddressbalances(const JSONRPCRequest& request)
566567
{
567-
if (!EnsureWalletIsAvailable(request.fHelp))
568+
CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
569+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
568570
return NullUniValue;
569571

570572
if (request.fHelp || request.params.size() > 1)
@@ -585,7 +587,7 @@ UniValue listaddressbalances(const JSONRPCRequest& request)
585587
+ HelpExampleRpc("listaddressbalances", "10")
586588
);
587589

588-
LOCK2(cs_main, pwalletMain->cs_wallet);
590+
LOCK2(cs_main, pwallet->cs_wallet);
589591

590592
CAmount nMinAmount = 0;
591593
if (request.params.size() > 0)
@@ -595,7 +597,7 @@ UniValue listaddressbalances(const JSONRPCRequest& request)
595597
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
596598

597599
UniValue jsonBalances(UniValue::VOBJ);
598-
std::map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
600+
std::map<CTxDestination, CAmount> balances = pwallet->GetAddressBalances();
599601
for (auto& balance : balances)
600602
if (balance.second >= nMinAmount)
601603
jsonBalances.push_back(Pair(CBitcoinAddress(balance.first).ToString(), ValueFromAmount(balance.second)));
@@ -1259,7 +1261,7 @@ UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bool fByA
12591261
if (it == mapTally.end() && !fIncludeEmpty)
12601262
continue;
12611263

1262-
isminefilter mine = IsMine(*pwalletMain, address.Get());
1264+
isminefilter mine = IsMine(*pwallet, address.Get());
12631265
if(!(mine & filter))
12641266
continue;
12651267

@@ -2091,13 +2093,13 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
20912093
if (request.params.size() >= 3)
20922094
fForMixingOnly = request.params[2].get_bool();
20932095

2094-
if (fForMixingOnly && !pwalletMain->IsLocked(true) && pwalletMain->IsLocked())
2096+
if (fForMixingOnly && !pwallet->IsLocked(true) && pwallet->IsLocked())
20952097
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked for mixing only.");
20962098

2097-
if (!pwalletMain->IsLocked())
2099+
if (!pwallet->IsLocked())
20982100
throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already fully unlocked.");
20992101

2100-
if (!pwalletMain->Unlock(strWalletPass, fForMixingOnly))
2102+
if (!pwallet->Unlock(strWalletPass, fForMixingOnly))
21012103
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
21022104

21032105
pwallet->TopUpKeyPool();
@@ -2778,7 +2780,7 @@ UniValue listunspent(const JSONRPCRequest& request)
27782780
entry.push_back(Pair("confirmations", out.nDepth));
27792781
entry.push_back(Pair("spendable", out.fSpendable));
27802782
entry.push_back(Pair("solvable", out.fSolvable));
2781-
entry.push_back(Pair("ps_rounds", pwalletMain->GetCappedOutpointPrivateSendRounds(COutPoint(out.tx->GetHash(), out.i))));
2783+
entry.push_back(Pair("ps_rounds", pwallet->GetCappedOutpointPrivateSendRounds(COutPoint(out.tx->GetHash(), out.i))));
27822784
results.push_back(entry);
27832785
}
27842786

0 commit comments

Comments
 (0)