Skip to content

Commit f9fd3a2

Browse files
author
MarcoFalke
committed
Merge #17750: util: change GetWarnings parameter to bool
7aab8d1 [style] Code style fixups in GetWarnings() (John Newbery) 492c6dc util: change GetWarnings parameter to bool (John Newbery) 869b631 [qt] remove unused parameter from getWarnings() (John Newbery) Pull request description: `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. ACKs for top commit: laanwj: code review ACK 7aab8d1 practicalswift: ACK 7aab8d1 -- diff looks correct :) MarcoFalke: ACK 7aab8d1 otherwise. promag: Code review ACK 7aab8d1. Tree-SHA512: 75882c6e3e44aa9586411b803149b36ba487f4eb9cac3f5c8f07cd9f586870bba4488a51e674cf8147f05718534f482836e6a4e3f66e0d4ef6821900c7dfd04e
2 parents 48d64d7 + 7aab8d1 commit f9fd3a2

File tree

10 files changed

+33
-40
lines changed

10 files changed

+33
-40
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(const std::string& type) override { return GetWarnings(type); }
71+
std::string getWarnings() override { return GetWarnings(true); }
7272
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
7373
bool baseInitialize() override
7474
{

src/interfaces/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Node
7878
virtual void initParameterInteraction() = 0;
7979

8080
//! Get warnings.
81-
virtual std::string getWarnings(const std::string& type) = 0;
81+
virtual std::string getWarnings() = 0;
8282

8383
// Get log flags.
8484
virtual uint32_t getLogCategories() = 0;

src/qt/bitcoin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ BitcoinCore::BitcoinCore(interfaces::Node& node) :
135135
void BitcoinCore::handleRunawayException(const std::exception *e)
136136
{
137137
PrintExceptionContinue(e, "Runaway exception");
138-
Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings("gui")));
138+
Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings()));
139139
}
140140

141141
void BitcoinCore::initialize()
@@ -589,10 +589,10 @@ int GuiMain(int argc, char* argv[])
589589
}
590590
} catch (const std::exception& e) {
591591
PrintExceptionContinue(&e, "Runaway exception");
592-
app.handleRunawayException(QString::fromStdString(node->getWarnings("gui")));
592+
app.handleRunawayException(QString::fromStdString(node->getWarnings()));
593593
} catch (...) {
594594
PrintExceptionContinue(nullptr, "Runaway exception");
595-
app.handleRunawayException(QString::fromStdString(node->getWarnings("gui")));
595+
app.handleRunawayException(QString::fromStdString(node->getWarnings()));
596596
}
597597
return rv;
598598
}

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ enum BlockSource ClientModel::getBlockSource() const
134134

135135
QString ClientModel::getStatusBarWarnings() const
136136
{
137-
return QString::fromStdString(m_node.getWarnings("gui"));
137+
return QString::fromStdString(m_node.getWarnings());
138138
}
139139

140140
OptionsModel *ClientModel::getOptionsModel()

src/rpc/blockchain.cpp

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

1293-
obj.pushKV("warnings", GetWarnings("statusbar"));
1293+
obj.pushKV("warnings", GetWarnings(false));
12941294
return obj;
12951295
}
12961296

src/rpc/mining.cpp

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

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: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,34 @@ 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;
45-
const std::string uiAlertSeperator = "<hr />";
43+
std::string warnings_concise;
44+
std::string warnings_verbose;
45+
const std::string warning_separator = "<hr />";
4646

4747
LOCK(cs_warnings);
4848

49+
// Pre-release build warning
4950
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;
51+
warnings_concise = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";
52+
warnings_verbose = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications").translated;
5253
}
5354

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

61-
if (fLargeWorkForkFound)
62-
{
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;
65-
}
66-
else if (fLargeWorkInvalidChainFound)
67-
{
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;
61+
if (fLargeWorkForkFound) {
62+
warnings_concise = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
63+
warnings_verbose += (warnings_verbose.empty() ? "" : warning_separator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.").translated;
64+
} else if (fLargeWorkInvalidChainFound) {
65+
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.";
66+
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;
7067
}
7168

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

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)