Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
node
warnings.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present 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
{
22
// Pre-release build warning
23
if
(!CLIENT_VERSION_IS_RELEASE) {
24
m_warnings.insert(
25
{
Warning::PRE_RELEASE_TEST_BUILD
,
26
_
(
"This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
)});
27
}
28
}
29
bool
Warnings::Set
(
warning_type
id
,
bilingual_str
message)
30
{
31
const
auto
& [
_
, inserted]{
WITH_LOCK
(
m_mutex
,
return
m_warnings.insert({id, std::move(message)}))};
32
if
(inserted)
uiInterface
.NotifyAlertChanged();
33
return
inserted;
34
}
35
36
bool
Warnings::Unset
(
warning_type
id
)
37
{
38
auto
success{
WITH_LOCK
(
m_mutex
,
return
m_warnings.erase(
id
))};
39
if
(success)
uiInterface
.NotifyAlertChanged();
40
return
success;
41
}
42
43
std::vector<bilingual_str>
Warnings::GetMessages
()
const
44
{
45
LOCK
(
m_mutex
);
46
std::vector<bilingual_str> messages;
47
messages.reserve(m_warnings.size());
48
for
(
const
auto
& [
id
, msg] : m_warnings) {
49
messages.push_back(msg);
50
}
51
return
messages;
52
}
53
54
UniValue
GetWarningsForRpc
(
const
Warnings
& warnings,
bool
use_deprecated)
55
{
56
if
(use_deprecated) {
57
const
auto
all_messages{warnings.
GetMessages
()};
58
return
all_messages.empty() ?
""
: all_messages.back().original;
59
}
60
61
UniValue
messages{
UniValue::VARR
};
62
for
(
auto
&& message : warnings.
GetMessages
()) {
63
messages.push_back(std::move(message.original));
64
}
65
return
messages;
66
}
67
}
// namespace node
UniValue
Definition
univalue.h:22
UniValue::VARR
@ VARR
Definition
univalue.h:24
node::Warnings
Manages warning messages within a node.
Definition
warnings.h:40
node::Warnings::warning_type
std::variant< kernel::Warning, node::Warning > warning_type
Definition
warnings.h:41
node::Warnings::Unset
bool Unset(warning_type id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Unset a warning message.
Definition
warnings.cpp:36
node::Warnings::Warnings
Warnings()
Definition
warnings.cpp:20
node::Warnings::m_mutex
Mutex m_mutex
Definition
warnings.h:43
node::Warnings::Set
bool Set(warning_type id, bilingual_str message) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Set a warning message.
Definition
warnings.cpp:29
node::Warnings::GetMessages
std::vector< bilingual_str > GetMessages() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Return potential problems detected by the node, sorted by the warning_type id.
Definition
warnings.cpp:43
uiInterface
CClientUIInterface uiInterface
Definition
interface_ui.cpp:15
interface_ui.h
node
Definition
messages.h:21
node::GetWarningsForRpc
UniValue GetWarningsForRpc(const Warnings &warnings, bool use_deprecated)
RPC helper function that wraps warnings.GetMessages().
Definition
warnings.cpp:54
node::Warning::PRE_RELEASE_TEST_BUILD
@ PRE_RELEASE_TEST_BUILD
Definition
warnings.h:25
bilingual_str
Bilingual messages:
Definition
translation.h:24
sync.h
LOCK
#define LOCK(cs)
Definition
sync.h:258
WITH_LOCK
#define WITH_LOCK(cs, code)
Definition
sync.h:289
system.h
translation.h
_
consteval auto _(util::TranslatedLiteral str)
Definition
translation.h:79
univalue.h
warnings.h
Generated on
for Bitcoin Core by
1.17.0