Skip to content

Commit 749be01

Browse files
committed
Move GetWarnings() into its own file.
1 parent e3ba0ef commit 749be01

File tree

9 files changed

+116
-89
lines changed

9 files changed

+116
-89
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ BITCOIN_CORE_H = \
154154
wallet/rpcwallet.h \
155155
wallet/wallet.h \
156156
wallet/walletdb.h \
157+
warnings.h \
157158
zmq/zmqabstractnotifier.h \
158159
zmq/zmqconfig.h\
159160
zmq/zmqnotificationinterface.h \
@@ -305,6 +306,7 @@ libbitcoin_common_a_SOURCES = \
305306
scheduler.cpp \
306307
script/sign.cpp \
307308
script/standard.cpp \
309+
warnings.cpp \
308310
$(BITCOIN_CORE_H)
309311

310312
# util: shared between all executables.

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#ifdef ENABLE_WALLET
4242
#include "wallet/wallet.h"
4343
#endif
44+
#include "warnings.h"
4445
#include <stdint.h>
4546
#include <stdio.h>
4647
#include <memory>

src/qt/bitcoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "scheduler.h"
3131
#include "ui_interface.h"
3232
#include "util.h"
33+
#include "warnings.h"
3334

3435
#ifdef ENABLE_WALLET
3536
#include "wallet/wallet.h"

src/timedata.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "ui_interface.h"
1414
#include "util.h"
1515
#include "utilstrencodings.h"
16+
#include "warnings.h"
1617

1718
#include <boost/foreach.hpp>
1819

src/util.cpp

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ bool fDebug = false;
108108
bool fPrintToConsole = false;
109109
bool fPrintToDebugLog = true;
110110

111-
CCriticalSection cs_warnings;
112-
string strMiscWarning;
113-
bool fLargeWorkForkFound = false;
114-
bool fLargeWorkInvalidChainFound = false;
115-
116111
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
117112
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
118113
bool fLogIPs = DEFAULT_LOGIPS;
@@ -813,78 +808,3 @@ std::string CopyrightHolders(const std::string& strPrefix)
813808
}
814809
return strCopyrightHolders;
815810
}
816-
817-
void SetMiscWarning(const std::string& strWarning)
818-
{
819-
LOCK(cs_warnings);
820-
strMiscWarning = strWarning;
821-
}
822-
823-
void SetfLargeWorkForkFound(bool flag)
824-
{
825-
LOCK(cs_warnings);
826-
fLargeWorkForkFound = flag;
827-
}
828-
829-
bool GetfLargeWorkForkFound()
830-
{
831-
LOCK(cs_warnings);
832-
return fLargeWorkForkFound;
833-
}
834-
835-
void SetfLargeWorkInvalidChainFound(bool flag)
836-
{
837-
LOCK(cs_warnings);
838-
fLargeWorkInvalidChainFound = flag;
839-
}
840-
841-
bool GetfLargeWorkInvalidChainFound()
842-
{
843-
LOCK(cs_warnings);
844-
return fLargeWorkInvalidChainFound;
845-
}
846-
847-
std::string GetWarnings(const std::string& strFor)
848-
{
849-
string strStatusBar;
850-
string strRPC;
851-
string strGUI;
852-
const string uiAlertSeperator = "<hr />";
853-
854-
LOCK(cs_warnings);
855-
856-
if (!CLIENT_VERSION_IS_RELEASE) {
857-
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";
858-
strGUI = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
859-
}
860-
861-
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
862-
strStatusBar = strRPC = strGUI = "testsafemode enabled";
863-
864-
// Misc warnings like out of disk space and clock is wrong
865-
if (strMiscWarning != "")
866-
{
867-
strStatusBar = strMiscWarning;
868-
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
869-
}
870-
871-
if (fLargeWorkForkFound)
872-
{
873-
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
874-
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
875-
}
876-
else if (fLargeWorkInvalidChainFound)
877-
{
878-
strStatusBar = strRPC = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.";
879-
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.");
880-
}
881-
882-
if (strFor == "gui")
883-
return strGUI;
884-
else if (strFor == "statusbar")
885-
return strStatusBar;
886-
else if (strFor == "rpc")
887-
return strRPC;
888-
assert(!"GetWarnings(): invalid parameter");
889-
return "error";
890-
}

src/util.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ extern bool fDebug;
4747
extern bool fPrintToConsole;
4848
extern bool fPrintToDebugLog;
4949

50-
static const bool DEFAULT_TESTSAFEMODE = false;
51-
5250
extern bool fLogTimestamps;
5351
extern bool fLogTimeMicros;
5452
extern bool fLogIPs;
@@ -226,11 +224,4 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
226224

227225
std::string CopyrightHolders(const std::string& strPrefix);
228226

229-
void SetMiscWarning(const std::string& strWarning);
230-
void SetfLargeWorkForkFound(bool flag);
231-
bool GetfLargeWorkForkFound();
232-
void SetfLargeWorkInvalidChainFound(bool flag);
233-
bool GetfLargeWorkInvalidChainFound();
234-
std::string GetWarnings(const std::string& strFor);
235-
236227
#endif // BITCOIN_UTIL_H

src/validation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "utilstrencodings.h"
3535
#include "validationinterface.h"
3636
#include "versionbits.h"
37+
#include "warnings.h"
3738

3839
#include <atomic>
3940
#include <sstream>

src/warnings.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#include "sync.h"
7+
#include "clientversion.h"
8+
#include "util.h"
9+
#include "warnings.h"
10+
11+
CCriticalSection cs_warnings;
12+
std::string strMiscWarning;
13+
bool fLargeWorkForkFound = false;
14+
bool fLargeWorkInvalidChainFound = false;
15+
16+
void SetMiscWarning(const std::string& strWarning)
17+
{
18+
LOCK(cs_warnings);
19+
strMiscWarning = strWarning;
20+
}
21+
22+
void SetfLargeWorkForkFound(bool flag)
23+
{
24+
LOCK(cs_warnings);
25+
fLargeWorkForkFound = flag;
26+
}
27+
28+
bool GetfLargeWorkForkFound()
29+
{
30+
LOCK(cs_warnings);
31+
return fLargeWorkForkFound;
32+
}
33+
34+
void SetfLargeWorkInvalidChainFound(bool flag)
35+
{
36+
LOCK(cs_warnings);
37+
fLargeWorkInvalidChainFound = flag;
38+
}
39+
40+
bool GetfLargeWorkInvalidChainFound()
41+
{
42+
LOCK(cs_warnings);
43+
return fLargeWorkInvalidChainFound;
44+
}
45+
46+
std::string GetWarnings(const std::string& strFor)
47+
{
48+
std::string strStatusBar;
49+
std::string strRPC;
50+
std::string strGUI;
51+
const std::string uiAlertSeperator = "<hr />";
52+
53+
LOCK(cs_warnings);
54+
55+
if (!CLIENT_VERSION_IS_RELEASE) {
56+
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";
57+
strGUI = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications");
58+
}
59+
60+
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
61+
strStatusBar = strRPC = strGUI = "testsafemode enabled";
62+
63+
// Misc warnings like out of disk space and clock is wrong
64+
if (strMiscWarning != "")
65+
{
66+
strStatusBar = strMiscWarning;
67+
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
68+
}
69+
70+
if (fLargeWorkForkFound)
71+
{
72+
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
73+
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
74+
}
75+
else if (fLargeWorkInvalidChainFound)
76+
{
77+
strStatusBar = strRPC = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.";
78+
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.");
79+
}
80+
81+
if (strFor == "gui")
82+
return strGUI;
83+
else if (strFor == "statusbar")
84+
return strStatusBar;
85+
else if (strFor == "rpc")
86+
return strRPC;
87+
assert(!"GetWarnings(): invalid parameter");
88+
return "error";
89+
}

src/warnings.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2009-2010 Satoshi Nakamoto
2+
// Copyright (c) 2009-2016 The Bitcoin Core developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#ifndef BITCOIN_WARNINGS_H
7+
#define BITCOIN_WARNINGS_H
8+
9+
#include <stdlib.h>
10+
#include <string>
11+
12+
void SetMiscWarning(const std::string& strWarning);
13+
void SetfLargeWorkForkFound(bool flag);
14+
bool GetfLargeWorkForkFound();
15+
void SetfLargeWorkInvalidChainFound(bool flag);
16+
bool GetfLargeWorkInvalidChainFound();
17+
std::string GetWarnings(const std::string& strFor);
18+
19+
static const bool DEFAULT_TESTSAFEMODE = false;
20+
21+
#endif // BITCOIN_WARNINGS_H

0 commit comments

Comments
 (0)