2016-11-30 06:07:42 +00:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2009-2021 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-04-18 14:05:12 +01:00
|
|
|
#ifndef BITCOIN_NODE_WARNINGS_H
|
|
|
|
#define BITCOIN_NODE_WARNINGS_H
|
2016-11-30 06:07:42 +00:00
|
|
|
|
2024-05-07 17:05:40 +01:00
|
|
|
#include <sync.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <variant>
|
2024-04-10 12:16:21 +02:00
|
|
|
#include <vector>
|
2016-11-30 06:07:42 +00:00
|
|
|
|
2024-04-18 14:05:12 +01:00
|
|
|
class UniValue;
|
2020-06-10 11:44:48 +03:00
|
|
|
struct bilingual_str;
|
|
|
|
|
2024-05-07 17:05:40 +01:00
|
|
|
namespace kernel {
|
|
|
|
enum class Warning;
|
|
|
|
} // namespace kernel
|
|
|
|
|
2024-04-18 14:05:12 +01:00
|
|
|
namespace node {
|
2024-05-07 17:05:40 +01:00
|
|
|
enum class Warning {
|
|
|
|
CLOCK_OUT_OF_SYNC,
|
|
|
|
PRE_RELEASE_TEST_BUILD,
|
|
|
|
FATAL_INTERNAL_ERROR,
|
|
|
|
};
|
|
|
|
|
2024-04-18 14:05:12 +01:00
|
|
|
/**
|
2024-05-07 17:05:40 +01:00
|
|
|
* @class Warnings
|
|
|
|
* @brief Manages warning messages within a node.
|
|
|
|
*
|
|
|
|
* The Warnings class provides mechanisms to set, unset, and retrieve
|
2024-05-07 17:22:49 +01:00
|
|
|
* warning messages. It updates the GUI when warnings are changed.
|
2024-05-07 17:05:40 +01:00
|
|
|
*
|
|
|
|
* This class is designed to be non-copyable to ensure warnings
|
|
|
|
* are managed centrally.
|
|
|
|
*/
|
|
|
|
class Warnings
|
|
|
|
{
|
|
|
|
typedef std::variant<kernel::Warning, node::Warning> warning_type;
|
|
|
|
|
|
|
|
mutable Mutex m_mutex;
|
|
|
|
std::map<warning_type, bilingual_str> m_warnings GUARDED_BY(m_mutex);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Warnings();
|
|
|
|
//! A warnings instance should always be passed by reference, never copied.
|
|
|
|
Warnings(const Warnings&) = delete;
|
|
|
|
Warnings& operator=(const Warnings&) = delete;
|
|
|
|
/**
|
|
|
|
* @brief Set a warning message. If a warning with the specified
|
|
|
|
* `id` is already active, false is returned and the new
|
|
|
|
* warning is ignored. If `id` does not yet exist, the
|
2024-05-07 17:22:49 +01:00
|
|
|
* warning is set, the UI is updated, and true is returned.
|
2024-05-07 17:05:40 +01:00
|
|
|
*
|
|
|
|
* @param[in] id Unique identifier of the warning.
|
|
|
|
* @param[in] message Warning message to be shown.
|
|
|
|
*
|
|
|
|
* @returns true if the warning was indeed set (i.e. there is no
|
|
|
|
* active warning with this `id`), otherwise false.
|
|
|
|
*/
|
|
|
|
bool Set(warning_type id, bilingual_str message) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
|
|
|
/**
|
|
|
|
* @brief Unset a warning message. If a warning with the specified
|
2024-05-07 17:22:49 +01:00
|
|
|
* `id` is active, it is unset, the UI is updated, and true
|
|
|
|
* is returned. Otherwise, no warning is unset and false is
|
|
|
|
* returned.
|
2024-05-07 17:05:40 +01:00
|
|
|
*
|
|
|
|
* @param[in] id Unique identifier of the warning.
|
|
|
|
*
|
|
|
|
* @returns true if the warning was indeed unset (i.e. there is an
|
|
|
|
* active warning with this `id`), otherwise false.
|
|
|
|
*/
|
|
|
|
bool Unset(warning_type id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
|
|
|
/** Return potential problems detected by the node, sorted by the
|
|
|
|
* warning_type id */
|
|
|
|
std::vector<bilingual_str> GetMessages() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RPC helper function that wraps g_warnings.GetMessages().
|
|
|
|
*
|
|
|
|
* Returns a UniValue::VSTR with the latest warning if use_deprecated is
|
|
|
|
* set to true, or a UniValue::VARR with all warnings otherwise.
|
2024-04-18 14:05:12 +01:00
|
|
|
*/
|
|
|
|
UniValue GetWarningsForRpc(bool use_deprecated);
|
2024-05-07 17:05:40 +01:00
|
|
|
|
|
|
|
extern Warnings g_warnings;
|
2024-04-18 14:05:12 +01:00
|
|
|
} // namespace node
|
2016-11-30 06:07:42 +00:00
|
|
|
|
2024-04-18 14:05:12 +01:00
|
|
|
#endif // BITCOIN_NODE_WARNINGS_H
|