Skip to content

Commit 492c6dc

Browse files
committed
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.
1 parent 869b631 commit 492c6dc

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

src/interfaces/node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class NodeImpl : public Node
6868
std::string getNetwork() override { return Params().NetworkIDString(); }
6969
void initLogging() override { InitLogging(); }
7070
void initParameterInteraction() override { InitParameterInteraction(); }
71-
std::string getWarnings() override { return GetWarnings("gui"); }
71+
std::string getWarnings() override { return GetWarnings(true); }
7272
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
7373
bool baseInitialize() override
7474
{

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
12861286
BIP9SoftForkDescPushBack(softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
12871287
obj.pushKV("softforks", softforks);
12881288

1289-
obj.pushKV("warnings", GetWarnings("statusbar"));
1289+
obj.pushKV("warnings", GetWarnings(false));
12901290
return obj;
12911291
}
12921292

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
253253
obj.pushKV("networkhashps", getnetworkhashps(request));
254254
obj.pushKV("pooledtx", (uint64_t)mempool.size());
255255
obj.pushKV("chain", Params().NetworkIDString());
256-
obj.pushKV("warnings", GetWarnings("statusbar"));
256+
obj.pushKV("warnings", GetWarnings(false));
257257
return obj;
258258
}
259259

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
522522
}
523523
}
524524
obj.pushKV("localaddresses", localAddresses);
525-
obj.pushKV("warnings", GetWarnings("statusbar"));
525+
obj.pushKV("warnings", GetWarnings(false));
526526
return obj;
527527
}
528528

src/test/timedata_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(addtimedata)
6565
MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); //filter size 5
6666
}
6767

68-
BOOST_CHECK(GetWarnings("gui").find("clock is wrong") != std::string::npos);
68+
BOOST_CHECK(GetWarnings(true).find("clock is wrong") != std::string::npos);
6969

7070
// nTimeOffset is not changed if the median of offsets exceeds DEFAULT_MAX_TIME_ADJUSTMENT
7171
BOOST_CHECK_EQUAL(GetTimeOffset(), 0);

src/warnings.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,37 @@ void SetfLargeWorkInvalidChainFound(bool flag)
3838
fLargeWorkInvalidChainFound = flag;
3939
}
4040

41-
std::string GetWarnings(const std::string& strFor)
41+
std::string GetWarnings(bool verbose)
4242
{
43-
std::string strStatusBar;
44-
std::string strGUI;
43+
std::string warnings_concise;
44+
std::string warnings_verbose;
4545
const std::string uiAlertSeperator = "<hr />";
4646

4747
LOCK(cs_warnings);
4848

4949
if (!CLIENT_VERSION_IS_RELEASE) {
50-
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";
51-
strGUI = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications").translated;
50+
warnings_concise = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";
51+
warnings_verbose = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications").translated;
5252
}
5353

5454
// Misc warnings like out of disk space and clock is wrong
5555
if (strMiscWarning != "")
5656
{
57-
strStatusBar = strMiscWarning;
58-
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
57+
warnings_concise = strMiscWarning;
58+
warnings_verbose += (warnings_verbose.empty() ? "" : uiAlertSeperator) + strMiscWarning;
5959
}
6060

6161
if (fLargeWorkForkFound)
6262
{
63-
strStatusBar = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
64-
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.").translated;
63+
warnings_concise = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
64+
warnings_verbose += (warnings_verbose.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.").translated;
6565
}
6666
else if (fLargeWorkInvalidChainFound)
6767
{
68-
strStatusBar = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.";
69-
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;
68+
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.";
69+
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;
7070
}
7171

72-
if (strFor == "gui")
73-
return strGUI;
74-
else if (strFor == "statusbar")
75-
return strStatusBar;
76-
assert(!"GetWarnings(): invalid parameter");
77-
return "error";
72+
if (verbose) return warnings_verbose;
73+
else return warnings_concise;
7874
}

src/warnings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ void SetfLargeWorkForkFound(bool flag);
1313
bool GetfLargeWorkForkFound();
1414
void SetfLargeWorkInvalidChainFound(bool flag);
1515
/** Format a string that describes several potential problems detected by the core.
16-
* @param[in] strFor can have the following values:
17-
* - "statusbar": get the most important warning
18-
* - "gui": get all warnings, translated (where possible) for GUI, separated by <hr />
19-
* @returns the warning string selected by strFor
16+
* @param[in] verbose bool
17+
* - if true, get all warnings, translated (where possible), separated by <hr />
18+
* - if false, get the most important warning
19+
* @returns the warning string
2020
*/
21-
std::string GetWarnings(const std::string& strFor);
21+
std::string GetWarnings(bool verbose);
2222

2323
#endif // BITCOIN_WARNINGS_H

0 commit comments

Comments
 (0)