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-03-16 20:44:16 +01:00
|
|
|
#include <base58.h>
|
2014-12-06 20:41:53 +01:00
|
|
|
|
|
|
|
CMasternodeConfig masternodeConfig;
|
|
|
|
|
2015-03-16 20:44:16 +01:00
|
|
|
void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex, std::string donationAddress, std::string donationPercent) {
|
|
|
|
CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex, donationAddress, donationPercent);
|
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) {
|
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
|
|
|
|
2014-12-27 13:47:08 +01:00
|
|
|
for(std::string line; std::getline(streamConfig, line); )
|
|
|
|
{
|
|
|
|
if(line.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::istringstream iss(line);
|
2015-03-16 20:44:16 +01:00
|
|
|
std::string alias, ip, privKey, txHash, outputIndex, donation, donationAddress, donationPercent;
|
|
|
|
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex >> donation)) {
|
|
|
|
donationAddress = "";
|
|
|
|
donationPercent = "";
|
|
|
|
iss.str(line);
|
|
|
|
iss.clear();
|
|
|
|
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
|
|
|
|
strErr = "Could not parse masternode.conf line: " + line;
|
|
|
|
streamConfig.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
size_t pos = donation.find_first_of(":");
|
|
|
|
if(pos == string::npos) { // no ":" found
|
|
|
|
donationPercent = "100";
|
|
|
|
donationAddress = donation;
|
|
|
|
} else {
|
|
|
|
donationPercent = donation.substr(pos + 1);
|
|
|
|
donationAddress = donation.substr(0, pos);
|
|
|
|
}
|
|
|
|
CBitcoinAddress address(donationAddress);
|
|
|
|
if (!address.IsValid()) {
|
2015-03-18 00:06:58 +01:00
|
|
|
strErr = "Invalid Dash address in masternode.conf line: " + 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-03-11 20:26:39 +01:00
|
|
|
if(Params().NetworkID() == CChainParams::MAIN){
|
|
|
|
if(CService(ip).GetPort() != 9999) {
|
|
|
|
strErr = "Invalid port detected in masternode.conf: " + line + " (must be 9999 for mainnet)";
|
|
|
|
streamConfig.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if(CService(ip).GetPort() == 9999) {
|
|
|
|
strErr = "Invalid port detected in masternode.conf: " + line + " (9999 must be 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-03-16 20:44:16 +01:00
|
|
|
add(alias, ip, privKey, txHash, outputIndex, donationAddress, donationPercent);
|
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
|
|
|
}
|