LCOV - code coverage report
Current view: top level - src/node - warnings.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 91.4 % 35 32
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 7 7
Branches: 42.0 % 50 21

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2                 :             : // Copyright (c) 2009-2022 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 <config/bitcoin-config.h> // IWYU pragma: keep
       7                 :             : 
       8                 :             : #include <node/warnings.h>
       9                 :             : 
      10                 :             : #include <common/system.h>
      11                 :             : #include <node/interface_ui.h>
      12                 :             : #include <sync.h>
      13                 :             : #include <univalue.h>
      14                 :             : #include <util/translation.h>
      15                 :             : 
      16                 :             : #include <utility>
      17                 :             : #include <vector>
      18                 :             : 
      19                 :             : namespace node {
      20                 :        5241 : Warnings::Warnings()
      21                 :             : {
      22                 :             :     // Pre-release build warning
      23                 :             :     if (!CLIENT_VERSION_IS_RELEASE) {
      24         [ +  - ]:        5241 :         m_warnings.insert(
      25                 :        5241 :             {Warning::PRE_RELEASE_TEST_BUILD,
      26         [ +  - ]:        5241 :              _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications")});
      27                 :             :     }
      28                 :        5241 : }
      29                 :      168240 : bool Warnings::Set(warning_type id, bilingual_str message)
      30                 :             : {
      31         [ +  - ]:      337423 :     const auto& [_, inserted]{WITH_LOCK(m_mutex, return m_warnings.insert({id, std::move(message)}))};
      32         [ +  + ]:      168240 :     if (inserted) uiInterface.NotifyAlertChanged();
      33                 :      336480 :     return inserted;
      34                 :      168240 : }
      35                 :             : 
      36                 :        5208 : bool Warnings::Unset(warning_type id)
      37                 :             : {
      38         [ +  - ]:       10416 :     auto success{WITH_LOCK(m_mutex, return m_warnings.erase(id))};
      39         [ +  + ]:        5208 :     if (success) uiInterface.NotifyAlertChanged();
      40                 :       10416 :     return success;
      41                 :        5208 : }
      42                 :             : 
      43                 :          12 : std::vector<bilingual_str> Warnings::GetMessages() const
      44                 :             : {
      45                 :          12 :     LOCK(m_mutex);
      46                 :          12 :     std::vector<bilingual_str> messages;
      47         [ +  - ]:          12 :     messages.reserve(m_warnings.size());
      48         [ +  + ]:          24 :     for (const auto& [id, msg] : m_warnings) {
      49         [ +  - ]:          12 :         messages.push_back(msg);
      50                 :          12 :     }
      51                 :          12 :     return messages;
      52         [ +  - ]:          12 : }
      53                 :             : 
      54                 :          12 : UniValue GetWarningsForRpc(const Warnings& warnings, bool use_deprecated)
      55                 :             : {
      56         [ +  - ]:          12 :     if (use_deprecated) {
      57                 :           0 :         const auto all_messages{warnings.GetMessages()};
      58   [ #  #  #  #  :           0 :         return all_messages.empty() ? "" : all_messages.back().original;
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      59                 :           0 :     }
      60                 :             : 
      61         [ +  - ]:          12 :     UniValue messages{UniValue::VARR};
      62   [ +  -  +  + ]:          24 :     for (auto&& message : warnings.GetMessages()) {
      63   [ +  -  +  - ]:          12 :         messages.push_back(std::move(message.original));
      64                 :          12 :     }
      65                 :          12 :     return messages;
      66         [ +  - ]:          24 : }
      67                 :             : } // namespace node
        

Generated by: LCOV version 2.0-1