LCOV - code coverage report
Current view: top level - src - warnings.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 32 45 71.1 %
Date: 2025-02-23 09:33:43 Functions: 4 6 66.7 %

          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         463 : void SetMiscWarning(const std::string& strWarning)
      18             : {
      19         463 :     LOCK(cs_warnings);
      20         463 :     strMiscWarning = strWarning;
      21         463 : }
      22             : 
      23       40864 : void SetfLargeWorkForkFound(bool flag)
      24             : {
      25       40864 :     LOCK(cs_warnings);
      26       40864 :     fLargeWorkForkFound = flag;
      27       40864 : }
      28             : 
      29           0 : bool GetfLargeWorkForkFound()
      30             : {
      31           0 :     LOCK(cs_warnings);
      32           0 :     return fLargeWorkForkFound;
      33             : }
      34             : 
      35       40864 : void SetfLargeWorkInvalidChainFound(bool flag)
      36             : {
      37       40864 :     LOCK(cs_warnings);
      38       40864 :     fLargeWorkInvalidChainFound = flag;
      39       40864 : }
      40             : 
      41           0 : bool GetfLargeWorkInvalidChainFound()
      42             : {
      43           0 :     LOCK(cs_warnings);
      44           0 :     return fLargeWorkInvalidChainFound;
      45             : }
      46             : 
      47      299293 : std::string GetWarnings(const std::string& strFor)
      48             : {
      49      598586 :     std::string strStatusBar;
      50      299293 :     std::string strRPC;
      51      299293 :     std::string strGUI;
      52      598586 :     const std::string uiAlertSeperator = "\n";
      53             : 
      54      598586 :     LOCK(cs_warnings);
      55             : 
      56      299293 :     if (!CLIENT_VERSION_IS_RELEASE) {
      57      299293 :         strStatusBar = "This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!";
      58      299293 :         strGUI = _("This is a pre-release test build - use at your own risk - do not use for staking or merchant applications!");
      59             :     }
      60             : 
      61      299293 :     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      299293 :     if (!strMiscWarning.empty()) {
      66          47 :         strStatusBar = strMiscWarning;
      67         188 :         strGUI += (strGUI.empty() ? "" : uiAlertSeperator) + strMiscWarning;
      68             :     }
      69             : 
      70      299293 :     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      299293 :     } else if (fLargeWorkInvalidChainFound) {
      74           0 :         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           0 :         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      299293 :     if (strFor == "gui")
      79           0 :         return strGUI;
      80      299293 :     else if (strFor == "statusbar")
      81        1241 :         return strStatusBar;
      82      298052 :     else if (strFor == "rpc")
      83      597345 :         return strRPC;
      84           0 :     assert(!"GetWarnings() : invalid parameter");
      85             :     return "error";
      86             : }
      87             : 

Generated by: LCOV version 1.14