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

Add checkbox to show only masternodes the wallet has keys for #2627

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
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
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