dash/src/masternodeconfig.cpp

64 lines
2.1 KiB
C++
Raw Normal View History

2015-01-09 20:45:41 +01:00
#include "net.h"
#include "masternodeconfig.h"
#include "util.h"
#include "ui_interface.h"
#include <base58.h>
CMasternodeConfig masternodeConfig;
void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) {
CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex);
entries.push_back(cme);
}
bool CMasternodeConfig::read(std::string& strErr) {
int linenumber = 1;
boost::filesystem::ifstream streamConfig(GetMasternodeConfigFile());
if (!streamConfig.good()) {
return true; // No masternode.conf file is OK
}
for(std::string line; std::getline(streamConfig, line); linenumber++)
{
if(line.empty()) {
continue;
}
std::istringstream iss(line);
std::string alias, ip, privKey, txHash, outputIndex;
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
iss.str(line);
iss.clear();
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
strErr = _("Could not parse masternode.conf") + "\n" +
strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"";
streamConfig.close();
return false;
}
}
2015-01-09 20:45:41 +01:00
2015-04-03 00:51:08 +02:00
if(Params().NetworkID() == CBaseChainParams::MAIN) {
2015-03-11 20:26:39 +01:00
if(CService(ip).GetPort() != 9999) {
strErr = _("Invalid port detected in masternode.conf") + "\n" +
strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" +
_("(must be 9999 for mainnet)");
2015-03-11 20:26:39 +01:00
streamConfig.close();
return false;
}
} else if(CService(ip).GetPort() == 9999) {
strErr = _("Invalid port detected in masternode.conf") + "\n" +
strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" +
_("(9999 could be used only on mainnet)");
2015-01-09 20:45:41 +01:00
streamConfig.close();
return false;
2015-03-11 20:26:39 +01:00
}
2015-01-09 20:45:41 +01:00
add(alias, ip, privKey, txHash, outputIndex);
}
streamConfig.close();
return true;
}