Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure pwalletMain is not null whenever it's used in PS client #2190

Merged
merged 2 commits into from
Jul 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/privatesend-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ void CPrivateSendClient::SetNull()
//
void CPrivateSendClient::UnlockCoins()
{
if (!pwalletMain) return;

while(true) {
TRY_LOCK(pwalletMain->cs_wallet, lockWallet);
if(!lockWallet) {MilliSleep(50); continue;}
Expand Down Expand Up @@ -486,6 +488,8 @@ bool CPrivateSendClient::CheckPoolStateUpdate(PoolState nStateNew, int nEntriesC
//
bool CPrivateSendClient::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman)
{
if (!pwalletMain) return false;

if(fMasternodeMode || pnode == nullptr) return false;

finalMutableTransaction = finalTransactionNew;
Expand Down Expand Up @@ -619,6 +623,13 @@ bool CPrivateSendClient::WaitForAnotherBlock()

bool CPrivateSendClient::CheckAutomaticBackup()
{
if (!pwalletMain) {
LogPrint("privatesend", "CPrivateSendClient::CheckAutomaticBackup -- Wallet is not initialized, no mixing available.\n");
strAutoDenomResult = _("Wallet is not initialized") + ", " + _("no mixing available.");
fEnablePrivateSend = false; // no mixing
return false;
}

switch(nWalletBackups) {
case 0:
LogPrint("privatesend", "CPrivateSendClient::CheckAutomaticBackup -- Automatic backups disabled, no mixing available.\n");
Expand Down Expand Up @@ -837,6 +848,8 @@ bool CPrivateSendClient::DoAutomaticDenominating(CConnman& connman, bool fDryRun

bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman)
{
if (!pwalletMain) return false;

std::vector<CAmount> vecStandardDenoms = CPrivateSend::GetStandardDenominations();
// Look through the queues and see if anything matches
for (auto& dsq : vecDarksendQueue) {
Expand Down Expand Up @@ -917,6 +930,8 @@ bool CPrivateSendClient::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CCon

bool CPrivateSendClient::StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsAnonymized, CConnman& connman)
{
if (!pwalletMain) return false;

int nTries = 0;
int nMnCountEnabled = mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION);

Expand Down Expand Up @@ -1198,6 +1213,8 @@ bool CPrivateSendClient::PrepareDenominate(int nMinRounds, int nMaxRounds, std::
// Create collaterals by looping through inputs grouped by addresses
bool CPrivateSendClient::MakeCollateralAmounts(CConnman& connman)
{
if (!pwalletMain) return false;

std::vector<CompactTallyItem> vecTally;
if(!pwalletMain->SelectCoinsGrouppedByAddresses(vecTally, false)) {
LogPrint("privatesend", "CPrivateSendClient::MakeCollateralAmounts -- SelectCoinsGrouppedByAddresses can't find any inputs!\n");
Expand All @@ -1224,6 +1241,8 @@ bool CPrivateSendClient::MakeCollateralAmounts(CConnman& connman)
// Split up large inputs or create fee sized inputs
bool CPrivateSendClient::MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated, CConnman& connman)
{
if (!pwalletMain) return false;

LOCK2(cs_main, pwalletMain->cs_wallet);

// denominated input is always a single one, so we can check its amount directly and return early
Expand Down Expand Up @@ -1296,6 +1315,8 @@ bool CPrivateSendClient::MakeCollateralAmounts(const CompactTallyItem& tallyItem
// Create denominations by looping through inputs grouped by addresses
bool CPrivateSendClient::CreateDenominated(CConnman& connman)
{
if (!pwalletMain) return false;

LOCK2(cs_main, pwalletMain->cs_wallet);

std::vector<CompactTallyItem> vecTally;
Expand All @@ -1318,6 +1339,8 @@ bool CPrivateSendClient::CreateDenominated(CConnman& connman)
// Create denominations
bool CPrivateSendClient::CreateDenominated(const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals, CConnman& connman)
{
if (!pwalletMain) return false;

std::vector<CRecipient> vecSend;
CKeyHolderStorage keyHolderStorageDenom;

Expand Down