7 #include <boost/filesystem.hpp> 8 #include <boost/filesystem/fstream.hpp> 20 boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile);
22 if (!streamConfig.good()) {
23 FILE* configFile = fopen(pathMasternodeConfigFile.string().c_str(),
"a");
24 if (configFile != NULL) {
25 std::string strHeader =
"# Masternode config file\n" 26 "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n" 27 "# Example: mn1 127.0.0.2:19999 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n";
28 fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile);
34 for(std::string line; std::getline(streamConfig, line); linenumber++)
36 if(line.empty())
continue;
38 std::istringstream iss(line);
39 std::string comment,
alias, ip, privKey, txHash, outputIndex;
42 if(comment.at(0) ==
'#')
continue;
47 if (!(iss >>
alias >> ip >> privKey >> txHash >> outputIndex)) {
50 if (!(iss >>
alias >> ip >> privKey >> txHash >> outputIndex)) {
51 strErr =
_(
"Could not parse masternode.conf") +
"\n" +
52 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"";
59 std::string hostname =
"";
61 if(
port == 0 || hostname ==
"") {
62 strErr =
_(
"Failed to parse host:port string") +
"\n"+
63 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"";
69 if(
port != mainnetDefaultPort) {
70 strErr =
_(
"Invalid port detected in masternode.conf") +
"\n" +
72 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"" +
"\n" +
73 strprintf(
_(
"(must be %d for mainnet)"), mainnetDefaultPort);
77 }
else if(
port == mainnetDefaultPort) {
78 strErr =
_(
"Invalid port detected in masternode.conf") +
"\n" +
79 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"" +
"\n" +
80 strprintf(
_(
"(%d could be used only on mainnet)"), mainnetDefaultPort);
86 add(
alias, ip, privKey, txHash, outputIndex);
CMasternodeConfig masternodeConfig
bool read(std::string &strErr)
std::vector< CMasternodeEntry > entries
int GetDefaultPort() const
void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex)
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
const CChainParams & Params()
boost::filesystem::path GetMasternodeConfigFile()
static const std::string MAIN
std::string _(const char *psz)
FDELT_TYPE alias("__fdelt_warn")))