2016-11-30 06:07:42 +00:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
2016-11-30 06:07:42 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2024-02-26 13:36:30 +01:00
|
|
|
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
2024-02-13 08:03:02 +01:00
|
|
|
|
2024-04-18 14:05:12 +01:00
|
|
|
#include <node/warnings.h>
|
2019-06-17 10:56:52 +03:00
|
|
|
|
2023-05-08 11:32:13 +02:00
|
|
|
#include <common/system.h>
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <sync.h>
|
2024-04-18 14:05:12 +01:00
|
|
|
#include <univalue.h>
|
2019-06-17 10:56:52 +03:00
|
|
|
#include <util/translation.h>
|
2016-11-30 06:07:42 +00:00
|
|
|
|
2024-05-07 17:05:40 +01:00
|
|
|
#include <utility>
|
2020-06-10 11:21:40 +03:00
|
|
|
#include <vector>
|
|
|
|
|
2024-04-18 14:05:12 +01:00
|
|
|
namespace node {
|
2024-05-07 17:05:40 +01:00
|
|
|
Warnings g_warnings;
|
|
|
|
|
|
|
|
Warnings::Warnings()
|
2016-11-30 06:07:42 +00:00
|
|
|
{
|
2024-05-07 17:05:40 +01:00
|
|
|
// Pre-release build warning
|
|
|
|
if (!CLIENT_VERSION_IS_RELEASE) {
|
|
|
|
m_warnings.insert(
|
|
|
|
{Warning::PRE_RELEASE_TEST_BUILD,
|
|
|
|
_("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications")});
|
|
|
|
}
|
2016-11-30 06:07:42 +00:00
|
|
|
}
|
2024-05-07 17:05:40 +01:00
|
|
|
bool Warnings::Set(warning_type id, bilingual_str message)
|
2016-11-30 06:07:42 +00:00
|
|
|
{
|
2024-05-07 17:05:40 +01:00
|
|
|
LOCK(m_mutex);
|
|
|
|
const auto& [_, inserted]{m_warnings.insert({id, std::move(message)})};
|
|
|
|
return inserted;
|
2016-11-30 06:07:42 +00:00
|
|
|
}
|
|
|
|
|
2024-05-07 17:05:40 +01:00
|
|
|
bool Warnings::Unset(warning_type id)
|
2024-03-07 11:23:00 +00:00
|
|
|
{
|
2024-05-07 17:05:40 +01:00
|
|
|
return WITH_LOCK(m_mutex, return m_warnings.erase(id));
|
2024-03-07 11:23:00 +00:00
|
|
|
}
|
2024-04-10 12:16:21 +02:00
|
|
|
|
2024-05-07 17:05:40 +01:00
|
|
|
std::vector<bilingual_str> Warnings::GetMessages() const
|
2016-11-30 06:07:42 +00:00
|
|
|
{
|
2024-05-07 17:05:40 +01:00
|
|
|
LOCK(m_mutex);
|
|
|
|
std::vector<bilingual_str> messages;
|
|
|
|
messages.reserve(m_warnings.size());
|
|
|
|
for (const auto& [id, msg] : m_warnings) {
|
|
|
|
messages.push_back(msg);
|
2020-06-10 11:21:40 +03:00
|
|
|
}
|
2024-05-07 17:05:40 +01:00
|
|
|
return messages;
|
2016-11-30 06:07:42 +00:00
|
|
|
}
|
2024-04-18 14:05:12 +01:00
|
|
|
|
|
|
|
UniValue GetWarningsForRpc(bool use_deprecated)
|
|
|
|
{
|
|
|
|
if (use_deprecated) {
|
2024-05-07 17:05:40 +01:00
|
|
|
const auto all_warnings{g_warnings.GetMessages()};
|
2024-04-18 14:05:12 +01:00
|
|
|
return all_warnings.empty() ? "" : all_warnings.back().original;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniValue warnings{UniValue::VARR};
|
2024-05-07 17:05:40 +01:00
|
|
|
for (auto&& warning : g_warnings.GetMessages()) {
|
2024-04-18 14:05:12 +01:00
|
|
|
warnings.push_back(std::move(warning.original));
|
|
|
|
}
|
|
|
|
return warnings;
|
|
|
|
}
|
|
|
|
} // namespace node
|