/bitcoin/src/node/warnings.cpp
Line | Count | Source |
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 <bitcoin-build-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 | | Warnings::Warnings() |
21 | 11.0k | { |
22 | | // Pre-release build warning |
23 | 11.0k | if (!CLIENT_VERSION_IS_RELEASE) { Branch (23:9): [Folded - Ignored]
|
24 | 11.0k | m_warnings.insert( |
25 | 11.0k | {Warning::PRE_RELEASE_TEST_BUILD, |
26 | 11.0k | _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications")}); |
27 | 11.0k | } |
28 | 11.0k | } |
29 | | bool Warnings::Set(warning_type id, bilingual_str message) |
30 | 39 | { |
31 | 39 | const auto& [_, inserted]{WITH_LOCK(m_mutex, return m_warnings.insert({id, std::move(message)}))}; |
32 | 39 | if (inserted) uiInterface.NotifyAlertChanged(); Branch (32:9): [True: 10, False: 29]
|
33 | 39 | return inserted; |
34 | 39 | } |
35 | | |
36 | | bool Warnings::Unset(warning_type id) |
37 | 2.27M | { |
38 | 2.27M | auto success{WITH_LOCK(m_mutex, return m_warnings.erase(id))}; |
39 | 2.27M | if (success) uiInterface.NotifyAlertChanged(); Branch (39:9): [True: 9, False: 2.27M]
|
40 | 2.27M | return success; |
41 | 2.27M | } |
42 | | |
43 | | std::vector<bilingual_str> Warnings::GetMessages() const |
44 | 11.0k | { |
45 | 11.0k | LOCK(m_mutex); |
46 | 11.0k | std::vector<bilingual_str> messages; |
47 | 11.0k | messages.reserve(m_warnings.size()); |
48 | 11.0k | for (const auto& [id, msg] : m_warnings) { Branch (48:32): [True: 11.0k, False: 11.0k]
|
49 | 11.0k | messages.push_back(msg); |
50 | 11.0k | } |
51 | 11.0k | return messages; |
52 | 11.0k | } |
53 | | |
54 | | UniValue GetWarningsForRpc(const Warnings& warnings, bool use_deprecated) |
55 | 11.0k | { |
56 | 11.0k | if (use_deprecated) { Branch (56:9): [True: 0, False: 11.0k]
|
57 | 0 | const auto all_messages{warnings.GetMessages()}; |
58 | 0 | return all_messages.empty() ? "" : all_messages.back().original; Branch (58:16): [True: 0, False: 0]
|
59 | 0 | } |
60 | | |
61 | 11.0k | UniValue messages{UniValue::VARR}; |
62 | 11.0k | for (auto&& message : warnings.GetMessages()) { Branch (62:25): [True: 11.0k, False: 11.0k]
|
63 | 11.0k | messages.push_back(std::move(message.original)); |
64 | 11.0k | } |
65 | 11.0k | return messages; |
66 | 11.0k | } |
67 | | } // namespace node |