15 void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex)
25 fs::ifstream streamConfig(pathMasternodeConfigFile);
27 if (!streamConfig.good()) {
29 if (configFile != NULL) {
30 std::string strHeader =
"# Masternode config file\n"
31 "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n"
32 "# Example: mn1 127.0.0.2:59682 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n";
33 fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile);
39 for (std::string line; std::getline(streamConfig, line); linenumber++) {
40 if (line.empty())
continue;
42 std::istringstream iss(line);
43 std::string comment, alias, ip, privKey, txHash, outputIndex;
46 if (comment.at(0) ==
'#')
continue;
51 if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
54 if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
55 strErr =
_(
"Could not parse masternode.conf") +
"\n" +
56 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"";
64 std::string hostname =
"";
66 if(port == 0 || hostname ==
"") {
67 strErr =
_(
"Failed to parse host:port string") +
"\n"+
68 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"";
73 if (port != nDefaultPort) {
74 strErr =
strprintf(
_(
"Invalid port %d detected in masternode.conf"), port) +
"\n" +
75 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + ip +
"\"" +
"\n" +
76 strprintf(
_(
"(must be %d for %s-net)"), nDefaultPort,
Params().NetworkIDString());
82 add(alias, ip, privKey, txHash, outputIndex);
93 }
catch (
const std::exception e) {
94 LogPrintf(
"%s: %s on getOutputIndex\n", __func__, e.what());