Line data Source code
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 "warnings.h" 7 : 8 : #include "sync.h" 9 : #include "clientversion.h" 10 : #include "util/system.h" 11 : 12 : RecursiveMutex cs_warnings; 13 : std::string strMiscWarning; 14 : bool fLargeWorkForkFound = false; 15 : bool fLargeWorkInvalidChainFound = false; 16 : 17 459 : void SetMiscWarning(const std::string& strWarning) 18 : { 19 459 : LOCK(cs_warnings); 20 459 : strMiscWarning = strWarning; 21 459 : } 22 : 23 41092 : void SetfLargeWorkForkFound(bool flag) 24 : { 25 41092 : LOCK(cs_warnings); 26 41092 : fLargeWorkForkFound = flag; 27 41092 : } 28 : 29 20 : bool GetfLargeWorkForkFound() 30 : { 31 20 : LOCK(cs_warnings); 32 20 : return fLargeWorkForkFound; 33 : } 34 : 35 41112 : void SetfLargeWorkInvalidChainFound(bool flag) 36 : { 37 41112 : LOCK(cs_warnings); 38 41112 : fLargeWorkInvalidChainFound = flag; 39 41112 : } 40 : 41 0 : bool GetfLargeWorkInvalidChainFound() 42 : { 43 0 : LOCK(cs_warnings); 44 0 : return fLargeWorkInvalidChainFound; 45 : } 46 : 47 290298 : std::string GetWarnings(const std::string& strFor) 48 : { 49 580596 : std::string strStatusBar; 50 290298 : std::string strRPC; 51 290298 : std::string strGUI; 52 580596 : const std::string uiAlertSeperator = "\n"; 53 : 54 580596 : LOCK(cs_warnings); 55 : 56 290298 : if (!CLIENT_VERSION_IS_RELEASE) { 57 290298 : strStatusBar = "This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!"; 58 290298 : strGUI = _("This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!"); 59 : } 60 : 61 290298 : if (gArgs.GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE)) 62 0 : strStatusBar = strRPC = strGUI = "testsafemode enabled"; 63 : 64 : // Misc warnings like out of disk space and clock is wrong 65 290298 : if (!strMiscWarning.empty()) { 66 41 : strStatusBar = strMiscWarning; 67 164 : strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning; 68 : } 69 : 70 290298 : if (fLargeWorkForkFound) { 71 0 : strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues."; 72 0 : strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues."); 73 290298 : } else if (fLargeWorkInvalidChainFound) { 74 6 : 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."; 75 24 : 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."); 76 : } 77 : 78 290298 : if (strFor == "gui") 79 0 : return strGUI; 80 290298 : else if (strFor == "statusbar") 81 1241 : return strStatusBar; 82 289057 : else if (strFor == "rpc") 83 579355 : return strRPC; 84 0 : assert(!"GetWarnings() : invalid parameter"); 85 : return "error"; 86 : } 87 :