Skip to content

Commit

Permalink
Add checkbox to show only masternodes the wallet has keys for (#2627)
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Jan 15, 2019
1 parent 000fabf commit ee808d8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/qt/forms/masternodelist.ui
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxMyMasternodesOnly">
<property name="toolTip">
<string>Show only masternodes this wallet has keys for.</string>
</property>
<property name="text">
<string>My masternodes only</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
Expand Down
37 changes: 37 additions & 0 deletions src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ void MasternodeList::showContextMenuDIP3(const QPoint& point)
if (item) contextMenuDIP3->exec(QCursor::pos());
}

static bool CheckWalletOwnsScript(const CScript& script)
{
CTxDestination dest;
if (ExtractDestination(script, dest)) {
if ((boost::get<CKeyID>(&dest) && pwalletMain->HaveKey(*boost::get<CKeyID>(&dest))) || (boost::get<CScriptID>(&dest) && pwalletMain->HaveCScript(*boost::get<CScriptID>(&dest)))) {
return true;
}
}
return false;
}

void MasternodeList::updateDIP3List()
{
if (ShutdownRequested()) {
Expand Down Expand Up @@ -146,7 +157,26 @@ void MasternodeList::updateDIP3List()
nextPayments.emplace(dmn->proTxHash, mnList.GetHeight() + (int)i + 1);
}

std::set<COutPoint> setOutpts;
if (pwalletMain && ui->checkBoxMyMasternodesOnly->isChecked()) {
LOCK(pwalletMain->cs_wallet);
std::vector<COutPoint> vOutpts;
pwalletMain->ListProTxCoins(vOutpts);
for (const auto& outpt : vOutpts) {
setOutpts.emplace(outpt);
}
}

mnList.ForEachMN(false, [&](const CDeterministicMNCPtr& dmn) {
if (pwalletMain && ui->checkBoxMyMasternodesOnly->isChecked()) {
LOCK(pwalletMain->cs_wallet);
bool fMyMasternode = setOutpts.count(dmn->collateralOutpoint) ||
pwalletMain->HaveKey(dmn->pdmnState->keyIDOwner) ||
pwalletMain->HaveKey(dmn->pdmnState->keyIDVoting) ||
CheckWalletOwnsScript(dmn->pdmnState->scriptPayout) ||
CheckWalletOwnsScript(dmn->pdmnState->scriptOperatorPayout);
if (!fMyMasternode) return;
}
// populate list
// Address, Protocol, Status, Active Seconds, Last Seen, Pub Key
QTableWidgetItem* addressItem = new QTableWidgetItem(QString::fromStdString(dmn->pdmnState->addr.ToString()));
Expand Down Expand Up @@ -222,6 +252,13 @@ void MasternodeList::on_filterLineEditDIP3_textChanged(const QString& strFilterI
ui->countLabelDIP3->setText(QString::fromStdString(strprintf("Please wait... %d", MASTERNODELIST_FILTER_COOLDOWN_SECONDS)));
}

void MasternodeList::on_checkBoxMyMasternodesOnly_stateChanged(int state)
{
// no cooldown
nTimeFilterUpdatedDIP3 = GetTime() - MASTERNODELIST_FILTER_COOLDOWN_SECONDS;
fFilterUpdatedDIP3 = true;
}

CDeterministicMNCPtr MasternodeList::GetSelectedDIP3MN()
{
std::string strProTxHash;
Expand Down
1 change: 1 addition & 0 deletions src/qt/masternodelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Q_SLOTS:
private Q_SLOTS:
void showContextMenuDIP3(const QPoint&);
void on_filterLineEditDIP3_textChanged(const QString& strFilterIn);
void on_checkBoxMyMasternodesOnly_stateChanged(int state);

void extraInfoDIP3_clicked();
void copyProTxHash_clicked();
Expand Down

0 comments on commit ee808d8

Please sign in to comment.