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;
|
2015-08-08 12:49:55 +02:00
|
|
|
boost::filesystem::path pathMasternodeConfigFile = GetMasternodeConfigFile();
|
|
|
|
boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile);
|
2015-07-10 18:08:50 +02:00
|
|
|
|
2014-12-27 13:47:08 +01:00
|
|
|
if (!streamConfig.good()) {
|
2015-08-08 12:49:55 +02:00
|
|
|
FILE* configFile = fopen(pathMasternodeConfigFile.string().c_str(), "a");
|
|
|
|
if (configFile != NULL) {
|
|
|
|
std::string strHeader = "# Masternode config file\n"
|
|
|
|
"# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n"
|
|
|
|
"# Example: mn1 127.0.0.2:19999 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n";
|
|
|
|
fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile);
|
|
|
|
fclose(configFile);
|
|
|
|
}
|
|
|
|
return true; // Nothing to read, so just return
|
2014-12-27 13:47:08 +01:00
|
|
|
}
|
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
|
|
|
{
|
2015-08-08 12:49:55 +02:00
|
|
|
if(line.empty()) continue;
|
|
|
|
|
2014-12-27 13:47:08 +01:00
|
|
|
std::istringstream iss(line);
|
2015-08-08 12:49:55 +02:00
|
|
|
std::string comment, alias, ip, privKey, txHash, outputIndex;
|
|
|
|
|
|
|
|
if (iss >> comment) {
|
|
|
|
if(comment.at(0) == '#') continue;
|
|
|
|
iss.str(line);
|
|
|
|
iss.clear();
|
|
|
|
}
|
|
|
|
|
2015-06-23 18:38:28 +02:00
|
|
|
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
|
|
|
}
|