2015-01-09 20:45:41 +01:00
|
|
|
|
|
|
|
#include "net.h"
|
2014-12-06 20:41:53 +01:00
|
|
|
#include "masternodeconfig.h"
|
|
|
|
#include "util.h"
|
2015-07-10 18:08:50 +02:00
|
|
|
#include "ui_interface.h"
|
2015-03-16 20:44:16 +01:00
|
|
|
#include <base58.h>
|
2014-12-06 20:41:53 +01:00
|
|
|
|
|
|
|
CMasternodeConfig masternodeConfig;
|
|
|
|
|
2015-06-23 18:38:28 +02:00
|
|
|
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);
|
2014-12-27 13:47:08 +01:00
|
|
|
entries.push_back(cme);
|
2014-12-06 20:41:53 +01:00
|
|
|
}
|
|
|
|
|
2015-01-11 18:28:28 +01:00
|
|
|
bool CMasternodeConfig::read(std::string& strErr) {
|
2015-07-10 18:08:50 +02:00
|
|
|
int linenumber = 1;
|
|
|
|
|
2014-12-27 13:47:08 +01:00
|
|
|
boost::filesystem::ifstream streamConfig(GetMasternodeConfigFile());
|
|
|
|
if (!streamConfig.good()) {
|
|
|
|
return true; // No masternode.conf file is OK
|
|
|
|
}
|
2014-12-06 20:41:53 +01:00
|
|
|
|
2015-07-10 18:08:50 +02:00
|
|
|
for(std::string line; std::getline(streamConfig, line); linenumber++)
|
2014-12-27 13:47:08 +01:00
|
|
|
{
|
|
|
|
if(line.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::istringstream iss(line);
|
2015-06-23 18:38:28 +02:00
|
|
|
std::string alias, ip, privKey, txHash, outputIndex;
|
|
|
|
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
|
2015-03-16 20:44:16 +01:00
|
|
|
iss.str(line);
|
|
|
|
iss.clear();
|
|
|
|
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
|
2015-07-10 18:08:50 +02:00
|
|
|
strErr = _("Could not parse masternode.conf") + "\n" +
|
|
|
|
strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"";
|
2015-03-16 20:44:16 +01:00
|
|
|
streamConfig.close();
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-06 20:41:53 +01:00
|
|
|
}
|
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) {
|
2015-07-10 18:08:50 +02:00
|
|
|
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) {
|
2015-07-10 18:08:50 +02:00
|
|
|
strErr = _("Invalid port detected in masternode.conf") + "\n" +
|
|
|
|
strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" +
|
2015-08-02 04:05:49 +02:00
|
|
|
_("(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
|
|
|
|
2015-06-23 18:38:28 +02:00
|
|
|
add(alias, ip, privKey, txHash, outputIndex);
|
2014-12-27 13:47:08 +01:00
|
|
|
}
|
2014-12-06 20:41:53 +01:00
|
|
|
|
2014-12-27 13:47:08 +01:00
|
|
|
streamConfig.close();
|
|
|
|
return true;
|
2014-12-06 20:41:53 +01:00
|
|
|
}
|