Skip to content

Commit

Permalink
adds activemasternode.conf export function
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-at-decenomy committed Nov 4, 2024
1 parent bf18ee2 commit 9469fba
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/masternodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,28 @@ bool CMasternodeConfig::CMasternodeEntry::castOutputIndex(int &n) const

return true;
}

bool CMasternodeConfig::exportActiveMasternodes(std::string filename)
{
try {
std::ofstream file(filename);

if (!file.is_open()) {
return false;
}

// Iterate through entries and write to the file
for (const auto& mne : entries) {
std::string line = mne.getAlias() + " " + mne.getPrivKey() + "\n";
file << line;

if (file.fail()) {
return false;
}
}
} catch (const std::exception& e) {
return false;
}

return true;
}
2 changes: 2 additions & 0 deletions src/masternodeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class CMasternodeConfig
return false;
}

bool exportActiveMasternodes(std::string filename);

private:
std::vector<CMasternodeEntry> entries;
};
Expand Down
10 changes: 10 additions & 0 deletions src/qt/pivx/forms/masternodeswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ and vote on the treasury system receiving a periodic reward.</string>
</property>
</widget>
</item>
<item>
<widget class="OptionButton" name="btnExportActivemasternodeConf" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
Expand Down
20 changes: 20 additions & 0 deletions src/qt/pivx/masternodeswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
ui->btnAboutController->setSubTitleClassAndText("text-subtitle", tr("FAQ explaining what is a Masternode Controller"));
ui->btnMasternodeConf->setTitleClassAndText("btn-title-grey", tr("masternode.conf"));
ui->btnMasternodeConf->setSubTitleClassAndText("text-subtitle", tr("Opens the masternode configuration file for editing"));
ui->btnExportActivemasternodeConf->setTitleClassAndText("btn-title-grey", tr("Export activemasternode.conf"));
ui->btnExportActivemasternodeConf->setSubTitleClassAndText("text-subtitle", tr("Exports the masternode list as a activemasternode.conf file"));

setCssProperty(ui->listMn, "container");
ui->listMn->setItemDelegate(delegate);
Expand Down Expand Up @@ -138,6 +140,24 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
inform(tr("Unable to open masternode.conf with default application"));
}
});
connect(ui->btnExportActivemasternodeConf, &OptionButton::clicked, [this](){
QString filename =
GUIUtil::getSaveFileName(
this,
tr("Export activemasternode.conf"),
tr("activemasternode.conf"),
tr("activemasternode.conf (*.conf)"),
NULL
);

if (!filename.isEmpty()) {
if(masternodeConfig.exportActiveMasternodes(filename.toStdString())) {
inform(tr("activemasternode.conf file exported to file: ") + filename);
} else {
inform(tr("Error exporting activemasternode.conf file"));
}
}
});
}

void MasterNodesWidget::showEvent(QShowEvent *event)
Expand Down

0 comments on commit 9469fba

Please sign in to comment.