diff --git a/src/index/base.cpp b/src/index/base.cpp --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -23,7 +23,7 @@ template static void FatalError(const char *fmt, const Args &... args) { std::string strMessage = tfm::format(fmt, args...); - SetMiscWarning(strMessage); + SetMiscWarning(Untranslated(strMessage)); LogPrintf("*** %s\n", strMessage); AbortError(_("A fatal internal error occurred, see debug.log for details")); StartShutdown(); diff --git a/src/interfaces/node.h b/src/interfaces/node.h --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -11,6 +11,7 @@ #include // For Network #include // For SecureString +#include #include #include @@ -54,7 +55,7 @@ virtual void initParameterInteraction() = 0; //! Get warnings. - virtual std::string getWarnings() = 0; + virtual bilingual_str getWarnings() = 0; //! Initialize app dependencies. virtual bool baseInitialize(Config &config) = 0; diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -72,7 +72,7 @@ void initParameterInteraction() override { InitParameterInteraction(*Assert(m_context->args)); } - std::string getWarnings() override { return GetWarnings(true); } + bilingual_str getWarnings() override { return GetWarnings(true); } bool baseInitialize(Config &config) override { return AppInitBasicSetup(gArgs) && AppInitParameterInteraction(config, gArgs) && diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -151,7 +151,8 @@ void BitcoinABC::handleRunawayException(const std::exception *e) { PrintExceptionContinue(e, "Runaway exception"); - Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings())); + Q_EMIT runawayException( + QString::fromStdString(m_node.getWarnings().translated)); } void BitcoinABC::initialize(Config *config, RPCServer *rpcServer, @@ -789,11 +790,11 @@ } catch (const std::exception &e) { PrintExceptionContinue(&e, "Runaway exception"); app.handleRunawayException( - QString::fromStdString(app.node().getWarnings())); + QString::fromStdString(app.node().getWarnings().translated)); } catch (...) { PrintExceptionContinue(nullptr, "Runaway exception"); app.handleRunawayException( - QString::fromStdString(app.node().getWarnings())); + QString::fromStdString(app.node().getWarnings().translated)); } return EXIT_FAILURE; } diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -157,7 +157,7 @@ } QString ClientModel::getStatusBarWarnings() const { - return QString::fromStdString(m_node.getWarnings()); + return QString::fromStdString(m_node.getWarnings().translated); } OptionsModel *ClientModel::getOptionsModel() { diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include // For VersionBitsDeploymentInfo @@ -1577,7 +1578,7 @@ } obj.pushKV("softforks", softforks); - obj.pushKV("warnings", GetWarnings(false)); + obj.pushKV("warnings", GetWarnings(false).original); return obj; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -513,8 +514,7 @@ obj.pushKV("networkhashps", getnetworkhashps(config, request)); obj.pushKV("pooledtx", uint64_t(mempool.size())); obj.pushKV("chain", config.GetChainParams().NetworkIDString()); - obj.pushKV("warnings", GetWarnings(false)); - + obj.pushKV("warnings", GetWarnings(false).original); return obj; } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -706,7 +707,7 @@ } } obj.pushKV("localaddresses", localAddresses); - obj.pushKV("warnings", GetWarnings(false)); + obj.pushKV("warnings", GetWarnings(false).original); 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 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -67,7 +68,8 @@ MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); } - BOOST_CHECK(GetWarnings(true).find("clock is wrong") != std::string::npos); + BOOST_CHECK(GetWarnings(true).original.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/timedata.cpp b/src/timedata.cpp --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -107,7 +107,7 @@ "and time are correct! If your clock is " "wrong, %s will not work properly."), PACKAGE_NAME); - SetMiscWarning(strMessage.translated); + SetMiscWarning(strMessage); uiInterface.ThreadSafeMessageBox( strMessage, "", CClientUIInterface::MSG_WARNING); } diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1310,7 +1310,7 @@ /** Abort with a message */ static bool AbortNode(const std::string &strMessage, bilingual_str user_message = bilingual_str()) { - SetMiscWarning(strMessage); + SetMiscWarning(Untranslated(strMessage)); LogPrintf("*** %s\n", strMessage); if (!user_message.empty()) { user_message = diff --git a/src/warnings.h b/src/warnings.h --- a/src/warnings.h +++ b/src/warnings.h @@ -8,7 +8,10 @@ #include -void SetMiscWarning(const std::string &strWarning); +struct bilingual_str; + +void SetMiscWarning(const bilingual_str &strWarning); + void SetfLargeWorkForkFound(bool flag); bool GetfLargeWorkForkFound(); void SetfLargeWorkInvalidChainFound(bool flag); @@ -16,12 +19,12 @@ * Format a string that describes several potential problems detected by the * core. * @param[in] verbose bool - * - if true, get all warnings, translated (where possible), separated by
+ * - if true, get all warnings 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(bool verbose); +bilingual_str 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 @@ -7,17 +7,20 @@ #include #include +#include #include #include +#include + static Mutex g_warnings_mutex; -static std::string strMiscWarning GUARDED_BY(g_warnings_mutex); +static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex); static bool fLargeWorkForkFound GUARDED_BY(g_warnings_mutex) = false; static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false; -void SetMiscWarning(const std::string &strWarning) { +void SetMiscWarning(const bilingual_str &warning) { LOCK(g_warnings_mutex); - strMiscWarning = strWarning; + g_misc_warnings = warning; } void SetfLargeWorkForkFound(bool flag) { @@ -35,55 +38,41 @@ fLargeWorkInvalidChainFound = flag; } -std::string GetWarnings(bool verbose) { - std::string warnings_concise; - std::string warnings_verbose; - const std::string warning_separator = "
"; +bilingual_str GetWarnings(bool verbose) { + bilingual_str warnings_concise; + std::vector warnings_verbose; LOCK(g_warnings_mutex); // Pre-release build warning if (!CLIENT_VERSION_IS_RELEASE) { - warnings_concise = + 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; + "use for mining or merchant applications"); + warnings_verbose.emplace_back(warnings_concise); } // Misc warnings like out of disk space and clock is wrong - if (strMiscWarning != "") { - warnings_concise = strMiscWarning; - warnings_verbose += - (warnings_verbose.empty() ? "" : warning_separator) + - strMiscWarning; + if (!g_misc_warnings.empty()) { + warnings_concise = g_misc_warnings; + warnings_verbose.emplace_back(warnings_concise); } if (fLargeWorkForkFound) { - warnings_concise = + warnings_concise = _( "Warning: The network does not appear to fully agree! Some miners " - "appear to be experiencing issues."; - warnings_verbose += - (warnings_verbose.empty() ? "" : warning_separator) + - _("Warning: The network does not appear to fully agree! Some " - "miners appear to be experiencing issues.") - .translated; + "appear to be experiencing issues."); + warnings_verbose.emplace_back(warnings_concise); } else if (fLargeWorkInvalidChainFound) { - warnings_concise = + 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() ? "" : warning_separator) + - _("Warning: We do not appear to fully agree with our peers! You " - "may need to upgrade, or other nodes may need to upgrade.") - .translated; + "need to upgrade, or other nodes may need to upgrade."); + warnings_verbose.emplace_back(warnings_concise); } if (verbose) { - return warnings_verbose; - } else { - return warnings_concise; + return Join(warnings_verbose, Untranslated("
")); } + + return warnings_concise; }