diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -102,7 +102,7 @@ std::string getNetwork() override { return Params().NetworkIDString(); } void initLogging() override { InitLogging(); } void initParameterInteraction() override { InitParameterInteraction(); } - std::string getWarnings() override { return GetWarnings("gui"); } + std::string getWarnings() override { return GetWarnings(true); } bool baseInitialize(Config &config) override { return AppInitBasicSetup() && AppInitParameterInteraction(config) && AppInitSanityChecks() && AppInitLockDataDirectory(); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1565,7 +1565,7 @@ } obj.pushKV("softforks", softforks); - obj.pushKV("warnings", GetWarnings("statusbar")); + obj.pushKV("warnings", GetWarnings(false)); return obj; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -335,7 +335,7 @@ obj.pushKV("networkhashps", getnetworkhashps(config, request)); obj.pushKV("pooledtx", uint64_t(mempool.size())); obj.pushKV("chain", config.GetChainParams().NetworkIDString()); - obj.pushKV("warnings", GetWarnings("statusbar")); + obj.pushKV("warnings", GetWarnings(false)); return obj; } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -692,7 +692,7 @@ } } obj.pushKV("localaddresses", localAddresses); - obj.pushKV("warnings", GetWarnings("statusbar")); + obj.pushKV("warnings", GetWarnings(false)); return obj; } diff --git a/src/test/timedata_tests.cpp b/src/test/timedata_tests.cpp --- a/src/test/timedata_tests.cpp +++ b/src/test/timedata_tests.cpp @@ -66,7 +66,7 @@ MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); } - BOOST_CHECK(GetWarnings("gui").find("clock is wrong") != std::string::npos); + BOOST_CHECK(GetWarnings(true).find("clock is wrong") != std::string::npos); // nTimeOffset is not changed if the median of offsets exceeds // DEFAULT_MAX_TIME_ADJUSTMENT diff --git a/src/warnings.h b/src/warnings.h --- a/src/warnings.h +++ b/src/warnings.h @@ -15,12 +15,13 @@ /** * Format a string that describes several potential problems detected by the * core. - * strFor can have three values: - * - "statusbar": get all warnings - * - "gui": get all warnings, translated (where possible) for GUI + * @param[in] verbose bool + * - if true, get all warnings, translated (where possible), separated by
+ * - if false, get the most important warning + * @returns the warning string * This function only returns the highest priority warning of the set selected * by strFor. */ -std::string GetWarnings(const std::string &strFor); +std::string GetWarnings(bool verbose); #endif // BITCOIN_WARNINGS_H diff --git a/src/warnings.cpp b/src/warnings.cpp --- a/src/warnings.cpp +++ b/src/warnings.cpp @@ -35,50 +35,53 @@ fLargeWorkInvalidChainFound = flag; } -std::string GetWarnings(const std::string &strFor) { - std::string strStatusBar; - std::string strGUI; +std::string GetWarnings(bool verbose) { + std::string warnings_concise; + std::string warnings_verbose; const std::string uiAlertSeperator = "
"; LOCK(cs_warnings); if (!CLIENT_VERSION_IS_RELEASE) { - strStatusBar = "This is a pre-release test build - use at your own " - "risk - do not use for mining or merchant applications"; - strGUI = _("This is a pre-release test build - use at your own risk - " - "do not use for mining or merchant applications") - .translated; + warnings_concise = + "This is a pre-release test build - use at your own risk - do not " + "use for mining or merchant applications"; + warnings_verbose = + _("This is a pre-release test build - use at your own risk - do " + "not use for mining or merchant applications") + .translated; } // Misc warnings like out of disk space and clock is wrong if (strMiscWarning != "") { - strStatusBar = strMiscWarning; - strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning; + warnings_concise = strMiscWarning; + warnings_verbose += + (warnings_verbose.empty() ? "" : uiAlertSeperator) + strMiscWarning; } if (fLargeWorkForkFound) { - strStatusBar = "Warning: The network does not appear to fully agree! " - "Some miners appear to be experiencing issues."; - strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + - _("Warning: The network does not appear to fully agree! Some " - "miners appear to be experiencing issues.") - .translated; + warnings_concise = + "Warning: The network does not appear to fully agree! Some miners " + "appear to be experiencing issues."; + warnings_verbose += + (warnings_verbose.empty() ? "" : uiAlertSeperator) + + _("Warning: The network does not appear to fully agree! Some " + "miners appear to be experiencing issues.") + .translated; } else if (fLargeWorkInvalidChainFound) { - strStatusBar = "Warning: We do not appear to fully agree with our " - "peers! You may need to upgrade, or other nodes may " - "need to upgrade."; - strGUI += - (strGUI.empty() ? "" : uiAlertSeperator) + + warnings_concise = + "Warning: We do not appear to fully agree with our peers! You may " + "need to upgrade, or other nodes may need to upgrade."; + warnings_verbose += + (warnings_verbose.empty() ? "" : uiAlertSeperator) + _("Warning: We do not appear to fully agree with our peers! You " "may need to upgrade, or other nodes may need to upgrade.") .translated; } - if (strFor == "gui") { - return strGUI; - } else if (strFor == "statusbar") { - return strStatusBar; + if (verbose) { + return warnings_verbose; + } else { + return warnings_concise; } - assert(!"GetWarnings(): invalid parameter"); - return "error"; }