MCPcopy Create free account
hub / github.com/LUX-Core/lux / read

Method read

src/masternodeconfig.cpp:19–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19bool CMasternodeConfig::read(std::string& strErr) {
20
21 int linenumber = 1;
22 boost::filesystem::path pathMasternodeConfigFile = GetMasternodeConfigFile();
23 boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile);
24
25 if (!streamConfig.good()) {
26 FILE* configFile = fopen(pathMasternodeConfigFile.string().c_str(), "a");
27 if (configFile != NULL) {
28 std::string strHeader = "# Masternode config file\n"
29 "# Format: alias IP:port masternodeprivkey collateral_output_txid collateral_output_index\n"
30 "# Example: mn1 127.0.0.2:26969 93HaYBVUCYjEMeeH1Y4sBGLALQZE1Yc1K64xiqgX37tGBDQL8Xg 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0\n";
31 fwrite(strHeader.c_str(), std::strlen(strHeader.c_str()), 1, configFile);
32 fclose(configFile);
33 }
34 return true; // Nothing to read, so just return
35 }
36
37 for (std::string line; std::getline(streamConfig, line); linenumber++) {
38 if (line.empty()) continue;
39
40 std::istringstream iss(line);
41 std::string comment, alias, ip, privKey, txHash, outputIndex;
42
43 if (iss >> comment) {
44 if (comment.at(0) == '#') continue;
45 iss.str(line);
46 iss.clear();
47 }
48
49 if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
50 iss.str(line);
51 iss.clear();
52 if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
53 LogPrintf("CMasternodeConfig::read - Could not parse masternode.conf. Line: %s\n", line.c_str());
54 streamConfig.close();
55 return false;
56 }
57 }
58
59 if (Params().NetworkID() == CBaseChainParams::MAIN) {
60 if (CService(ip).GetPort() != 26969) {
61 LogPrintf("Invalid port detected in masternode.conf: %s (must be 26969 for mainnet)\n", line.c_str());
62 streamConfig.close();
63 return false;
64 }
65 } else if (CService(ip).GetPort() == 26969) {
66 LogPrintf("Invalid port detected in masternode.conf: %s (26969 must be only on mainnet)\n", line.c_str());
67 streamConfig.close();
68 return false;
69 }
70
71 if (!(CService(ip).IsIPv4() && CService(ip).IsRoutable())) {
72 LogPrintf("Invalid Address detected in masternode.conf: %s (IPV4 ONLY) \n", line.c_str());
73 streamConfig.close();
74 return false;
75 }
76

Callers

nothing calls this directly

Calls 12

GetMasternodeConfigFileFunction · 0.85
strMethod · 0.80
NetworkIDMethod · 0.80
GetPortMethod · 0.80
IsIPv4Method · 0.80
IsRoutableMethod · 0.80
ParamsClass · 0.70
CServiceClass · 0.70
emptyMethod · 0.45
atMethod · 0.45
clearMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected