util: change GetWarnings parameter to bool

GetWarnings() changes the format of the output warning string based on a
passed-in string argument that can be set to "gui" or "statusbar".
Change the argument to a bool:

- there are only two types of behaviour, so a bool is a more natural
argument type
- changing the name to 'verbose' does not set any expectations for the
how the calling code will use the returned string (currently,
'statusbar' is used for RPC warnings, not a status bar)
- removes some error-handling code for when the passed-in string is not
one of the two strings expected.
pull/764/head
John Newbery 5 years ago
parent 869b6314fd
commit 492c6dc1e7

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

@ -1286,7 +1286,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
BIP9SoftForkDescPushBack(softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY); BIP9SoftForkDescPushBack(softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
obj.pushKV("softforks", softforks); obj.pushKV("softforks", softforks);
obj.pushKV("warnings", GetWarnings("statusbar")); obj.pushKV("warnings", GetWarnings(false));
return obj; return obj;
} }

@ -253,7 +253,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
obj.pushKV("networkhashps", getnetworkhashps(request)); obj.pushKV("networkhashps", getnetworkhashps(request));
obj.pushKV("pooledtx", (uint64_t)mempool.size()); obj.pushKV("pooledtx", (uint64_t)mempool.size());
obj.pushKV("chain", Params().NetworkIDString()); obj.pushKV("chain", Params().NetworkIDString());
obj.pushKV("warnings", GetWarnings("statusbar")); obj.pushKV("warnings", GetWarnings(false));
return obj; return obj;
} }

@ -522,7 +522,7 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
} }
} }
obj.pushKV("localaddresses", localAddresses); obj.pushKV("localaddresses", localAddresses);
obj.pushKV("warnings", GetWarnings("statusbar")); obj.pushKV("warnings", GetWarnings(false));
return obj; return obj;
} }

@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(addtimedata)
MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); //filter size 5 MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); //filter size 5
} }
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 // nTimeOffset is not changed if the median of offsets exceeds DEFAULT_MAX_TIME_ADJUSTMENT
BOOST_CHECK_EQUAL(GetTimeOffset(), 0); BOOST_CHECK_EQUAL(GetTimeOffset(), 0);

@ -38,41 +38,37 @@ void SetfLargeWorkInvalidChainFound(bool flag)
fLargeWorkInvalidChainFound = flag; fLargeWorkInvalidChainFound = flag;
} }
std::string GetWarnings(const std::string& strFor) std::string GetWarnings(bool verbose)
{ {
std::string strStatusBar; std::string warnings_concise;
std::string strGUI; std::string warnings_verbose;
const std::string uiAlertSeperator = "<hr />"; const std::string uiAlertSeperator = "<hr />";
LOCK(cs_warnings); LOCK(cs_warnings);
if (!CLIENT_VERSION_IS_RELEASE) { 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"; warnings_concise = "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_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 // Misc warnings like out of disk space and clock is wrong
if (strMiscWarning != "") if (strMiscWarning != "")
{ {
strStatusBar = strMiscWarning; warnings_concise = strMiscWarning;
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning; warnings_verbose += (warnings_verbose.empty() ? "" : uiAlertSeperator) + strMiscWarning;
} }
if (fLargeWorkForkFound) if (fLargeWorkForkFound)
{ {
strStatusBar = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues."; warnings_concise = "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_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) 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."; 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.";
strGUI += (strGUI.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; 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") if (verbose) return warnings_verbose;
return strGUI; else return warnings_concise;
else if (strFor == "statusbar")
return strStatusBar;
assert(!"GetWarnings(): invalid parameter");
return "error";
} }

@ -13,11 +13,11 @@ void SetfLargeWorkForkFound(bool flag);
bool GetfLargeWorkForkFound(); bool GetfLargeWorkForkFound();
void SetfLargeWorkInvalidChainFound(bool flag); void SetfLargeWorkInvalidChainFound(bool flag);
/** Format a string that describes several potential problems detected by the core. /** Format a string that describes several potential problems detected by the core.
* @param[in] strFor can have the following values: * @param[in] verbose bool
* - "statusbar": get the most important warning * - if true, get all warnings, translated (where possible), separated by <hr />
* - "gui": get all warnings, translated (where possible) for GUI, separated by <hr /> * - if false, get the most important warning
* @returns the warning string selected by strFor * @returns the warning string
*/ */
std::string GetWarnings(const std::string& strFor); std::string GetWarnings(bool verbose);
#endif // BITCOIN_WARNINGS_H #endif // BITCOIN_WARNINGS_H

Loading…
Cancel
Save