Merge #19233: Make SetMiscWarning() accept bilingual_str argument

d49612f98add29066817b7c808b76c2d728948e5 Make SetMiscWarning() accept bilingual_str argument (Hennadii Stepanov)
d1ae7c0355662481a7d181a0a458284936d53eb1 Make GetWarnings() return bilingual_str (Hennadii Stepanov)
38e33aa481cefbe12c50f344bae190c0d95fb489 refactor: Make GetWarnings() bilingual_str aware internally (Hennadii Stepanov)

Pull request description:

  This is one more step for consistent usage of `bilingual_str`.

  No new translation messages are defined.

ACKs for top commit:
  laanwj:
    Code review ACK d49612f98add29066817b7c808b76c2d728948e5
  MarcoFalke:
    ACK d49612f98add29066817b7c808b76c2d728948e5 🌂

Tree-SHA512: 7413cb94a85291209c182845f6873350bb9e9ce940647d416c462a136603832fec8a63d792341bf634f07629767c78bc206d3a318cf10c7e87241c114c2496e9
This commit is contained in:
MarcoFalke 2020-06-10 09:50:50 -04:00 committed by pasta
parent 08c75adce7
commit 673111c448
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
15 changed files with 54 additions and 42 deletions

View File

@ -22,7 +22,7 @@ template <typename... Args>
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();

View File

@ -11,6 +11,7 @@
#include <netaddress.h> // For Network
#include <support/allocators/secure.h> // For SecureString
#include <uint256.h>
#include <util/translation.h>
#include <functional>
#include <memory>
@ -171,7 +172,7 @@ public:
virtual void initParameterInteraction() = 0;
//! Get warnings.
virtual std::string getWarnings() = 0;
virtual bilingual_str getWarnings() = 0;
// Get log flags.
virtual uint64_t getLogCategories() = 0;

View File

@ -246,7 +246,7 @@ public:
std::string getNetwork() override { return Params().NetworkIDString(); }
void initLogging() override { InitLogging(gArgs); }
void initParameterInteraction() override { InitParameterInteraction(gArgs); }
std::string getWarnings() override { return GetWarnings(true); }
bilingual_str getWarnings() override { return GetWarnings(true); }
uint64_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
bool baseInitialize() override
{

View File

@ -143,7 +143,7 @@ BitcoinCore::BitcoinCore(interfaces::Node& node) :
void BitcoinCore::handleRunawayException(const std::exception_ptr e)
{
PrintExceptionContinue(e, "Runaway exception");
Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings()));
Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings().translated));
}
void BitcoinCore::initialize()
@ -747,7 +747,7 @@ int GuiMain(int argc, char* argv[])
}
} catch (...) {
PrintExceptionContinue(std::current_exception(), "Runaway exception");
app.handleRunawayException(QString::fromStdString(node->getWarnings()));
app.handleRunawayException(QString::fromStdString(node->getWarnings().translated));
}
return rv;
}

View File

@ -202,7 +202,7 @@ enum BlockSource ClientModel::getBlockSource() const
QString ClientModel::getStatusBarWarnings() const
{
return QString::fromStdString(m_node.getWarnings());
return QString::fromStdString(m_node.getWarnings().translated);
}
OptionsModel *ClientModel::getOptionsModel()

View File

@ -37,6 +37,7 @@
#include <undo.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
#include <versionbits.h>
@ -1766,7 +1767,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
obj.pushKV("softforks", softforks);
obj.pushKV("warnings", GetWarnings(false));
obj.pushKV("warnings", GetWarnings(false).original);
return obj;
}

View File

@ -39,6 +39,7 @@
#include <util/strencodings.h>
#include <util/string.h>
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
#include <warnings.h>
@ -459,7 +460,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
obj.pushKV("networkhashps", getnetworkhashps(request));
obj.pushKV("pooledtx", (uint64_t)mempool.size());
obj.pushKV("chain", Params().NetworkIDString());
obj.pushKV("warnings", GetWarnings(false));
obj.pushKV("warnings", GetWarnings(false).original);
return obj;
}

View File

@ -23,6 +23,7 @@
#include <util/strencodings.h>
#include <util/string.h>
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
#include <version.h>
#include <warnings.h>
@ -594,7 +595,7 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
}
}
obj.pushKV("localaddresses", localAddresses);
obj.pushKV("warnings", GetWarnings(false));
obj.pushKV("warnings", GetWarnings(false).original);
return obj;
}

View File

@ -23,7 +23,7 @@
bool AbortNode(const std::string& strMessage, bilingual_str user_message)
{
SetMiscWarning(strMessage);
SetMiscWarning(Untranslated(strMessage));
LogPrintf("*** %s\n", strMessage);
if (user_message.empty()) {
user_message = _("A fatal internal error occurred, see debug.log for details");

View File

@ -9,6 +9,7 @@
#include <test/util/setup_common.h>
#include <timedata.h>
#include <util/string.h>
#include <util/translation.h>
#include <warnings.h>
#include <string>
@ -66,7 +67,7 @@ BOOST_AUTO_TEST_CASE(addtimedata)
MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); //filter size 5
}
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
BOOST_CHECK_EQUAL(GetTimeOffset(), 0);

View File

@ -92,7 +92,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
if (!fMatch) {
fDone = true;
bilingual_str strMessage = strprintf(_("Please check that your computer's date 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);
}
}

View File

@ -2655,20 +2655,20 @@ void CChainState::PruneAndFlush()
}
}
static void DoWarning(const std::string& strWarning)
static void DoWarning(const bilingual_str& warning)
{
static bool fWarned = false;
SetMiscWarning(strWarning);
SetMiscWarning(warning);
if (!fWarned) {
AlertNotify(strWarning);
AlertNotify(warning.original);
fWarned = true;
}
}
/** Private helper function that concatenates warning messages. */
static void AppendWarning(std::string& res, const std::string& warn)
static void AppendWarning(bilingual_str& res, const bilingual_str& warn)
{
if (!res.empty()) res += ", ";
if (!res.empty()) res += Untranslated(", ");
res += warn;
}
@ -2685,7 +2685,7 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
g_best_block_cv.notify_all();
}
std::string warningMessages;
bilingual_str warning_messages;
assert(std::addressof(::ChainstateActive()) == std::addressof(*this));
if (!this->IsInitialBlockDownload())
{
@ -2694,11 +2694,11 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
WarningBitsConditionChecker checker(bit);
ThresholdState state = checker.GetStateFor(pindex, m_params.GetConsensus(), warningcache[bit]);
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)").translated, bit);
const bilingual_str warning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
if (state == ThresholdState::ACTIVE) {
DoWarning(strWarning);
DoWarning(warning);
} else {
AppendWarning(warningMessages, strWarning);
AppendWarning(warning_messages, warning);
}
}
}
@ -2710,7 +2710,7 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
FormatISO8601DateTime(pindexNew->GetBlockTime()),
GuessVerificationProgress(m_params.TxData(), pindexNew), this->CoinsTip().DynamicMemoryUsage() * (1.0 / (1<<20)), this->CoinsTip().GetCacheSize(),
m_evoDb.GetMemoryUsage() * (1.0 / (1<<20)),
!warningMessages.empty() ? strprintf(" warning='%s'", warningMessages) : "");
!warning_messages.empty() ? strprintf(" warning='%s'", warning_messages.original) : "");
}
/** Disconnect m_chain's tip.

View File

@ -4689,7 +4689,7 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain& chain, interfaces::C
// Warn user every time a non-encrypted HD wallet is started
if (walletInstance->IsHDEnabled() && !walletInstance->IsLocked()) {
SetMiscWarning(_("Make sure to encrypt your wallet and delete all non-encrypted backups after you have verified that the wallet works!").translated);
SetMiscWarning(_("Make sure to encrypt your wallet and delete all non-encrypted backups after you have verified that the wallet works!"));
}
if (gArgs.IsArgSet("-mintxfee")) {

View File

@ -6,18 +6,21 @@
#include <warnings.h>
#include <sync.h>
#include <util/string.h>
#include <util/system.h>
#include <util/translation.h>
#include <hash.h>
#include <vector>
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 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 SetfLargeWorkInvalidChainFound(bool flag)
@ -26,31 +29,33 @@ void SetfLargeWorkInvalidChainFound(bool flag)
fLargeWorkInvalidChainFound = flag;
}
std::string GetWarnings(bool verbose)
bilingual_str GetWarnings(bool verbose)
{
std::string warnings_concise;
std::string warnings_verbose;
const std::string warning_separator = "<hr />";
bilingual_str warnings_concise;
std::vector<bilingual_str> warnings_verbose;
LOCK(g_warnings_mutex);
// Pre-release build warning
if (!CLIENT_VERSION_IS_RELEASE) {
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;
warnings_concise = _("This is a pre-release test build - use at your own risk - do not 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 (fLargeWorkInvalidChainFound) {
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;
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.emplace_back(warnings_concise);
}
if (verbose) return warnings_verbose;
else return warnings_concise;
if (verbose) {
return Join(warnings_verbose, Untranslated("<hr />"));
}
return warnings_concise;
}

View File

@ -8,14 +8,16 @@
#include <string>
void SetMiscWarning(const std::string& strWarning);
struct bilingual_str;
void SetMiscWarning(const bilingual_str& warning);
void SetfLargeWorkInvalidChainFound(bool flag);
/** 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 <hr />
* - if true, get all warnings separated by <hr />
* - if false, get the most important warning
* @returns the warning string
*/
std::string GetWarnings(bool verbose);
bilingual_str GetWarnings(bool verbose);
#endif // BITCOIN_WARNINGS_H