Skip to content

Commit

Permalink
Move GetWarnings() into its own file.
Browse files Browse the repository at this point in the history
Github-Pull: #2063
Rebased-From: ce58263
  • Loading branch information
furszy authored and Fuzzbawls committed Dec 19, 2020
1 parent edf51b3 commit 6850224
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 86 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ set(COMMON_SOURCES
./src/script/script_error.cpp
./src/spork.cpp
./src/sporkdb.cpp
./src/warnings.cpp
)
add_library(COMMON_A STATIC ${BitcoinHeaders} ${COMMON_SOURCES})
target_include_directories(COMMON_A PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ BITCOIN_CORE_H = \
destination_io.h \
wallet/wallet.h \
wallet/walletdb.h \
warnings.h \
zpivchain.h \
zpiv/deterministicmint.h \
zpiv/mintpool.h \
Expand Down Expand Up @@ -511,6 +512,7 @@ libbitcoin_common_a_SOURCES = \
script/script.cpp \
script/sign.cpp \
script/standard.cpp \
warnings.cpp \
script/script_error.cpp \
spork.cpp \
sporkdb.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "wallet/rpcwallet.h"

#endif
#include "warnings.h"

#include <atomic>
#include <fstream>
Expand Down
1 change: 1 addition & 0 deletions src/qt/pivx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "rpc/server.h"
#include "guiinterface.h"
#include "util.h"
#include "warnings.h"

#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "wallet/db.h"
#include "wallet/wallet.h"
#endif
#include "warnings.h"

#include <stdint.h>

Expand Down
1 change: 1 addition & 0 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "wallet/wallet.h"
#include "wallet/walletdb.h"
#endif
#include "warnings.h"

#include <stdint.h>

Expand Down
2 changes: 1 addition & 1 deletion src/timedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "netaddress.h"
#include "sync.h"
#include "util.h"
#include "utilstrencodings.h"
#include "warnings.h"


static RecursiveMutex cs_nTimeOffset;
Expand Down
76 changes: 0 additions & 76 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ ArgsManager gArgs;
bool fDaemon = false;
CTranslationInterface translationInterface;

RecursiveMutex cs_warnings;
std::string strMiscWarning;
bool fLargeWorkForkFound = false;
bool fLargeWorkInvalidChainFound = false;

/** Init OpenSSL library multithreading support */
static RecursiveMutex** ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
Expand Down Expand Up @@ -346,7 +341,6 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
std::string message = FormatException(pex, pszThread);
LogPrintf("\n\n************************\n%s\n", message);
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
strMiscWarning = message;
}

fs::path GetDefaultDataDir()
Expand Down Expand Up @@ -844,73 +838,3 @@ int GetNumCores()
return std::thread::hardware_concurrency();
}

void SetMiscWarning(const std::string& strWarning)
{
LOCK(cs_warnings);
strMiscWarning = strWarning;
}

void SetfLargeWorkForkFound(bool flag)
{
LOCK(cs_warnings);
fLargeWorkForkFound = flag;
}

bool GetfLargeWorkForkFound()
{
LOCK(cs_warnings);
return fLargeWorkForkFound;
}

void SetfLargeWorkInvalidChainFound(bool flag)
{
LOCK(cs_warnings);
fLargeWorkInvalidChainFound = flag;
}

bool GetfLargeWorkInvalidChainFound()
{
LOCK(cs_warnings);
return fLargeWorkInvalidChainFound;
}

std::string GetWarnings(const std::string& strFor)
{
std::string strStatusBar;
std::string strRPC;
std::string strGUI;
const std::string uiAlertSeperator = "<hr />";

LOCK(cs_warnings);

if (!CLIENT_VERSION_IS_RELEASE) {
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for staking or merchant applications";
strGUI = _("This is a pre-release test build - use at your own risk - do not use for staking or merchant applications");
}

if (gArgs.GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
strStatusBar = strRPC = strGUI = "testsafemode enabled";

// Misc warnings like out of disk space and clock is wrong
if (!strMiscWarning.empty()) {
strStatusBar = strMiscWarning;
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
}

if (fLargeWorkForkFound) {
strStatusBar = strRPC = "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.");
} else if (fLargeWorkInvalidChainFound) {
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.";
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.");
}

if (strFor == "gui")
return strGUI;
else if (strFor == "statusbar")
return strStatusBar;
else if (strFor == "rpc")
return strRPC;
assert(!"GetWarnings() : invalid parameter");
return "error";
}
9 changes: 0 additions & 9 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ extern std::string strBudgetMode;

extern CTranslationInterface translationInterface;

static const bool DEFAULT_TESTSAFEMODE = false;

/**
* Translation function: Call Translate signal on UI interface, which returns a Optional result.
* If no translation slot is registered, nothing is returned, and simply return the input.
Expand Down Expand Up @@ -263,11 +261,4 @@ void TraceThread(const char* name, Callable func)

fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true);

void SetMiscWarning(const std::string& strWarning);
void SetfLargeWorkForkFound(bool flag);
bool GetfLargeWorkForkFound();
void SetfLargeWorkInvalidChainFound(bool flag);
bool GetfLargeWorkInvalidChainFound();
std::string GetWarnings(const std::string& strFor);

#endif // BITCOIN_UTIL_H
1 change: 1 addition & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "util.h"
#include "utilmoneystr.h"
#include "validationinterface.h"
#include "warnings.h"
#include "zpivchain.h"
#include "zpiv/zerocoin.h"
#include "zpiv/zpivmodule.h"
Expand Down
87 changes: 87 additions & 0 deletions src/warnings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "warnings.h"

#include "sync.h"
#include "clientversion.h"
#include "util.h"

RecursiveMutex cs_warnings;
std::string strMiscWarning;
bool fLargeWorkForkFound = false;
bool fLargeWorkInvalidChainFound = false;

void SetMiscWarning(const std::string& strWarning)
{
LOCK(cs_warnings);
strMiscWarning = strWarning;
}

void SetfLargeWorkForkFound(bool flag)
{
LOCK(cs_warnings);
fLargeWorkForkFound = flag;
}

bool GetfLargeWorkForkFound()
{
LOCK(cs_warnings);
return fLargeWorkForkFound;
}

void SetfLargeWorkInvalidChainFound(bool flag)
{
LOCK(cs_warnings);
fLargeWorkInvalidChainFound = flag;
}

bool GetfLargeWorkInvalidChainFound()
{
LOCK(cs_warnings);
return fLargeWorkInvalidChainFound;
}

std::string GetWarnings(const std::string& strFor)
{
std::string strStatusBar;
std::string strRPC;
std::string strGUI;
const std::string uiAlertSeperator = "\n";

LOCK(cs_warnings);

if (!CLIENT_VERSION_IS_RELEASE) {
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!";
strGUI = _("This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!");
}

if (gArgs.GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
strStatusBar = strRPC = strGUI = "testsafemode enabled";

// Misc warnings like out of disk space and clock is wrong
if (!strMiscWarning.empty()) {
strStatusBar = strMiscWarning;
strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
}

if (fLargeWorkForkFound) {
strStatusBar = strRPC = "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.");
} else if (fLargeWorkInvalidChainFound) {
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.";
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.");
}

if (strFor == "gui")
return strGUI;
else if (strFor == "statusbar")
return strStatusBar;
else if (strFor == "rpc")
return strRPC;
assert(!"GetWarnings() : invalid parameter");
return "error";
}

21 changes: 21 additions & 0 deletions src/warnings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#ifndef PIVX_WARNINGS_H
#define PIVX_WARNINGS_H

#include <stdlib.h>
#include <string>

void SetMiscWarning(const std::string& strWarning);
void SetfLargeWorkForkFound(bool flag);
bool GetfLargeWorkForkFound();
void SetfLargeWorkInvalidChainFound(bool flag);
bool GetfLargeWorkInvalidChainFound();
std::string GetWarnings(const std::string& strFor);

static const bool DEFAULT_TESTSAFEMODE = false;

#endif //PIVX_WARNINGS_H

0 comments on commit 6850224

Please sign in to comment.