25 for (
int i = 0; i < ((int)
entries.size()); ++i) {
42 if (!streamConfig.good()) {
44 if (configFile !=
nullptr) {
45 std::string strHeader =
"# Masternode config file\n"
46 "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n"
47 "# Example: mn1 127.0.0.2:51472 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0"
49 fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile);
55 for (std::string line; std::getline(streamConfig, line); linenumber++) {
56 if (line.empty())
continue;
58 std::istringstream iss(line);
59 std::string comment, alias,
ip, privKey, txHash, outputIndex;
62 if (comment.at(0) ==
'#')
continue;
67 if (!(iss >> alias >>
ip >> privKey >> txHash >> outputIndex)) {
70 if (!(iss >> alias >>
ip >> privKey >> txHash >> outputIndex)) {
71 strErr =
_(
"Could not parse masternode.conf") +
"\n" +
72 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"";
80 std::string hostname =
"";
82 if(port == 0 || hostname ==
"") {
83 strErr =
_(
"Failed to parse host:port string") +
"\n"+
84 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" + line +
"\"";
89 if (port != nDefaultPort && !
Params().IsRegTestNet()) {
90 strErr =
strprintf(
_(
"Invalid port %d detected in masternode.conf"), port) +
"\n" +
91 strprintf(
_(
"Line: %d"), linenumber) +
"\n\"" +
ip +
"\"" +
"\n" +
92 strprintf(
_(
"(must be %d for %s-net)"), nDefaultPort,
Params().NetworkIDString());
98 add(alias,
ip, privKey, txHash, outputIndex);
101 streamConfig.close();
109 }
catch (
const std::exception& e) {
110 LogPrintf(
"%s: %s on getOutputIndex\n", __func__, e.what());
const CChainParams & Params()
Return the currently selected parameters.
int GetDefaultPort() const
bool castOutputIndex(int &n) const
const std::string & getAlias() const
bool read(std::string &strErr)
void remove(std::string alias)
CMasternodeConfig::CMasternodeEntry * add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex)
std::vector< CMasternodeEntry > entries
CMasternodeConfig masternodeConfig
FILE * fopen(const fs::path &p, const char *mode)
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
fs::path GetMasternodeConfigFile()
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.