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

This commit is contained in:
UdjinM6 2019-01-15 15:46:02 +03:00 committed by Alexander Block
parent 942838e937
commit 332e0361c7
3 changed files with 48 additions and 0 deletions

View File

@ -356,6 +356,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">

View File

@ -148,6 +148,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::StartAlias(std::string strAlias)
{
std::string strStatusHtml;
@ -442,7 +453,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()));
@ -701,6 +731,13 @@ void MasternodeList::ShowQRCode(std::string strAlias)
dialog->show();
}
void MasternodeList::on_checkBoxMyMasternodesOnly_stateChanged(int state)
{
// no cooldown
nTimeFilterUpdatedDIP3 = GetTime() - MASTERNODELIST_FILTER_COOLDOWN_SECONDS;
fFilterUpdatedDIP3 = true;
}
CDeterministicMNCPtr MasternodeList::GetSelectedDIP3MN()
{
std::string strProTxHash;

View File

@ -90,6 +90,7 @@ private Q_SLOTS:
void on_startMissingButton_clicked();
void on_tableWidgetMyMasternodes_itemSelectionChanged();
void on_UpdateButton_clicked();
void on_checkBoxMyMasternodesOnly_stateChanged(int state);
void extraInfoDIP3_clicked();
void copyProTxHash_clicked();